Created
February 9, 2011 16:34
-
-
Save wpalmer/818764 to your computer and use it in GitHub Desktop.
adc/describe
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
#!/bin/bash | |
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 | |
echo 'option 'candidates' expects a numerical value' >&2 | |
exit 1 | |
fi | |
args[${#args[@]}]="--candidates=$1" | |
;; | |
--match) | |
shift | |
args[${#args[@]}]="--match=$1" | |
;; | |
--) | |
in_args=0 | |
;; | |
-*) | |
echo "error: unknown or disallowed option '$1'" >&2 | |
exit 1 | |
;; | |
*) | |
if [ $did_set_repo -eq 0 ]; then | |
did_set_repo=1 | |
repo="${1%.git}" | |
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 | |
echo 'repository not specified' >&2 | |
exit 1 | |
fi | |
if [ ${#refs[@]} -eq 0 ]; then | |
echo 'no refs specified' >&2 | |
exit 1 | |
fi | |
for ref in "${refs[@]}"; do | |
if \ | |
perl -I$GL_BINDIR -Mgitolite -e 'cli_repo_rights($ARGV[0], $ARGV[1])' "$repo" "$ref" | | |
grep -v -q '^[^ ]*R' | |
then | |
echo "no read permissions on $repo for $ref" >&2 | |
exit 1 | |
fi | |
done | |
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