Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 40 lines (28 sloc) 587 Bytes
#!/usr/bin/env bash
###
### git-branch: Add convenience options to git-branch(1).
###
ERR_NOTREPO="Not a Git repository."
ERR_NO_PREV_BRANCH="No previous branch found."
if [[ ! "$(git rev-parse --is-inside-work-tree)" ]] 2>/dev/null; then
printf '%s\n' "$ERR_NOTREPO"
exit 1
fi
ARGV=()
while [[ $# -gt 0 ]]; do
case "$1" in
-L|--last)
$GIT check-ref-format --branch @{-1} 2>/dev/null
if [[ $? -gt 0 ]]; then
printf '%s: %s\n' "$0" "$ERR_NO_PREV_BRANCH"
exit 1
fi
exit 0
;;
*)
ARGV+=("$1")
shift
;;
esac
done
exec $GIT branch "${ARGV[@]}"