tg-info: properly handle showing unmerged remotes
[topgit/pro.git] / tg-info.sh
blobf7f54e7c05fdff562839733aa219e1dba0faab4f
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 name=
9 ## Parse options
11 while [ -n "$1" ]; do
12 arg="$1"; shift
13 case "$arg" in
14 -*)
15 echo "Usage: tg [...] info [<name>]" >&2
16 exit 1;;
18 [ -z "$name" ] || die "name already specified ($name)"
19 name="$arg";;
20 esac
21 done
23 [ -n "$name" ] || name="$(strip_ref "$(git symbolic-ref HEAD 2>/dev/null)")"
24 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
25 die "not a TopGit-controlled branch"
27 measure="$(measure_branch "$name" "$base_rev")"
29 echo "Topic Branch: $name ($measure)"
30 if [ "$(git rev-parse --short "$name")" = "$base_rev" ]; then
31 echo "* No commits."
32 exit 0
35 git cat-file blob "$name:.topmsg" | grep ^Subject: || :
37 echo "Base: $base_rev"
38 branch_contains "$name" "$base_rev" ||
39 echo "* Base is newer than head! Please run \`$tg update\`."
41 if has_remote "$name"; then
42 echo "Remote Mate: $base_remote/$name"
43 branch_contains "$base_rev" "refs/remotes/$base_remote/top-bases/$name" ||
44 echo "* Local base is out of date wrt. the remote base."
45 branch_contains "$name" "refs/remotes/$base_remote/$name" ||
46 echo "* Local head is out of date wrt. the remote head."
47 branch_contains "refs/remotes/$base_remote/$name" "$name" ||
48 echo "* Local head is ahead of the remote head."
51 git cat-file blob "$name:.topdeps" |
52 sed '1{ s/^/Depends: /; n; }; s/^/ /;'
54 depcheck="$(get_temp tg-depcheck)"
55 missing_deps=
56 needs_update "$name" >"$depcheck" || :
57 if [ -n "$missing_deps" ]; then
58 echo "MISSING: $missing_deps"
60 depcheck2="$(get_temp tg-depcheck2)"
61 sed '/^!/d' <"$depcheck" >"$depcheck2"
62 if [ -s "$depcheck2" ]; then
63 echo "Needs update from:"
64 cat "$depcheck2" |
65 sed 's/ [^ ]* *$//' | # last is $name
66 sed 's/^[:] //' | # don't distinguish base updates
67 sed 's/^% /~/' | # but we may need special remote handling
68 while read dep chain; do
69 rmt=
70 dep2=
71 case "$dep" in "~"?*)
72 rmt=1
73 dep="${dep#?}"
74 #dep2="refs/remotes/$base_remote/$dep"
75 esac
76 printf '%s' "$dep "
77 [ -n "$chain" ] && printf '%s' "(<= $(echo "$chain" | sed 's/ / <= /')) "
78 dep_parent="${chain%% *}"
79 printf '%s' "($(measure_branch "$dep" "${dep2:-$name}"))"
80 echo
81 done | sed 's/^/ /'
82 else
83 echo "Up-to-date${missing_deps:+ (except for missing dependencies)}."
86 # vim:noet