test-lib.sh: fully construct UNSET_VARS before test-lib-main.sh
[topgit/pro.git] / tg-base.sh
blob2ab4ee105c28ec84df95b6a16e8146178ba5ec9d
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (C) Petr Baudis <pasky@suse.cz> 2008
4 # (C) Per Cederqvist <ceder@lysator.liu.se> 2010
5 # (C) Kyle J. McKay <mackyle@gmail.com> 2017
6 # All rights reserved.
7 # GPLv2
9 USAGE="Usage: ${tgname:-tg} [...] base [--short[=n] | --no-short] [--] [branch...]"
11 usage()
13 if [ "${1:-0}" != 0 ]; then
14 printf '%s\n' "$USAGE" >&2
15 else
16 printf '%s\n' "$USAGE"
18 exit ${1:-0}
21 ## Parse options
23 short="--short"
25 while [ $# -gt 0 ]; do case "$1" in
26 -h|--help)
27 usage;;
28 --short|--short=*|--no-short)
29 short="$1";;
30 --)
31 shift
32 break;;
33 -?*)
34 die "unrecognized option: $1";;
36 break;;
37 esac; shift; done
39 if [ "$#" -eq 0 ]; then
40 set -- HEAD
43 rv=0
44 for rev in "$@"; do
45 [ "$rev" != "@" ] || rev="HEAD"
46 name="$(git symbolic-ref -q "$rev" 2>/dev/null)" || name="$rev"
47 v_strip_ref name "$name"
48 git rev-parse --verify $short "refs/$topbases/$name^0" -- 2>/dev/null || {
49 rv=1
50 echo "$rev is not a TopGit branch" >&2
52 done
53 exit $rv