Skip to content

fix: separate fallback push branch from pathspecs#1396

Merged
mrexox merged 1 commit intoevilmartians:masterfrom
lawrence3699:fix/push-branch-pathspecs
Apr 20, 2026
Merged

fix: separate fallback push branch from pathspecs#1396
mrexox merged 1 commit intoevilmartians:masterfrom
lawrence3699:fix/push-branch-pathspecs

Conversation

@lawrence3699
Copy link
Copy Markdown
Contributor

Closes #1395

Context

When @{push} is unavailable, PushFiles() falls back to git diff --name-only HEAD <default-branch>.
If the repository also contains a directory with the same name as that default branch, Git treats the branch name as ambiguous and the pre-push hook fails before it can resolve {push_files}.

Changes

  • terminate the fallback git diff revision list with --
  • add regression coverage for the branch/path collision case

Validation

  • go test ./internal/git -run TestPushFiles -count=1
  • go test ./internal/git -count=1
  • go test ./internal/run/controller/... -count=1
  • go test ./... -count=1
  • manual repro on a throwaway repo where origin/HEAD points to dev and the worktree contains dev/

Copilot AI review requested due to automatic review settings April 17, 2026 17:11
@lawrence3699 lawrence3699 requested a review from mrexox as a code owner April 17, 2026 17:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Git argument ambiguity in Repository.PushFiles() when falling back from @{push} to a default branch name that also exists as a path in the worktree, by separating revisions from pathspecs using -- and adding a regression test for that scenario.

Changes:

  • Update the fallback git diff --name-only HEAD <branch> invocation to git diff --name-only HEAD <branch> -- to disambiguate branch vs. path names.
  • Add a regression test covering the branch/path collision case (e.g., default branch dev and a dev/ directory present).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/git/repository.go Appends -- to the fallback git diff command to prevent branch/path ambiguity errors.
internal/git/repository_test.go Adds a test ensuring the fallback diff uses -- and succeeds when a directory matches the branch name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mrexox
Copy link
Copy Markdown
Member

mrexox commented Apr 20, 2026

Thank you for preparing the PR! I'll fix linter issues

@mrexox mrexox merged commit 9d53c36 into evilmartians:master Apr 20, 2026
16 of 18 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.

"fatal: ambiguous argument" when a folder exists that matches the branch name

3 participants