Skip to content

fix(missing): only pass the arguments after -- as pathspec - #1287

Merged
spacewander merged 1 commit into
tj:mainfrom
shivangithaker-0510:fix/git-missing-pathspec
Nov 25, 2026
Merged

spacewander merged 1 commit into
tj:mainfrom
shivangithaker-0510:fix/git-missing-pathspec

Conversation

@shivangithaker-0510

Copy link
Copy Markdown
Contributor

git missing builds its pathspec wrong. Once it sees --, the loop adds all of "$@" to the pathspec. That includes the branch names and the -- itself. So

git missing main feature -- src

runs

git log main...feature --format="%m %h %s" --left-right -- main feature -- src

and also lists commits that touch a file or directory named like one of the branches (feature/ here), as well as commits under src.

To reproduce:

git init -b main demo && cd demo
git commit --allow-empty -m init
git switch -c feature
mkdir feature src
echo a > feature/file && git add . && git commit -m "Change feature dir"
echo b > src/file && git add . && git commit -m "Change src dir"
git switch main
git missing main feature -- src
# before: > ... Change src dir
#         > ... Change feature dir   <- should not be listed
# after:  > ... Change src dir

The fix walks the arguments with shift, so only the arguments after -- go into the pathspec. Branch and --option parsing is unchanged.

I also added tests/git-missing.bats. There were no tests for this command before. Two of the three new tests fail without the fix and pass with it.

The pathspec support came from #1156.

AI disclosure: I used an AI coding assistant to find this bug and draft the fix and tests. I reviewed the change and reproduced the bug myself, and I ran the new tests with and without the fix.

The argument loop appended all of "$@" to the pathspec once it saw
"--", so `git missing main feature -- src` ran

    git log main...feature ... -- main feature -- src

and also matched commits touching paths named like the branches.
Shift through the arguments instead so that only the ones after "--"
end up in the pathspec, and add tests for git-missing.
@spacewander
spacewander merged commit 02938b5 into tj:main Nov 25, 2026
5 checks passed
@spacewander

Copy link
Copy Markdown
Collaborator

@shivangithaker-0510
Merged. Thanks!

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