Skip to content

plumbing: revlist, Add regression tests for control-char tree names - #2527

Merged
pjbgf merged 1 commit into
go-git:mainfrom
arseniy-gl:revlist-control-char-tree-name-tests
Oct 23, 2026
Merged

pjbgf merged 1 commit into
go-git:mainfrom
arseniy-gl:revlist-control-char-tree-name-tests

Conversation

@arseniy-gl

Copy link
Copy Markdown
Contributor

Why

#2251 reported that Push failed with invalid path "\x1b\x1b\x1b": contains control character whenever a tree entry with a control character existed anywhere in reachable history, even when the objects were already present on the remote. Upstream Git accepts such names (verify_path forbids only / and NUL in a path component) and pushes that history without complaint. I verified this locally against git 2.39.5 with a repository whose history contains a \x1b-prefixed entry: both a first push and a push where the offending objects were already on the remote succeed.

The bug itself is already fixed: on releases/v5.x by 707175a (TreeWalker.SkipPathValidation), and on main the revlist rewrite no longer uses TreeWalker at all, collecting hashes straight from Tree.Entries. What main lacks is a regression test: a future object walk that reintroduces entry-name validation would break push again.

What

Three regression tests in plumbing/revlist covering the scenarios from #2251:

  • the offending entry exists only in history (the pushed commit deleted it)
  • the offending entry is in the pushed commit itself
  • the offending objects arrive as haves, already present on the remote

The tests store the tree by writing its wire format directly, because Tree.Encode rejects these names on the producer side. A tree fetched from a remote bypasses that gate, and Encode's doc comment documents the direct write as the way to store such objects.

AI disclosure

Prepared with AI assistance (pi coding agent), per the AI Contribution Policy. Upstream git behaviour was verified locally as described above.

Refs #2251

Upstream Git accepts tree entry names with control characters:
verify_path forbids only '/' and NUL in a path component, and Git
pushes such history without complaint. go-git's push rejected these
names until the object walk stopped validating them: fixed on v5 via
TreeWalker.SkipPathValidation, and no longer applicable on main since
the revlist rewrite, which collects hashes straight from Tree.Entries
without a TreeWalker.

Cover the scenario on main so a walk that reintroduces name validation
fails loudly: the offending entry only in history, in the pushed
commit itself, and arriving as haves already present on the remote.

Refs go-git#2251

Signed-off-by: Ars Golushkov <[email protected]>
Assisted-by: pi

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arseniy-gl Thanks for working on this. 🙇

@pjbgf
pjbgf merged commit 11ba054 into go-git:main Oct 23, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants