tg: tolerate missing .topdeps better
[topgit/pro.git] / tg-patch.sh
blob550ba6cce222614fde12fa62564d0f50dfbef750
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 name=
8 head_from=
11 ## Parse options
13 while [ -n "$1" ]; do
14 arg="$1"; shift
15 case "$arg" in
16 -i|-w)
17 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
18 head_from="$arg";;
19 -*)
20 echo "Usage: ${tgname:-tg} [...] patch [-i | -w] [<name>]" >&2
21 exit 1;;
23 [ -z "$name" ] || die "name already specified ($name)"
24 name="$arg";;
25 esac
26 done
28 head="$(git symbolic-ref HEAD)"
29 head="${head#refs/heads/}"
31 [ -n "$name" ] ||
32 name="${head:-HEAD}"
33 name="$(verify_topgit_branch "$name")"
34 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
35 die "not a TopGit-controlled branch"
37 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
38 die "$head_from makes only sense for the current branch"
43 setup_pager
44 # We now collect the rest of the code in this file into a block
45 # so we can redirect the output to the pager.
48 # put out the commit message
49 # and put an empty line out, if the last one in the message was not an empty line
50 # and put out "---" if the commit message does not have one yet
51 cat_file "$name:.topmsg" $head_from |
52 awk '
53 /^---/ {
54 has_3dash=1;
57 need_empty = 1;
58 if ($0 == "")
59 need_empty = 0;
60 print;
62 END {
63 if (need_empty)
64 print "";
65 if (!has_3dash)
66 print "---";
70 b_tree=$(pretty_tree "$name" -b)
71 t_tree=$(pretty_tree "$name" $head_from)
73 if [ $b_tree = $t_tree ]; then
74 echo "No changes."
75 else
76 git diff-tree -p --stat $b_tree $t_tree
79 echo '-- '
80 echo "$tgname: ($base_rev..) $name (depends on: $(cat_file "$name:.topdeps" $head_from 2>/dev/null | paste -s -d ' ' -))"
81 branch_contains "$name" "$base_rev" ||
82 echo "$tgname: The patch is out-of-date wrt. the base! Run \`$tgdisplay update\`."
84 } | "$TG_PAGER"
85 # ... and then we pipe all the output through the pager
87 # vim:noet