chiark / gitweb /
TopGit - A different patch queue manager
[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
9 ## Parse options
10
11 while [ -n "$1" ]; do
12         arg="$1"; shift
13         case "$arg" in
14         -*)
15                 echo "Usage: tg patch [NAME]" >&2
16                 exit 1;;
17         *)
18                 [ -z "$name" ] || die "name already specified ($name)"
19                 name="$arg";;
20         esac
21 done
22
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"
26
27 git cat-file blob "$name:.topmsg"
28 echo
29 [ -n "$(git grep '^[-]--' "$name" -- ".topmsg")" ] || echo '---'
30
31 # Evil obnoxious hack to work around the lack of git diff --exclude
32 git_is_stupid="$(mktemp)"
33 git diff-tree --name-only "$base_rev" "$name" |
34         fgrep -vx ".topdeps" |
35         fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
36 if [ -s "$git_is_stupid" ]; then
37         cat "$git_is_stupid" | xargs git diff --patch-with-stat "$base_rev" "$name" --
38 else
39         echo "No changes."
40 fi
41 rm "$git_is_stupid"
42
43 echo '-- '
44 echo "tg: ($base_rev..) $name (depends on $(git cat-file blob "$name:.topdeps"))"
45 branch_contains "$name" "$base_rev" ||
46         echo "tg: The patch is out-of-date wrt. the base! Run \`tg update\`."