Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-missing: do proper argument parsing. Fix #562 #565

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions bin/git-missing
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
#!/usr/bin/env bash

# grab first two non-option arguments
for arg in $*; do
if [ -n "${arg}" ]; then
test -z "$firstbranch" && firstbranch="${arg}" && continue
test -z "$secondbranch" && secondbranch="${arg}" && continue
else
# add anything else to a passthrough
passthrough="$passthrough $arg"
fi
done
usage() {
echo 1>&2 "usage: git missing [<first branch>] <second branch> [<git log options>]"
}

if [ "${#}" -lt 1 ]
then
usage
exit 1
fi

test -z "$firstbranch" && echo "at least one branch required" && exit 1
declare -a git_log_args=()
declare -a branches=()
for arg in "$@" ; do

case "$arg" in
--*)
git_log_args+=( "$arg" )
;;
*)
branches+=( "$arg" )
;;
esac
done

if test -z "$secondbranch"; then
secondbranch=$firstbranch
firstbranch=
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 $passthrough $firstbranch...$secondbranch --format="%m %h %s" --left-right
git log "${git_log_args[@]}" "$firstbranch"..."$secondbranch" --format="%m %h %s" --left-right