needs_update(): Return non-zero if update is required
[topgit.git] / tg-info.sh
blob21b69dc488893a4c7f4f2b2cf98f3cf39e6f4f74
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="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
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 deps="$(git cat-file blob "$name:.topdeps" | paste -s -d' ')"
42 echo "Depends: $deps"
44 depcheck="$(mktemp)"
45 missing_deps=
46 needs_update "$name" >"$depcheck" || :
47 if [ -n "$missing_deps" ]; then
48 echo "MISSING: $missing_deps"
50 if [ -s "$depcheck" ]; then
51 echo "Needs update from:"
52 cat "$depcheck" |
53 sed 's/ [^ ]* *$//' | # last is $name
54 sed 's/^: //' | # don't distinguish base updates
55 while read dep chain; do
56 echo -n "$dep "
57 [ -n "$chain" ] && echo -n "(<= $(echo "$chain" | sed 's/ / <= /')) "
58 dep_parent="${chain%% *}"
59 echo -n "($(measure_branch "$dep" "${dep2:-$name}"))"
60 echo
61 done | sed 's/^/\t/'
62 else
63 echo "Up-to-date."
65 rm "$depcheck"