README: fix typo
[topgit/pro.git] / tg-patch.sh
bloba1fc2eecbd5c6c63637a518bbf333fbd101fa8af
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # All rights reserved.
5 # GPLv2
7 name=
8 head_from=
9 binary=
11 ## Parse options
13 while [ -n "$1" ]; do
14 arg="$1"
15 case "$arg" in
16 --)
17 case "$2" in
18 -*)
19 shift; break;;
21 break;;
22 esac;;
23 -|-h|--help)
24 echo "Usage: ${tgname:-tg} [...] patch [-i | -w] [--binary] [<name>] [--] [<git-diff-tree-option>...]" >&2
25 exit 1;;
26 -i|-w)
27 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
28 head_from="$arg";;
29 --binary)
30 binary=1;;
31 -?*)
32 if test="$(verify_topgit_branch "$arg" -f)"; then
33 [ -z "$name" ] || die "name already specified ($name)"
34 name="$arg"
35 else
36 break
37 fi;;
39 [ -z "$name" ] || die "name already specified ($name)"
40 name="$arg";;
41 esac
42 shift
43 done
45 head="$(git symbolic-ref -q HEAD)" || :
46 head="${head#refs/heads/}"
48 [ -n "$name" ] ||
49 name="${head:-HEAD}"
50 name="$(verify_topgit_branch "$name")"
51 base_rev="$(git rev-parse --short --verify "refs/$topbases/$name" -- 2>/dev/null)" ||
52 die "not a TopGit-controlled branch"
54 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
55 die "$head_from makes only sense for the current branch"
60 # We now collect the rest of the code in this file into a function
61 # so we can redirect the output to the pager.
62 output()
65 # put out the commit message
66 # and put an empty line out, if the last one in the message was not an empty line
67 # and put out "---" if the commit message does not have one yet
68 cat_file "refs/heads/$name:.topmsg" $head_from |
69 awk '
70 /^---/ {
71 has_3dash=1;
74 need_empty = 1;
75 if ($0 == "")
76 need_empty = 0;
77 print;
79 END {
80 if (need_empty)
81 print "";
82 if (!has_3dash)
83 print "---";
87 b_tree=$(pretty_tree "$name" -b)
88 t_tree=$(pretty_tree "$name" $head_from)
90 if [ $b_tree = $t_tree ]; then
91 echo "No changes."
92 else
93 hasdd=
94 for a; do
95 [ "$a" != "--" ] || { hasdd=1; break; }
96 done
97 if [ -z "$hasdd" ]; then
98 git diff-tree -p --stat --summary ${binary:+--binary} "$@" $b_tree $t_tree
99 else
100 cmd="git diff-tree -p --stat --summary ${binary:+--binary}"
101 while [ $# -gt 0 -a "$1" != "--" ]; do
102 cmd="$cmd $(quotearg "$1")"
103 shift
104 done
105 cmd="$cmd $(quotearg "$b_tree") $(quotearg "$t_tree")"
106 while [ $# -gt 0 ]; do
107 cmd="$cmd $(quotearg "$1")"
108 shift
109 done
110 eval "$cmd"
114 echo '-- '
115 depon="$(cat_file "refs/heads/$name:.topdeps" $head_from 2>/dev/null | paste -s -d ' ' -)"
116 echo "$tgname: ($base_rev..) $name${depon:+ (depends on: $depon)}"
117 branch_contains "refs/heads/$name" "refs/$topbases/$name" ||
118 echo "$tgname: The patch is out-of-date wrt. the base! Run \`$tgdisplay update\`."
121 USE_PAGER_TYPE=diff
122 page output "$@"
123 # ... and then we run it through the pager with the page function
125 # vim:noet