topgit: version 0.19.13
[topgit/pro.git] / tg-base.sh
blob35e04f1d60e32a7c3b5555b9a5d16f870fef1c62
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, 2021
6 # All rights reserved
7 # GPLv2
9 USAGE="\
10 Usage: ${tgname:-tg} [...] base [--short[=<n>] | --no-short] [--] [branch...]
11 Options:
12 --short[=<n>] display shortened hashes (default)
13 --no-short display full hashes"
15 usage()
17 if [ "${1:-0}" != 0 ]; then
18 printf '%s\n' "$USAGE" >&2
19 else
20 printf '%s\n' "$USAGE"
22 exit ${1:-0}
25 ## Parse options
27 short="--short"
29 while [ $# -gt 0 ]; do case "$1" in
30 -h|--help)
31 usage;;
32 --short|--short=*|--no-short)
33 short="$1";;
34 --)
35 shift
36 break;;
37 -?*)
38 die "unrecognized option: $1";;
40 break;;
41 esac; shift; done
43 if [ "$#" -eq 0 ]; then
44 set -- HEAD
47 rv=0
48 for rev in "$@"; do
49 [ "$rev" != "@" ] || rev="HEAD"
50 name="$(git symbolic-ref -q "$rev" 2>/dev/null)" || name="$rev"
51 v_strip_ref name "$name"
52 git rev-parse --verify $short "refs/$topbases/$name^0" -- 2>/dev/null || {
53 rv=1
54 echo "$rev is not a TopGit branch" >&2
56 done
57 exit $rv