chiark / gitweb /
Merge commit 'index-wt~2' of git://repo.or.cz/topgit/bertw
[topgit.git] / tg-patch.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz>  2008
4 # GPLv2
5
6 name=
7
8 head_from=
9
10
11 ## Parse options
12
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: tg [...] patch [-i | -w] [NAME]" >&2
21                 exit 1;;
22         *)
23                 [ -z "$name" ] || die "name already specified ($name)"
24                 name="$arg";;
25         esac
26 done
27
28 head="$(git symbolic-ref HEAD)"
29 head="${head#refs/heads/}"
30
31 [ -n "$name" ] ||
32         name="$head"
33 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
34         die "not a TopGit-controlled branch"
35
36 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
37         die "$head_from makes only sense for the current branch"
38 fi
39
40
41
42 setup_pager
43
44
45 # put out the commit message
46 # and put an empty line out, if the last one in the message was not an empty line
47 # and put out "---" if the commit message does not have one yet
48 cat_file "$name:.topmsg" $head_from |
49         awk '
50 /^---/ {
51     has_3dash=1;
52 }
53        {
54     need_empty = 1;
55     if ($0 == "")
56         need_empty = 0;
57     print;
58 }
59 END    {
60     if (need_empty)
61         print "";
62     if (!has_3dash)
63         print "---";
64 }
65 '
66
67 b_tree=$(pretty_tree "$name" -b)
68 t_tree=$(pretty_tree "$name" $head_from)
69
70 if [ $b_tree = $t_tree ]; then
71         echo "No changes."
72 else
73         git diff-tree -p --stat $b_tree $t_tree
74 fi
75
76 echo '-- '
77 echo "tg: ($base_rev..) $name (depends on: $(cat_file "$name:.topdeps" $head_from | paste -s -d' '))"
78 branch_contains "$name" "$base_rev" ||
79         echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."
80
81 # vim:noet