tj.git-extras/bin/git-missing
Wiktor Żurawik f0b9e18e54
Some checks failed
ci / lint (push) Has been cancelled
ci / typo (push) Has been cancelled
ci / test (push) Has been cancelled
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-latest) (push) Has been cancelled
Add pathspec support in git-missing (#1156)
* feat: Add pathspec support in git-missing

Allow to specify a path to limit the commit difference list. This
improvement allows users to focus on changes in specific directories or
files when comparing branches for missing commits.

* refactor: Improve pathspec handling in git-missing

- Change pathspec from string to array to support multiple pathspecs
- Remove unnecessary 'shift' command in argument processing loop
- Simplify git log command execution by using a single codepath

* chore: Update git-missing docs

* chore: Fix a typo in git-missing docs
2024-08-26 10:38:15 +08:00

53 lines
993 B
Bash
Executable file

#!/usr/bin/env bash
usage() {
echo 1>&2 "usage: git missing [<first branch>] <second branch> [<git log options>] [[--] <path>...]"
}
if [ "${#}" -lt 1 ]
then
usage
exit 1
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
case "$arg" in
--)
parse_path=true
;;
--*)
git_log_args+=( "$arg" )
;;
*)
branches+=( "$arg" )
;;
esac
done
firstbranch=
secondbranch=
if [ ${#branches[@]} -eq 2 ]
then
firstbranch="${branches[0]}"
secondbranch="${branches[1]}"
elif [ ${#branches[@]} -eq 1 ]
then
secondbranch="${branches[0]}"
else
echo >&2 "error: at least one branch required"
exit 1
fi
git log "${git_log_args[@]}" "$firstbranch"..."$secondbranch" --format="%m %h %s" --left-right -- "${pathspec[@]}"