fix: add '--' separator to Git commands to disambiguate refs from paths #1618
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When a branch name matches a filename in the working directory, Git commands like
git checkoutandgit resetbecome ambiguous about whether arguments are refs or paths. This causes git-branchless commands (likegit branchless amend) to fail when operating on branches that have the same name as files in the current directory.Example scenario:
$ git checkout -b foo $ touch foo $ git branchless amend # Error: pathspec 'foo' did not match any filesSolution
This PR adds the standard Git
--separator to all checkout and reset operations in thecheck_outmodule to explicitly separate refs from paths, preventing such ambiguity.Changes
Core fix (check_out.rs): Added
--separator to 5 git command invocations:git reset <target> --git checkout <target> --git reset --hard HEAD --git checkout <oid> --git reset <oid> --Tests:
--separatortest_amend_with_branch_name_matching_file()in test_amend.rs to verify the fix works when branch names match filenamesThe
--separator is a standard Git convention that tells Git to treat everything before it as refs/options and everything after it as paths. This ensures unambiguous command parsing even when branch names and filenames collide.Test Results
All affected test suites passing: