test-lib.sh: make sure exported variables get cached
[topgit/pro.git] / tg-info.sh
blob3b6975ce6495f0c4e3bb9d01a4ca6ab7b95f3823
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, 2016, 2017
5 # GPLv2
7 USAGE="Usage: ${tgname:-tg} [...] info [--heads | --leaves] [<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=
22 leaves=
24 while [ $# -gt 0 ]; do case "$1" in
25 -h|--help)
26 usage
28 --heads)
29 heads=1
31 --leaves)
32 leaves=1
34 -?*)
35 echo "Unknown option: $1" >&2
36 usage 1
39 break
41 esac; shift; done
42 [ "$heads$leaves" != "11" ] || die "mutually exclusive options --heads and --leaves"
43 [ $# -gt 0 ] || set -- HEAD
44 [ $# -eq 1 ] || die "name already specified ($1)"
45 name="$1"
47 # true if $1 is an ancestor of (or the same as) $2
48 is_ancestor()
50 [ "$(git rev-list --count --max-count=1 "$1" --not "$2" --)" = "0" ]
53 if [ -n "$heads" ]; then
54 verify="$name"
55 ! test="$(verify_topgit_branch "${name:-HEAD}" -f)" || verify="refs/heads/$test"
56 hash="$(git rev-parse --verify --quiet "$verify" --)" || die "no such ref: $name"
57 $tg summary --tgish-only --heads |
58 while read -r head; do
59 if is_ancestor "$hash" "refs/heads/$head"; then
60 printf '%s\n' "$head"
62 done
63 exit 0
66 name="$(verify_topgit_branch "${name:-HEAD}")"
67 if [ -n "$leaves" ]; then
68 find_leaves "$name"
69 exit 0
71 base_rev="$(git rev-parse --short --verify "refs/$topbases/$name" -- 2>/dev/null)" ||
72 die "not a TopGit-controlled branch"
74 measure="$(measure_branch "refs/heads/$name" "$base_rev")"
76 echo "Topic Branch: $name ($measure)"
77 if [ "$(git rev-parse --verify --short "refs/heads/$name" --)" = "$base_rev" ]; then
78 echo "* No commits."
79 exit 0
82 git cat-file blob "$name:.topmsg" | grep ^Subject: || :
84 echo "Base: $base_rev"
85 branch_contains "refs/heads/$name" "refs/$topbases/$name" ||
86 echo "* Base is newer than head! Please run \`$tgdisplay update\`."
88 if has_remote "$name"; then
89 echo "Remote Mate: $base_remote/$name"
90 branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" ||
91 echo "* Local base is out of date wrt. the remote base."
92 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name" ||
93 echo "* Local head is out of date wrt. the remote head."
94 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" ||
95 echo "* Local head is ahead of the remote head."
98 git cat-file blob "$name:.topdeps" 2>/dev/null |
99 sed '1{ s/^/Depends: /; n; }; s/^/ /;'
101 depcheck="$(get_temp tg-depcheck)"
102 missing_deps=
103 needs_update "$name" >"$depcheck" || :
104 if [ -n "$missing_deps" ]; then
105 echo "MISSING: $missing_deps"
107 depcheck2="$(get_temp tg-depcheck2)"
108 sed '/^!/d' <"$depcheck" >"$depcheck2"
109 if [ -s "$depcheck2" ]; then
110 echo "Needs update from:"
111 # 's/ [^ ]* *$//' -- last is $name
112 # 's/^[:] /:/' -- don't distinguish base updates
113 <"$depcheck2" sed -e 's/ [^ ]* *$//' -e 's/^[:] /:/' |
114 while read dep chain; do
115 case "$dep" in
117 dep="${dep#:}"
118 fulldep="refs/heads/$dep"
119 extradep="refs/$topbases/$dep"
122 extradep=
123 case "$dep" in
124 refs/*)
125 fulldep="$dep";;
127 fulldep="refs/heads/$dep";;
128 esac
130 esac
131 printf '%s' "$dep "
132 [ -n "$chain" ] && printf '%s' "(<= $(echol "$chain" | sed 's/ / <= /')) "
133 printf '%s' "($(eval measure_branch '"$fulldep"' '"refs/heads/$name"' ${extradep:+\"\$extradep\"}))"
134 echo
135 done | sed 's/^/ /'
136 else
137 echo "Up-to-date${missing_deps:+ (except for missing dependencies)}."
140 # vim:noet