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 "" +}