Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Junio C Hamano | d64e6b0 | 2006-02-18 20:51:26 -0800 | [diff] [blame] | 3 | # Copyright (c) 2005, 2006 Junio C Hamano |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 4 | |
Jeff King | c149184 | 2008-03-01 01:22:55 -0500 | [diff] [blame] | 5 | SUBDIRECTORY_OK=Yes |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 6 | OPTIONS_KEEPDASHDASH= |
| 7 | OPTIONS_SPEC="\ |
| 8 | git-am [options] <mbox>|<Maildir>... |
| 9 | git-am [options] --resolved |
| 10 | git-am [options] --skip |
| 11 | -- |
Junio C Hamano | e72c740 | 2008-03-04 00:25:05 -0800 | [diff] [blame] | 12 | d,dotest= (removed -- do not use) |
Junio C Hamano | 66006c6 | 2007-11-08 23:04:31 -0800 | [diff] [blame] | 13 | i,interactive run interactively |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 14 | b,binary pass --allo-binary-replacement to git-apply |
| 15 | 3,3way allow fall back on 3way merging if needed |
| 16 | s,signoff add a Signed-off-by line to the commit message |
| 17 | u,utf8 recode into utf8 (default) |
Jörg Sommer | fe1fa94 | 2008-02-03 00:58:06 +0100 | [diff] [blame] | 18 | k,keep pass -k flag to git-mailinfo |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 19 | whitespace= pass it through git-apply |
| 20 | C= pass it through git-apply |
| 21 | p= pass it through git-apply |
| 22 | resolvemsg= override error message when patch failure occurs |
| 23 | r,resolved to be used after a patch failure |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 24 | skip skip the current patch |
| 25 | rebasing (internal use for git-rebase)" |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 26 | |
freku045@student.liu.se | cf1fe88 | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 27 | . git-sh-setup |
Junio C Hamano | bb034f8 | 2008-03-04 00:25:04 -0800 | [diff] [blame] | 28 | prefix=$(git rev-parse --show-prefix) |
Shawn O. Pearce | f947413 | 2006-12-28 02:34:48 -0500 | [diff] [blame] | 29 | set_reflog_action am |
Shawn O. Pearce | 7eff28a | 2006-12-30 23:32:38 -0500 | [diff] [blame] | 30 | require_work_tree |
Jeff King | c149184 | 2008-03-01 01:22:55 -0500 | [diff] [blame] | 31 | cd_to_toplevel |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 32 | |
Junio C Hamano | d64e6b0 | 2006-02-18 20:51:26 -0800 | [diff] [blame] | 33 | git var GIT_COMMITTER_IDENT >/dev/null || exit |
| 34 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 35 | stop_here () { |
| 36 | echo "$1" >"$dotest/next" |
| 37 | exit 1 |
| 38 | } |
| 39 | |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 40 | stop_here_user_resolve () { |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 41 | if [ -n "$resolvemsg" ]; then |
Jeff King | a23bfae | 2007-05-26 00:33:03 -0700 | [diff] [blame] | 42 | printf '%s\n' "$resolvemsg" |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 43 | stop_here $1 |
| 44 | fi |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 45 | cmdline=$(basename $0) |
| 46 | if test '' != "$interactive" |
| 47 | then |
| 48 | cmdline="$cmdline -i" |
| 49 | fi |
| 50 | if test '' != "$threeway" |
| 51 | then |
| 52 | cmdline="$cmdline -3" |
| 53 | fi |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 54 | echo "When you have resolved this problem run \"$cmdline --resolved\"." |
| 55 | echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"." |
| 56 | |
| 57 | stop_here $1 |
| 58 | } |
| 59 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 60 | go_next () { |
| 61 | rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \ |
| 62 | "$dotest/patch" "$dotest/info" |
| 63 | echo "$next" >"$dotest/next" |
| 64 | this=$next |
| 65 | } |
| 66 | |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 67 | cannot_fallback () { |
| 68 | echo "$1" |
| 69 | echo "Cannot fall back to three-way merge." |
| 70 | exit 1 |
| 71 | } |
| 72 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 73 | fall_back_3way () { |
| 74 | O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd` |
| 75 | |
| 76 | rm -fr "$dotest"/patch-merge-* |
| 77 | mkdir "$dotest/patch-merge-tmp-dir" |
| 78 | |
| 79 | # First see if the patch records the index info that we can use. |
Johannes Schindelin | 7a98869 | 2007-09-17 23:34:06 +0100 | [diff] [blame] | 80 | git apply --build-fake-ancestor "$dotest/patch-merge-tmp-index" \ |
| 81 | "$dotest/patch" && |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 82 | GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 83 | git write-tree >"$dotest/patch-merge-base+" || |
Junio C Hamano | b1440cc | 2007-02-24 01:05:27 -0800 | [diff] [blame] | 84 | cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge." |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 85 | |
| 86 | echo Using index info to reconstruct a base tree... |
| 87 | if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 88 | git apply $binary --cached <"$dotest/patch" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 89 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 90 | mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base" |
| 91 | mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index" |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 92 | else |
| 93 | cannot_fallback "Did you hand edit your patch? |
| 94 | It does not apply to blobs recorded in its index." |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 95 | fi |
| 96 | |
| 97 | test -f "$dotest/patch-merge-index" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 98 | his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) && |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 99 | orig_tree=$(cat "$dotest/patch-merge-base") && |
| 100 | rm -fr "$dotest"/patch-merge-* || exit 1 |
| 101 | |
| 102 | echo Falling back to patching base and 3-way merge... |
| 103 | |
| 104 | # This is not so wrong. Depending on which base we picked, |
| 105 | # orig_tree may be wildly different from ours, but his_tree |
| 106 | # has the same set of wildly different changes in parts the |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 107 | # patch did not touch, so recursive ends up canceling them, |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 108 | # saying that we reverted all those changes. |
| 109 | |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 110 | eval GITHEAD_$his_tree='"$FIRSTLINE"' |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 111 | export GITHEAD_$his_tree |
| 112 | git-merge-recursive $orig_tree -- HEAD $his_tree || { |
Johannes Schindelin | b4372ef | 2007-07-06 13:05:59 +0100 | [diff] [blame] | 113 | git rerere |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 114 | echo Failed to merge in the changes. |
| 115 | exit 1 |
| 116 | } |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 117 | unset GITHEAD_$his_tree |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | prec=4 |
Junio C Hamano | e72c740 | 2008-03-04 00:25:05 -0800 | [diff] [blame] | 121 | dotest=".dotest" |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 122 | sign= utf8=t keep= skip= interactive= resolved= binary= rebasing= |
Gerrit Pape | 3f0a8f3 | 2007-08-06 14:15:30 +0000 | [diff] [blame] | 123 | resolvemsg= resume= |
Michael S. Tsirkin | 67dad68 | 2007-02-08 15:57:08 +0200 | [diff] [blame] | 124 | git_apply_opt= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 125 | |
David Kastrup | 822f7c7 | 2007-09-23 22:42:08 +0200 | [diff] [blame] | 126 | while test $# != 0 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 127 | do |
| 128 | case "$1" in |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 129 | -i|--interactive) |
| 130 | interactive=t ;; |
| 131 | -b|--binary) |
| 132 | binary=t ;; |
| 133 | -3|--3way) |
| 134 | threeway=t ;; |
Johannes Sixt | dfdd7e6 | 2007-11-06 21:33:58 +0100 | [diff] [blame] | 135 | -s|--signoff) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 136 | sign=t ;; |
| 137 | -u|--utf8) |
| 138 | utf8=t ;; # this is now default |
| 139 | --no-utf8) |
| 140 | utf8= ;; |
| 141 | -k|--keep) |
| 142 | keep=t ;; |
| 143 | -r|--resolved) |
| 144 | resolved=t ;; |
| 145 | --skip) |
| 146 | skip=t ;; |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 147 | --rebasing) |
| 148 | rebasing=t threeway=t keep=t binary=t ;; |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 149 | -d|--dotest) |
Junio C Hamano | e72c740 | 2008-03-04 00:25:05 -0800 | [diff] [blame] | 150 | die "-d option is no longer supported. Do not use." |
| 151 | ;; |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 152 | --resolvemsg) |
| 153 | shift; resolvemsg=$1 ;; |
| 154 | --whitespace) |
| 155 | git_apply_opt="$git_apply_opt $1=$2"; shift ;; |
| 156 | -C|-p) |
| 157 | git_apply_opt="$git_apply_opt $1$2"; shift ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 158 | --) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 159 | shift; break ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 160 | *) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 161 | usage ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 162 | esac |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 163 | shift |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 164 | done |
| 165 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 166 | # If the dotest directory exists, but we have finished applying all the |
| 167 | # patches in them, clear it out. |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 168 | if test -d "$dotest" && |
| 169 | last=$(cat "$dotest/last") && |
| 170 | next=$(cat "$dotest/next") && |
| 171 | test $# != 0 && |
| 172 | test "$next" -gt "$last" |
| 173 | then |
| 174 | rm -fr "$dotest" |
| 175 | fi |
| 176 | |
| 177 | if test -d "$dotest" |
| 178 | then |
Junio C Hamano | c95b138 | 2006-09-15 23:19:02 -0700 | [diff] [blame] | 179 | case "$#,$skip$resolved" in |
| 180 | 0,*t*) |
| 181 | # Explicit resume command and we do not have file, so |
| 182 | # we are happy. |
| 183 | : ;; |
| 184 | 0,) |
| 185 | # No file input but without resume parameters; catch |
| 186 | # user error to feed us a patch from standard input |
Junio C Hamano | e72c740 | 2008-03-04 00:25:05 -0800 | [diff] [blame] | 187 | # when there is already $dotest. This is somewhat |
Junio C Hamano | c95b138 | 2006-09-15 23:19:02 -0700 | [diff] [blame] | 188 | # unreliable -- stdin could be /dev/null for example |
| 189 | # and the caller did not intend to feed us a patch but |
| 190 | # wanted to continue unattended. |
| 191 | tty -s |
| 192 | ;; |
| 193 | *) |
| 194 | false |
| 195 | ;; |
| 196 | esac || |
| 197 | die "previous dotest directory $dotest still exists but mbox given." |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 198 | resume=yes |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 199 | else |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 200 | # Make sure we are not given --skip nor --resolved |
| 201 | test ",$skip,$resolved," = ,,, || |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 202 | die "Resolve operation not in progress, we are not resuming." |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 203 | |
| 204 | # Start afresh. |
| 205 | mkdir -p "$dotest" || exit |
| 206 | |
Junio C Hamano | bb034f8 | 2008-03-04 00:25:04 -0800 | [diff] [blame] | 207 | if test -n "$prefix" && test $# != 0 |
| 208 | then |
| 209 | first=t |
| 210 | for arg |
| 211 | do |
| 212 | test -n "$first" && { |
| 213 | set x |
| 214 | first= |
| 215 | } |
| 216 | case "$arg" in |
| 217 | /*) |
| 218 | set "$@" "$arg" ;; |
| 219 | *) |
| 220 | set "$@" "$prefix$arg" ;; |
| 221 | esac |
| 222 | done |
| 223 | shift |
| 224 | fi |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 225 | git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 226 | rm -fr "$dotest" |
| 227 | exit 1 |
| 228 | } |
| 229 | |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 230 | # -b, -s, -u, -k and --whitespace flags are kept for the |
| 231 | # resuming session after a patch failure. |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 232 | # -3 and -i can and must be given when resuming. |
Junio C Hamano | 087b674 | 2005-11-16 16:46:24 -0800 | [diff] [blame] | 233 | echo "$binary" >"$dotest/binary" |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 234 | echo " $ws" >"$dotest/whitespace" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 235 | echo "$sign" >"$dotest/sign" |
| 236 | echo "$utf8" >"$dotest/utf8" |
| 237 | echo "$keep" >"$dotest/keep" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 238 | echo 1 >"$dotest/next" |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 239 | if test -n "$rebasing" |
| 240 | then |
| 241 | : >"$dotest/rebasing" |
| 242 | else |
| 243 | : >"$dotest/applying" |
| 244 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 245 | fi |
| 246 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 247 | case "$resolved" in |
| 248 | '') |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 249 | files=$(git diff-index --cached --name-only HEAD --) || exit |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 250 | if [ "$files" ]; then |
| 251 | echo "Dirty index: cannot apply patches (dirty: $files)" >&2 |
| 252 | exit 1 |
| 253 | fi |
| 254 | esac |
| 255 | |
Junio C Hamano | 087b674 | 2005-11-16 16:46:24 -0800 | [diff] [blame] | 256 | if test "$(cat "$dotest/binary")" = t |
| 257 | then |
| 258 | binary=--allow-binary-replacement |
| 259 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 260 | if test "$(cat "$dotest/utf8")" = t |
| 261 | then |
| 262 | utf8=-u |
Junio C Hamano | bb1091a | 2007-01-09 21:31:36 -0800 | [diff] [blame] | 263 | else |
| 264 | utf8=-n |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 265 | fi |
| 266 | if test "$(cat "$dotest/keep")" = t |
| 267 | then |
| 268 | keep=-k |
| 269 | fi |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 270 | ws=`cat "$dotest/whitespace"` |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 271 | if test "$(cat "$dotest/sign")" = t |
| 272 | then |
| 273 | SIGNOFF=`git-var GIT_COMMITTER_IDENT | sed -e ' |
| 274 | s/>.*/>/ |
| 275 | s/^/Signed-off-by: /' |
| 276 | ` |
| 277 | else |
| 278 | SIGNOFF= |
| 279 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 280 | |
| 281 | last=`cat "$dotest/last"` |
| 282 | this=`cat "$dotest/next"` |
| 283 | if test "$skip" = t |
| 284 | then |
Johannes Schindelin | b4372ef | 2007-07-06 13:05:59 +0100 | [diff] [blame] | 285 | git rerere clear |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 286 | this=`expr "$this" + 1` |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 287 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 288 | fi |
| 289 | |
| 290 | if test "$this" -gt "$last" |
| 291 | then |
| 292 | echo Nothing to do. |
| 293 | rm -fr "$dotest" |
| 294 | exit |
| 295 | fi |
| 296 | |
| 297 | while test "$this" -le "$last" |
| 298 | do |
| 299 | msgnum=`printf "%0${prec}d" $this` |
| 300 | next=`expr "$this" + 1` |
| 301 | test -f "$dotest/$msgnum" || { |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 302 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 303 | go_next |
| 304 | continue |
| 305 | } |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 306 | |
| 307 | # If we are not resuming, parse and extract the patch information |
| 308 | # into separate files: |
| 309 | # - info records the authorship and title |
| 310 | # - msg is the rest of commit log message |
| 311 | # - patch is the patch body. |
| 312 | # |
| 313 | # When we are resuming, these files are either already prepared |
| 314 | # by the user, or the user can tell us to do so by --resolved flag. |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 315 | case "$resume" in |
| 316 | '') |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 317 | git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \ |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 318 | <"$dotest/$msgnum" >"$dotest/info" || |
| 319 | stop_here $this |
Johannes Schindelin | ca193cf | 2007-07-24 01:02:25 +0100 | [diff] [blame] | 320 | |
| 321 | # skip pine's internal folder data |
| 322 | grep '^Author: Mail System Internal Data$' \ |
| 323 | <"$dotest"/info >/dev/null && |
| 324 | go_next && continue |
| 325 | |
Don Zickus | 87ab799 | 2007-03-12 15:52:04 -0400 | [diff] [blame] | 326 | test -s $dotest/patch || { |
Josh Triplett | 6777c38 | 2007-04-23 17:32:04 -0700 | [diff] [blame] | 327 | echo "Patch is empty. Was it split wrong?" |
Don Zickus | 87ab799 | 2007-03-12 15:52:04 -0400 | [diff] [blame] | 328 | stop_here $this |
| 329 | } |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 330 | if test -f "$dotest/rebasing" && |
| 331 | commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ |
| 332 | -e q "$dotest/$msgnum") && |
| 333 | test "$(git cat-file -t "$commit")" = commit |
| 334 | then |
| 335 | git cat-file commit "$commit" | |
| 336 | sed -e '1,/^$/d' >"$dotest/msg-clean" |
| 337 | else |
| 338 | SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")" |
| 339 | case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 340 | |
Junio C Hamano | 8876046 | 2008-04-19 00:25:15 -0700 | [diff] [blame] | 341 | (printf '%s\n\n' "$SUBJECT"; cat "$dotest/msg") | |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 342 | git stripspace > "$dotest/msg-clean" |
| 343 | fi |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 344 | ;; |
| 345 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 346 | |
| 347 | GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")" |
| 348 | GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")" |
| 349 | GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")" |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 350 | |
Junio C Hamano | 3b78959 | 2007-12-05 13:16:35 -0800 | [diff] [blame] | 351 | if test -z "$GIT_AUTHOR_EMAIL" |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 352 | then |
Junio C Hamano | 3b78959 | 2007-12-05 13:16:35 -0800 | [diff] [blame] | 353 | echo "Patch does not have a valid e-mail address." |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 354 | stop_here $this |
| 355 | fi |
| 356 | |
Junio C Hamano | 2c67419 | 2005-10-20 22:31:56 -0700 | [diff] [blame] | 357 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 358 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 359 | case "$resume" in |
| 360 | '') |
| 361 | if test '' != "$SIGNOFF" |
| 362 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 363 | LAST_SIGNED_OFF_BY=` |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 364 | sed -ne '/^Signed-off-by: /p' \ |
| 365 | "$dotest/msg-clean" | |
Jeff King | b4ce54f | 2008-03-12 17:34:34 -0400 | [diff] [blame] | 366 | sed -ne '$p' |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 367 | ` |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 368 | ADD_SIGNOFF=` |
| 369 | test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 370 | test '' = "$LAST_SIGNED_OFF_BY" && echo |
| 371 | echo "$SIGNOFF" |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 372 | }` |
| 373 | else |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 374 | ADD_SIGNOFF= |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 375 | fi |
| 376 | { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 377 | if test -s "$dotest/msg-clean" |
| 378 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 379 | cat "$dotest/msg-clean" |
| 380 | fi |
| 381 | if test '' != "$ADD_SIGNOFF" |
| 382 | then |
| 383 | echo "$ADD_SIGNOFF" |
| 384 | fi |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 385 | } >"$dotest/final-commit" |
| 386 | ;; |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 387 | *) |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 388 | case "$resolved$interactive" in |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 389 | tt) |
| 390 | # This is used only for interactive view option. |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 391 | git diff-index -p --cached HEAD -- >"$dotest/patch" |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 392 | ;; |
| 393 | esac |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 394 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 395 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 396 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 397 | if test "$interactive" = t |
| 398 | then |
Junio C Hamano | a145110 | 2005-10-12 18:31:41 -0700 | [diff] [blame] | 399 | test -t 0 || |
| 400 | die "cannot be interactive without stdin connected to a terminal." |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 401 | action=again |
| 402 | while test "$action" = again |
| 403 | do |
| 404 | echo "Commit Body is:" |
| 405 | echo "--------------------------" |
| 406 | cat "$dotest/final-commit" |
| 407 | echo "--------------------------" |
Jason Riedy | 9754563 | 2005-12-06 14:21:52 -0800 | [diff] [blame] | 408 | printf "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all " |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 409 | read reply |
| 410 | case "$reply" in |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 411 | [yY]*) action=yes ;; |
| 412 | [aA]*) action=yes interactive= ;; |
| 413 | [nN]*) action=skip ;; |
Adam Roben | ef0c2ab | 2007-07-19 22:09:35 -0700 | [diff] [blame] | 414 | [eE]*) git_editor "$dotest/final-commit" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 415 | action=again ;; |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 416 | [vV]*) action=again |
| 417 | LESS=-S ${PAGER:-less} "$dotest/patch" ;; |
| 418 | *) action=again ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 419 | esac |
| 420 | done |
| 421 | else |
| 422 | action=yes |
| 423 | fi |
Junio C Hamano | 11dc4e7 | 2008-04-16 16:46:26 -0700 | [diff] [blame] | 424 | FIRSTLINE=$(head -1 "$dotest/final-commit") |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 425 | |
| 426 | if test $action = skip |
| 427 | then |
| 428 | go_next |
| 429 | continue |
| 430 | fi |
| 431 | |
| 432 | if test -x "$GIT_DIR"/hooks/applypatch-msg |
| 433 | then |
| 434 | "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" || |
| 435 | stop_here $this |
| 436 | fi |
| 437 | |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 438 | printf 'Applying %s\n' "$FIRSTLINE" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 439 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 440 | case "$resolved" in |
| 441 | '') |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 442 | git apply $git_apply_opt $binary --index "$dotest/patch" |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 443 | apply_status=$? |
| 444 | ;; |
| 445 | t) |
| 446 | # Resolved means the user did all the hard work, and |
| 447 | # we do not have to do any patch application. Just |
| 448 | # trust what the user has in the index file and the |
| 449 | # working tree. |
| 450 | resolved= |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 451 | git diff-index --quiet --cached HEAD -- && { |
Shawn O. Pearce | 64646d1 | 2006-12-21 21:30:17 -0500 | [diff] [blame] | 452 | echo "No changes - did you forget to use 'git add'?" |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 453 | stop_here_user_resolve $this |
Alex Riesen | 06aff47 | 2007-03-25 01:56:13 +0100 | [diff] [blame] | 454 | } |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 455 | unmerged=$(git ls-files -u) |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 456 | if test -n "$unmerged" |
| 457 | then |
| 458 | echo "You still have unmerged paths in your index" |
Shawn O. Pearce | 64646d1 | 2006-12-21 21:30:17 -0500 | [diff] [blame] | 459 | echo "did you forget to use 'git add'?" |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 460 | stop_here_user_resolve $this |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 461 | fi |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 462 | apply_status=0 |
Johannes Schindelin | b4372ef | 2007-07-06 13:05:59 +0100 | [diff] [blame] | 463 | git rerere |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 464 | ;; |
| 465 | esac |
| 466 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 467 | if test $apply_status = 1 && test "$threeway" = t |
| 468 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 469 | if (fall_back_3way) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 470 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 471 | # Applying the patch to an earlier tree and merging the |
| 472 | # result may have produced the same tree as ours. |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 473 | git diff-index --quiet --cached HEAD -- && { |
Alex Riesen | 06aff47 | 2007-03-25 01:56:13 +0100 | [diff] [blame] | 474 | echo No changes -- Patch already applied. |
| 475 | go_next |
| 476 | continue |
| 477 | } |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 478 | # clear apply_status -- we have successfully merged. |
| 479 | apply_status=0 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 480 | fi |
| 481 | fi |
| 482 | if test $apply_status != 0 |
| 483 | then |
| 484 | echo Patch failed at $msgnum. |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 485 | stop_here_user_resolve $this |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 486 | fi |
| 487 | |
| 488 | if test -x "$GIT_DIR"/hooks/pre-applypatch |
| 489 | then |
| 490 | "$GIT_DIR"/hooks/pre-applypatch || stop_here $this |
| 491 | fi |
| 492 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 493 | tree=$(git write-tree) && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 494 | parent=$(git rev-parse --verify HEAD) && |
| 495 | commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") && |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 496 | git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 497 | stop_here $this |
| 498 | |
| 499 | if test -x "$GIT_DIR"/hooks/post-applypatch |
| 500 | then |
| 501 | "$GIT_DIR"/hooks/post-applypatch |
| 502 | fi |
| 503 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 504 | go_next |
| 505 | done |
| 506 | |
Michael Stefaniuc | e0cd252 | 2008-01-04 19:59:26 +0100 | [diff] [blame] | 507 | git gc --auto |
| 508 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 509 | rm -fr "$dotest" |