2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
10 diff_committed_only=yes # will be unset for index/worktree
20 diff_opts="$diff_opts --cached";
21 diff_committed_only=;;
24 diff_committed_only=;;
26 echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2
29 [ -z "$name" ] || die "name already specified ($name)"
35 [ -n "$name" -a -z "$diff_committed_only" ] &&
36 die "-i/-w are mutually exclusive with NAME"
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"
42 # if not index/worktree, topic is current branch
43 [ -z "$topic" ] && topic="$name"
49 cat_file "$topic:.topmsg"
51 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
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
60 cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
67 echo "tg: ($base_rev..) $name (depends on: $(cat_file "$topic:.topdeps" | paste -s -d' '))"
68 branch_contains "$name" "$base_rev" ||
69 echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."