chiark / gitweb /
debian/changelog: document new upstream release
[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 topic=
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                 topic='(i)'
20                 diff_opts="$diff_opts --cached";
21                 diff_committed_only=;;
22         -w)
23                 topic='(w)'
24                 diff_committed_only=;;
25         -*)
26                 echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2
27                 exit 1;;
28         *)
29                 [ -z "$name" ] || die "name already specified ($name)"
30                 name="$arg";;
31         esac
32 done
33
34
35 [ -n "$name"  -a  -z "$diff_committed_only" ]  &&
36         die "-i/-w are mutually exclusive with NAME"
37
38 [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
39 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
40         die "not a TopGit-controlled branch"
41
42 # if not index/worktree, topic is current branch
43 [ -z "$topic" ] && topic="$name"
44
45
46
47 setup_pager
48
49 cat_file "$topic:.topmsg"
50 echo
51 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
52
53 # Evil obnoxious hack to work around the lack of git diff --exclude
54 git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
55 git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
56         fgrep -vx ".topdeps" |
57         fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
58 if [ -s "$git_is_stupid" ]; then
59         cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
60 else
61         echo "No changes."
62 fi
63 rm "$git_is_stupid"
64
65 echo '-- '
66 echo "tg: ($base_rev..) $name (depends on: $(cat_file "$topic:.topdeps" | paste -s -d' '))"
67 branch_contains "$name" "$base_rev" ||
68         echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."
69
70 # vim:noet