Skip to content

fix: resolve push-files fallback against the remote-tracking ref - #1485

Open
hamodywe wants to merge 1 commit into
evilmartians:masterfrom
hamodywe:fix/push-files-remote-tracking-ref-fallback
Open

fix: resolve push-files fallback against the remote-tracking ref#1485
hamodywe wants to merge 1 commit into
evilmartians:masterfrom
hamodywe:fix/push-files-remote-tracking-ref-fallback

Conversation

@hamodywe

@hamodywe hamodywe commented Aug 8, 2026

Copy link
Copy Markdown

resolveHeadBranch() read origin/HEAD and returned the bare branch name (e.g. "main"), which PushFiles() then diffed against directly. In a clone that never checked out a local branch of that name (e.g. someone who always branches straight off origin/main), that local ref doesn't exist, so the diff fails with "fatal: bad revision 'main'" and the error propagates instead of falling through to the existing ls-tree fallback. Since pre-push always computes push-files internally to gate the {push_files}/{files} templates, this hard-fails the whole hook even for jobs that never reference either template.

Return the remote-tracking ref ("origin/main") instead, matching what the git-branch--remotes fallback path already produced. The remote-tracking ref always exists once origin/HEAD does, and reflects what was actually fetched rather than a possibly stale or entirely absent local branch of the same name.

Fixes #1474

Context

Pre-push hooks that gate {push_files}/{files} templates were hard-failing entirely in clones without a local branch matching the remote's default branch name.

Changes

internal/git/repo.go: resolveHeadBranch() now returns the remote-tracking ref instead of the bare branch name, consistent with the existing git-branch--remotes fallback path. Added a regression test in internal/git/repo_test.go.

resolveHeadBranch() read origin/HEAD and returned the bare branch name
(e.g. "main"), which PushFiles() then diffed against directly. In a
clone that never checked out a local branch of that name (e.g. someone
who always branches straight off origin/main), that local ref doesn't
exist, so the diff fails with "fatal: bad revision 'main'" and the
error propagates instead of falling through to the existing ls-tree
fallback. Since pre-push always computes push-files internally to
gate the {push_files}/{files} templates, this hard-fails the whole
hook even for jobs that never reference either template.

Return the remote-tracking ref ("origin/main") instead, matching what
the git-branch--remotes fallback path already produced. The
remote-tracking ref always exists once origin/HEAD does, and reflects
what was actually fetched rather than a possibly stale or entirely
absent local branch of the same name.

Fixes evilmartians#1474
@hamodywe
hamodywe requested a review from mrexox as a code owner August 8, 2026 23:09
Comment thread internal/git/repo_test.go
fs := afero.NewMemMapFs()
root := "/repo"
gitPath := filepath.Join(root, ".git")
originHead := filepath.Join(gitPath, "refs", "remotes", "origin", "HEAD")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Standalone regression test structure

The new regression case uses a standalone t.Run block and direct t.Fatalf assertions instead of the repository-required table-driven map[string]struct structure and testify/assert, making related cases harder to extend consistently.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

pre-push fails with fatal: bad revision '<default-branch>' when the default branch has no local ref

1 participant