chiark / gitweb /
tg-export: use pretty_tree -b for base
[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 diff_opts=
10 diff_committed_only=yes # will be unset for index/worktree
11
12
13 ## Parse options
14
15 while [ -n "$1" ]; do
16         arg="$1"; shift
17         case "$arg" in
18         -i)
19                 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
20                 head_from=-i
21                 diff_opts="$diff_opts --cached";
22                 diff_committed_only=;;
23         -w)
24                 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
25                 head_from=-w
26                 diff_committed_only=;;
27         -*)
28                 echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2
29                 exit 1;;
30         *)
31                 [ -z "$name" ] || die "name already specified ($name)"
32                 name="$arg";;
33         esac
34 done
35
36 head="$(git symbolic-ref HEAD)"
37 head="${head#refs/heads/}"
38
39 [ -n "$name" ] ||
40         name="$head"
41 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
42         die "not a TopGit-controlled branch"
43
44 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
45         die "$head_from makes only sense for the current branch"
46 fi
47
48
49
50 setup_pager
51
52 cat_file "$name:.topmsg" $head_from
53 echo
54 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
55
56 # Evil obnoxious hack to work around the lack of git diff --exclude
57 git_is_stupid="$(get_temp tg-patch-changes)"
58 git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
59         fgrep -vx ".topdeps" |
60         fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
61 if [ -s "$git_is_stupid" ]; then
62         cd "$root_dir"
63         cat "$git_is_stupid" | xargs git diff -a --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
64 else
65         echo "No changes."
66 fi
67
68 echo '-- '
69 echo "tg: ($base_rev..) $name (depends on: $(cat_file "$name:.topdeps" $head_from | paste -s -d' '))"
70 branch_contains "$name" "$base_rev" ||
71         echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."
72
73 # vim:noet