Repository navigation
Description
Bug Description
When pushing a commit, Repository.Push computes the set of objects to send via revlist.Objects, which walks the reachable trees through iterateCommitTrees → object.TreeWalker.Next. Since v5.19.1, TreeWalker.Next calls pathutil.ValidTreePath on every entry it enumerates (added in #2105), and the revlist TreeWalker is created with the default skipPathValidation = false.
As a result, if any reachable commit in history contains a tree entry whose name has a control character even one that was deleted years ago, and even one whose objects are already present on the remote and would therefore never be sent the entire push fails with:
invalid path "\x1b\x1b\x1b": contains control character
Expected: the push succeeds. The offending object is not part of the new commit, is already on the remote, and is never materialised to a filesystem. Upstream Git pushes such a repository without complaint.
Actual: the push aborts before any network transfer, because the revlist tree walk validates historical entry names it is only enumerating to compute the object set.
This is the same class of issue as #2222 ("skip path validation in tree diff walk"), which already established the principle that inspection-only walks that never materialise names to disk should not run ValidTreePath. The revlist walk performed for push is exactly such an inspection-only walk: it computes which objects to send, it writes nothing to the working tree. It looks like #2222 addressed the diff walk (treenoder.transformChildren) but not the revlist walk (plumbing/revlist.iterateCommitTrees).
go-git Version
v5.19.1
Steps to Reproduce
- Create a repo, commit a tree entry whose name contains a control character (a byte < 0x20), then delete it in a later commit. Upstream Git allows this — only
/and NUL are forbidden in a path component. - Push all history to a bare remote.
- Add a normal commit on top (that does not touch the bad path) and push it again.
- Observe the push fail with
invalid path "...": contains control character, even though the bad object is already on the remote and is not part of the new commit.
Code example:
// setup: a repo whose history contains a tree entry with a control-char name,
// already pushed to `remote`. HEAD is a later, clean commit.
repo, _ := git.PlainOpen("repo-with-bad-path-in-history")
// make an unrelated clean commit
wt, _ := repo.Worktree()
os.WriteFile("repo-with-bad-path-in-history/foo.txt", []byte("hi"), 0o644)
wt.Add("foo.txt")
wt.Commit("clean commit", &git.CommitOptions{Author: sig})
// this fails, even though the control-char object is already on the remote
// and the new commit does not reference it:
err := repo.Push(&git.PushOptions{RemoteName: "origin"})
// err: invalid path "\x1b\x1b\x1b": contains control character
### Additional Information
**Call path that triggers it:**
**Why upstream Git does not reject this:** `verify_path` forbids only `/` and NUL inside a path component; control characters and newlines are valid pathname bytes on disk. go-git's `ValidTreePath` is stricter, which is correct at *materialisation* boundaries (checkout, archive) but not for a read-only revlist walk that only computes the object set to transfer.
**Suggested fix:** set `skipPathValidation = true` on the `TreeWalker` created in `iterateCommitTrees` (revlist), mirroring what #2222 did for `treenoder.transformChildren` (diff). The revlist walk enumerates objects for transfer and never funnels entry names into the filesystem, so the materialisation-safety validation added in #2105 is not needed there. Materialising callers (`archive`, `FileIter`, `FindEntry`, `TreeEntryFile`) keep validating as before.
**Real-world impact:** a control-char filename committed in 2021 and deleted the next day still lives in history and is cloned by everyone. Every push of a version tag now fails, on every branch that descends from that commit, with no change to the user's code only a go-git bump triggered it. The only user-side remedy today is rewriting history (`git filter-repo`) across all affected branches.
Activity
plumbing: revlist, Skip path validation in the object walk. Fixes #2251
arseniy-gl commentedon Oct 17, 2026
Hi, I'd like to work on this issue.
plumbing: revlist, Add regression tests for control-char tree names
arseniy-gl commentedon Oct 29, 2026
@pjbgf Regression tests for this landed in #2527. Safe to close.
pjbgf commentedon Nov 14, 2026
@arseniy-gl thanks for working on this and the ping. 🙇