2 # TopGit - A different patch queue manager
12 # Options of "push" and "pop".
15 # Arguments of "goto".
19 _head
="$(git rev-parse --abbrev-ref=loose HEAD)"
20 ref_exists
"refs/top-bases/$_head" && branch_annihilated
"$_head" && _checkout_opts
="-f"
21 git checkout
${_checkout_opts} "$1"
24 while [ $# -gt 0 ]; do
42 echo "Usage: tg [...] checkout [ [ push | pop ] [ -a ] | goto <pattern> ]" >&2
47 if [ "$goto$all" = 11 ]; then
48 die
"goto -a does not make sense."
51 if [ -z "$push$pop$goto" ]; then
52 # Default subcommand is "push". This was the most reasonable
53 # opposite of ".." that I could figure out. "goto" would also
54 # make sense as the default command, I suppose.
58 _depfile
="$(mktemp -t tg-co-deps.XXXXXX)"
59 _altfile
="$(mktemp -t tg-co-alt.XXXXXX)"
60 trap "rm -f \"$_depfile\" \"$_altfile\"" 0
62 if [ -n "$goto" ]; then
63 tg summary
-t |
grep -e "$pattern" >$_altfile ||
:
64 no_branch_found
="No topic branch matches grep pattern '$pattern'"
66 branch
=`git symbolic-ref -q HEAD` || die
"Working on a detached head"
67 branch
=`git rev-parse --abbrev-ref $branch`
69 if [ -n "$pop" ]; then
70 no_branch_found
="$branch does not depend on any topic"
72 no_branch_found
="No topic depends on $branch"
75 if [ -z "$all" ]; then
76 if [ -n "$pop" ]; then
82 tg summary
--deps >$_depfile || die
"tg summary failed"
84 if [ -n "$pop" ]; then
89 script=@sharedir@
/leaves.
awk
90 awk -f @sharedir@
/leaves.
awk dir
=$dir start
=$branch <$_depfile |
sort >$_altfile
94 _alts
=`wc_l < $_altfile`
95 if [ $_alts = 0 ]; then
96 die
"$no_branch_found"
97 elif [ $_alts = 1 ]; then
98 checkout
`cat $_altfile`
102 echo Please
select one of the following topic branches
:
104 printf '%s' "Input the number: "
108 sane
=`echo $n|sed 's/[^0-9]//g'`
109 if [ -z "$n" ] ||
[ "$sane" != "$n" ]; then
112 if [ $n -lt 1 ] ||
[ $n -gt $_alts ]; then
113 die
"Input out of range"
116 new_branch
=`sed -n ${n}p $_altfile`
117 [ -n "$new_branch" ] || die
"Bad input"