forked from tj/git-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-missing: do proper argument parsing. Fix tj#562
- Loading branch information
1 parent
5d15928
commit a7470f4
Showing
1 changed file
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
#!/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 | ||
usage() { | ||
echo 1>&2 "usage: git missing [<first branch>] <second branch> [<git log options>]" | ||
} | ||
|
||
if [ "${#}" -lt 1 ] | ||
then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
declare -a git_log_args=() | ||
declare -a branches=() | ||
firstbranch= | ||
secondbranch= | ||
for arg in "$@" ; do | ||
|
||
case "$arg" in | ||
--*) | ||
git_log_args+=( "$arg" ) | ||
;; | ||
*) | ||
branches+=( "$arg" ) | ||
;; | ||
esac | ||
done | ||
|
||
test -z "$firstbranch" && echo "at least one branch required" && exit 1 | ||
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 | ||
|
||
if test -z "$secondbranch"; then | ||
secondbranch=$firstbranch | ||
firstbranch= | ||
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 |