tg-patch.sh: get all awked up on --from
[topgit/pro.git] / tg-base.sh
blob5133e8163af91cf31c5f4cd6cef5f871ca4a58da
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="$(strip_ref "$(git symbolic-ref -q "$rev" 2>/dev/null || echol "$rev")")"
47 git rev-parse --verify $short "refs/$topbases/$name" -- 2>/dev/null || {
48 rv=1
49 echo "$rev is not a TopGit branch" >&2
51 done
52 exit $rv