tg-info.sh: support new --heads option
[topgit/pro.git] / tg-info.sh
blob6da62d63b6d3875a56990a832c2ca135726d0b79
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2015
5 # GPLv2
7 USAGE="Usage: ${tgname:-tg} [...] info [--heads] [<name>]"
9 usage()
11 if [ "${1:-0}" != 0 ]; then
12 printf '%s\n' "$USAGE" >&2
13 else
14 printf '%s\n' "$USAGE"
16 exit ${1:-0}
19 ## Parse options
21 heads=
23 while [ $# -gt 0 ]; do case "$1" in
24 -h|--help)
25 usage
27 --heads)
28 heads=1
30 -?*)
31 echo "Unknown option: $1" >&2
32 usage 1
35 break
37 esac; shift; done
38 [ $# -gt 0 ] || set -- HEAD
39 [ $# -eq 1 ] || die "name already specified ($1)"
40 name="$1"
42 # true if $1 is an ancestor of (or the same as) $2
43 is_ancestor()
45 [ -z "$(git rev-list --max-count=1 "$1" --not "$2" --)" ]
48 if [ -n "$heads" ]; then
49 hash="$(git rev-parse --verify --quiet "$name" --)" || die "no such ref: $name"
50 $tg summary --tgish-only --heads |
51 while read -r head; do
52 if is_ancestor "$hash" "refs/heads/$head"; then
53 printf '%s\n' "$head"
55 done
56 exit 0
59 name="$(verify_topgit_branch "${name:-HEAD}")"
60 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" -- 2>/dev/null)" ||
61 die "not a TopGit-controlled branch"
63 measure="$(measure_branch "$name" "$base_rev")"
65 echo "Topic Branch: $name ($measure)"
66 if [ "$(git rev-parse --verify --short "$name" --)" = "$base_rev" ]; then
67 echo "* No commits."
68 exit 0
71 git cat-file blob "$name:.topmsg" | grep ^Subject: || :
73 echo "Base: $base_rev"
74 branch_contains "refs/heads/$name" "refs/top-bases/$name" ||
75 echo "* Base is newer than head! Please run \`$tgdisplay update\`."
77 if has_remote "$name"; then
78 echo "Remote Mate: $base_remote/$name"
79 branch_contains "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$name" ||
80 echo "* Local base is out of date wrt. the remote base."
81 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name" ||
82 echo "* Local head is out of date wrt. the remote head."
83 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" ||
84 echo "* Local head is ahead of the remote head."
87 git cat-file blob "$name:.topdeps" 2>/dev/null |
88 sed '1{ s/^/Depends: /; n; }; s/^/ /;'
90 depcheck="$(get_temp tg-depcheck)"
91 missing_deps=
92 needs_update "$name" >"$depcheck" || :
93 if [ -n "$missing_deps" ]; then
94 echo "MISSING: $missing_deps"
96 depcheck2="$(get_temp tg-depcheck2)"
97 sed '/^!/d' <"$depcheck" >"$depcheck2"
98 if [ -s "$depcheck2" ]; then
99 echo "Needs update from:"
100 cat "$depcheck2" |
101 sed 's/ [^ ]* *$//' | # last is $name
102 sed 's/^[:] //' | # don't distinguish base updates
103 sed 's/^% /~/' | # but we may need special remote handling
104 while read dep chain; do
105 rmt=
106 dep2=
107 case "$dep" in "~"?*)
108 rmt=1
109 dep="${dep#?}"
110 #dep2="refs/remotes/$base_remote/$dep"
111 esac
112 printf '%s' "$dep "
113 [ -n "$chain" ] && printf '%s' "(<= $(echo "$chain" | sed 's/ / <= /')) "
114 dep_parent="${chain%% *}"
115 printf '%s' "($(measure_branch "$dep" "${dep2:-$name}"))"
116 echo
117 done | sed 's/^/ /'
118 else
119 echo "Up-to-date${missing_deps:+ (except for missing dependencies)}."
122 # vim:noet