Skip to content

Instantly share code, notes, and snippets.

@wpalmer
Created February 9, 2011 16:48
Show Gist options
  • Save wpalmer/818787 to your computer and use it in GitHub Desktop.
Save wpalmer/818787 to your computer and use it in GitHub Desktop.
adc/describe
#!/bin/bash
. $(dirname "$0")/adc.common-functions
repo=
refs=()
args=()
did_set_repo=0
in_args=1
while [ $# -gt 0 ]; do
if [ $in_args -eq 0 ]; then
refs[${#refs[@]}]="$1"
shift
continue
fi
case "$1" in
--all|--tags|--contains|--exact-match|--long|--always|--abbrev=*|--candidates=*|--match=*)
args[${#args[@]}]="$1"
;;
--candidates)
shift
if [ "$1" -eq "$1" ] >/dev/null 2>&1; then
die 'error: option 'candidates' expects a numerical value'
fi
args[${#args[@]}]="--candidates=$1"
;;
--match)
shift
args[${#args[@]}]="--match=$1"
;;
--)
in_args=0
;;
-*)
die "error: unknown or disallowed option '$1'"
;;
*)
if [ $did_set_repo -eq 0 ]; then
did_set_repo=1
repo="$1"
else
if [ "$1" = "${1#refs/}" ]; then
refs[${#refs[@]}]="refs/heads/$1"
else
refs[${#refs[@]}]="$1"
fi
fi
esac
shift
done
if [ $did_set_repo -eq 0 ]; then
die 'repository not specified'
fi
if [ ${#refs[@]} -eq 0 ]; then
die 'no refs specified'
fi
get_rights_and_owner "$repo"
[ -z "$perm_read" ] && die "no read permissions on $repo"
GIT_DIR="$GL_REPO_BASE_ABS/$repo.git" exec git describe "${args[@]}" -- "${refs[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment