From 29e9c46d1bf952120931029bcb8ac2fcee23f6f2 Mon Sep 17 00:00:00 2001 From: Shivangi Thaker Date: Thu, 19 Nov 2026 14:29:58 +0530 Subject: [PATCH] fix(missing): only pass the arguments after -- as pathspec 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. --- bin/git-missing | 13 +++++-------- tests/git-missing.bats | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 tests/git-missing.bats diff --git a/bin/git-missing b/bin/git-missing index 32fbdabd..d3163c98 100755 --- a/bin/git-missing +++ b/bin/git-missing @@ -13,18 +13,15 @@ fi declare -a git_log_args=() declare -a branches=() declare -a pathspec=() -declare parse_path=false -for arg in "$@" ; do - - if [[ $parse_path == true ]]; then - pathspec+=("$@") - break - fi +while [ "${#}" -gt 0 ]; do + arg="$1" + shift case "$arg" in --) - parse_path=true + pathspec+=("$@") + break ;; --*) git_log_args+=( "$arg" ) diff --git a/tests/git-missing.bats b/tests/git-missing.bats new file mode 100644 index 00000000..797b321b --- /dev/null +++ b/tests/git-missing.bats @@ -0,0 +1,44 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + +setup_file() { + test_util.setup_file + test_util.install_command missing +} + +setup() { + test_util.cd_test + + test_util.git_init + git commit --allow-empty -m "Initial commit" + git switch -c feature + mkdir feature src + printf '%s\n' 'a' > feature/file + git add feature/file + git commit -m "Change feature dir" + printf '%s\n' 'b' > src/file + git add src/file + git commit -m "Change src dir" + git switch main +} + +@test "lists commits missing from either branch" { + run git missing main feature + assert_success + assert_line -p "Change feature dir" + assert_line -p "Change src dir" +} + +@test "limits commits to the given pathspec" { + run git missing main feature -- src + assert_success + assert_line -p "Change src dir" + refute_line -p "Change feature dir" +} + +@test "does not treat branch names as pathspec" { + run git missing main feature -- does-not-exist + assert_success + assert_output "" +}