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 | |
Junio C Hamano | 8273c79 | 2006-03-02 00:45:48 -0800 | [diff] [blame] | 5 | USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] |
| 6 | [--interactive] [--whitespace=<option>] <mbox>... |
freku045@student.liu.se | cf1fe88 | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 7 | or, when resuming [--skip | --resolved]' |
| 8 | . git-sh-setup |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 9 | |
Junio C Hamano | d64e6b0 | 2006-02-18 20:51:26 -0800 | [diff] [blame] | 10 | git var GIT_COMMITTER_IDENT >/dev/null || exit |
| 11 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 12 | stop_here () { |
| 13 | echo "$1" >"$dotest/next" |
| 14 | exit 1 |
| 15 | } |
| 16 | |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 17 | stop_here_user_resolve () { |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 18 | if [ -n "$resolvemsg" ]; then |
| 19 | echo "$resolvemsg" |
| 20 | stop_here $1 |
| 21 | fi |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 22 | cmdline=$(basename $0) |
| 23 | if test '' != "$interactive" |
| 24 | then |
| 25 | cmdline="$cmdline -i" |
| 26 | fi |
| 27 | if test '' != "$threeway" |
| 28 | then |
| 29 | cmdline="$cmdline -3" |
| 30 | fi |
| 31 | if test '.dotest' != "$dotest" |
| 32 | then |
| 33 | cmdline="$cmdline -d=$dotest" |
| 34 | fi |
| 35 | echo "When you have resolved this problem run \"$cmdline --resolved\"." |
| 36 | echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"." |
| 37 | |
| 38 | stop_here $1 |
| 39 | } |
| 40 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 41 | go_next () { |
| 42 | rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \ |
| 43 | "$dotest/patch" "$dotest/info" |
| 44 | echo "$next" >"$dotest/next" |
| 45 | this=$next |
| 46 | } |
| 47 | |
| 48 | fall_back_3way () { |
| 49 | O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd` |
| 50 | |
| 51 | rm -fr "$dotest"/patch-merge-* |
| 52 | mkdir "$dotest/patch-merge-tmp-dir" |
| 53 | |
| 54 | # First see if the patch records the index info that we can use. |
Junio C Hamano | 22943f1 | 2005-10-14 21:54:52 -0700 | [diff] [blame] | 55 | if git-apply -z --index-info "$dotest/patch" \ |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 56 | >"$dotest/patch-merge-index-info" 2>/dev/null && |
| 57 | GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
Junio C Hamano | 22943f1 | 2005-10-14 21:54:52 -0700 | [diff] [blame] | 58 | git-update-index -z --index-info <"$dotest/patch-merge-index-info" && |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 59 | GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
| 60 | git-write-tree >"$dotest/patch-merge-base+" && |
| 61 | # index has the base tree now. |
Junio C Hamano | b762727 | 2006-05-15 17:25:43 -0700 | [diff] [blame] | 62 | GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
| 63 | git-apply $binary --cached <"$dotest/patch" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 64 | then |
| 65 | echo Using index info to reconstruct a base tree... |
| 66 | mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base" |
| 67 | mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 68 | fi |
| 69 | |
| 70 | test -f "$dotest/patch-merge-index" && |
| 71 | his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git-write-tree) && |
| 72 | orig_tree=$(cat "$dotest/patch-merge-base") && |
| 73 | rm -fr "$dotest"/patch-merge-* || exit 1 |
| 74 | |
| 75 | echo Falling back to patching base and 3-way merge... |
| 76 | |
| 77 | # This is not so wrong. Depending on which base we picked, |
| 78 | # orig_tree may be wildly different from ours, but his_tree |
| 79 | # has the same set of wildly different changes in parts the |
| 80 | # patch did not touch, so resolve ends up cancelling them, |
| 81 | # saying that we reverted all those changes. |
| 82 | |
| 83 | git-merge-resolve $orig_tree -- HEAD $his_tree || { |
Junio C Hamano | 1536dd9c6 | 2006-02-11 18:55:43 -0800 | [diff] [blame] | 84 | if test -d "$GIT_DIR/rr-cache" |
| 85 | then |
| 86 | git-rerere |
| 87 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 88 | echo Failed to merge in the changes. |
| 89 | exit 1 |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | prec=4 |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 94 | dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 95 | |
| 96 | while case "$#" in 0) break;; esac |
| 97 | do |
| 98 | case "$1" in |
| 99 | -d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*) |
| 100 | dotest=`expr "$1" : '-[^=]*=\(.*\)'`; shift ;; |
| 101 | -d|--d|--do|--dot|--dote|--dotes|--dotest) |
| 102 | case "$#" in 1) usage ;; esac; shift |
| 103 | dotest="$1"; shift;; |
| 104 | |
| 105 | -i|--i|--in|--int|--inte|--inter|--intera|--interac|--interact|\ |
| 106 | --interacti|--interactiv|--interactive) |
| 107 | interactive=t; shift ;; |
| 108 | |
Junio C Hamano | 087b674 | 2005-11-16 16:46:24 -0800 | [diff] [blame] | 109 | -b|--b|--bi|--bin|--bina|--binar|--binary) |
| 110 | binary=t; shift ;; |
| 111 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 112 | -3|--3|--3w|--3wa|--3way) |
| 113 | threeway=t; shift ;; |
| 114 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
| 115 | sign=t; shift ;; |
| 116 | -u|--u|--ut|--utf|--utf8) |
| 117 | utf8=t; shift ;; |
| 118 | -k|--k|--ke|--kee|--keep) |
| 119 | keep=t; shift ;; |
| 120 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 121 | -r|--r|--re|--res|--reso|--resol|--resolv|--resolve|--resolved) |
| 122 | resolved=t; shift ;; |
| 123 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 124 | --sk|--ski|--skip) |
| 125 | skip=t; shift ;; |
| 126 | |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 127 | --whitespace=*) |
| 128 | ws=$1; shift ;; |
| 129 | |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 130 | --resolvemsg=*) |
| 131 | resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;; |
| 132 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 133 | --) |
| 134 | shift; break ;; |
| 135 | -*) |
| 136 | usage ;; |
| 137 | *) |
| 138 | break ;; |
| 139 | esac |
| 140 | done |
| 141 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 142 | # If the dotest directory exists, but we have finished applying all the |
| 143 | # patches in them, clear it out. |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 144 | if test -d "$dotest" && |
| 145 | last=$(cat "$dotest/last") && |
| 146 | next=$(cat "$dotest/next") && |
| 147 | test $# != 0 && |
| 148 | test "$next" -gt "$last" |
| 149 | then |
| 150 | rm -fr "$dotest" |
| 151 | fi |
| 152 | |
| 153 | if test -d "$dotest" |
| 154 | then |
| 155 | test ",$#," = ",0," || |
| 156 | die "previous dotest directory $dotest still exists but mbox given." |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 157 | resume=yes |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 158 | else |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 159 | # Make sure we are not given --skip nor --resolved |
| 160 | test ",$skip,$resolved," = ,,, || |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 161 | die "Resolve operation not in progress, we are not resuming." |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 162 | |
| 163 | # Start afresh. |
| 164 | mkdir -p "$dotest" || exit |
| 165 | |
H. Peter Anvin | b3f041f | 2005-12-13 22:39:23 -0800 | [diff] [blame] | 166 | git-mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 167 | rm -fr "$dotest" |
| 168 | exit 1 |
| 169 | } |
| 170 | |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 171 | # -b, -s, -u, -k and --whitespace flags are kept for the |
| 172 | # resuming session after a patch failure. |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 173 | # -3 and -i can and must be given when resuming. |
Junio C Hamano | 087b674 | 2005-11-16 16:46:24 -0800 | [diff] [blame] | 174 | echo "$binary" >"$dotest/binary" |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 175 | echo " $ws" >"$dotest/whitespace" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 176 | echo "$sign" >"$dotest/sign" |
| 177 | echo "$utf8" >"$dotest/utf8" |
| 178 | echo "$keep" >"$dotest/keep" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 179 | echo 1 >"$dotest/next" |
| 180 | fi |
| 181 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 182 | case "$resolved" in |
| 183 | '') |
| 184 | files=$(git-diff-index --cached --name-only HEAD) || exit |
| 185 | if [ "$files" ]; then |
| 186 | echo "Dirty index: cannot apply patches (dirty: $files)" >&2 |
| 187 | exit 1 |
| 188 | fi |
| 189 | esac |
| 190 | |
Junio C Hamano | 087b674 | 2005-11-16 16:46:24 -0800 | [diff] [blame] | 191 | if test "$(cat "$dotest/binary")" = t |
| 192 | then |
| 193 | binary=--allow-binary-replacement |
| 194 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 195 | if test "$(cat "$dotest/utf8")" = t |
| 196 | then |
| 197 | utf8=-u |
| 198 | fi |
| 199 | if test "$(cat "$dotest/keep")" = t |
| 200 | then |
| 201 | keep=-k |
| 202 | fi |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 203 | ws=`cat "$dotest/whitespace"` |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 204 | if test "$(cat "$dotest/sign")" = t |
| 205 | then |
| 206 | SIGNOFF=`git-var GIT_COMMITTER_IDENT | sed -e ' |
| 207 | s/>.*/>/ |
| 208 | s/^/Signed-off-by: /' |
| 209 | ` |
| 210 | else |
| 211 | SIGNOFF= |
| 212 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 213 | |
| 214 | last=`cat "$dotest/last"` |
| 215 | this=`cat "$dotest/next"` |
| 216 | if test "$skip" = t |
| 217 | then |
| 218 | this=`expr "$this" + 1` |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 219 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 220 | fi |
| 221 | |
| 222 | if test "$this" -gt "$last" |
| 223 | then |
| 224 | echo Nothing to do. |
| 225 | rm -fr "$dotest" |
| 226 | exit |
| 227 | fi |
| 228 | |
| 229 | while test "$this" -le "$last" |
| 230 | do |
| 231 | msgnum=`printf "%0${prec}d" $this` |
| 232 | next=`expr "$this" + 1` |
| 233 | test -f "$dotest/$msgnum" || { |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 234 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 235 | go_next |
| 236 | continue |
| 237 | } |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 238 | |
| 239 | # If we are not resuming, parse and extract the patch information |
| 240 | # into separate files: |
| 241 | # - info records the authorship and title |
| 242 | # - msg is the rest of commit log message |
| 243 | # - patch is the patch body. |
| 244 | # |
| 245 | # When we are resuming, these files are either already prepared |
| 246 | # 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] | 247 | case "$resume" in |
| 248 | '') |
| 249 | git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \ |
| 250 | <"$dotest/$msgnum" >"$dotest/info" || |
| 251 | stop_here $this |
| 252 | git-stripspace < "$dotest/msg" > "$dotest/msg-clean" |
| 253 | ;; |
| 254 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 255 | |
| 256 | GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")" |
| 257 | GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")" |
| 258 | GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")" |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 259 | |
| 260 | if test -z "$GIT_AUTHOR_EMAIL" |
| 261 | then |
| 262 | echo "Patch does not have a valid e-mail address." |
| 263 | stop_here $this |
| 264 | fi |
| 265 | |
Junio C Hamano | 2c67419 | 2005-10-20 22:31:56 -0700 | [diff] [blame] | 266 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 267 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 268 | SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 269 | case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 270 | |
| 271 | case "$resume" in |
| 272 | '') |
| 273 | if test '' != "$SIGNOFF" |
| 274 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 275 | LAST_SIGNED_OFF_BY=` |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 276 | sed -ne '/^Signed-off-by: /p' \ |
| 277 | "$dotest/msg-clean" | |
| 278 | tail -n 1 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 279 | ` |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 280 | ADD_SIGNOFF=` |
| 281 | test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 282 | test '' = "$LAST_SIGNED_OFF_BY" && echo |
| 283 | echo "$SIGNOFF" |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 284 | }` |
| 285 | else |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 286 | ADD_SIGNOFF= |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 287 | fi |
| 288 | { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 289 | echo "$SUBJECT" |
| 290 | if test -s "$dotest/msg-clean" |
| 291 | then |
| 292 | echo |
| 293 | cat "$dotest/msg-clean" |
| 294 | fi |
| 295 | if test '' != "$ADD_SIGNOFF" |
| 296 | then |
| 297 | echo "$ADD_SIGNOFF" |
| 298 | fi |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 299 | } >"$dotest/final-commit" |
| 300 | ;; |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 301 | *) |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 302 | case "$resolved$interactive" in |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 303 | tt) |
| 304 | # This is used only for interactive view option. |
| 305 | git-diff-index -p --cached HEAD >"$dotest/patch" |
| 306 | ;; |
| 307 | esac |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 308 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 309 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 310 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 311 | if test "$interactive" = t |
| 312 | then |
Junio C Hamano | a145110 | 2005-10-12 18:31:41 -0700 | [diff] [blame] | 313 | test -t 0 || |
| 314 | die "cannot be interactive without stdin connected to a terminal." |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 315 | action=again |
| 316 | while test "$action" = again |
| 317 | do |
| 318 | echo "Commit Body is:" |
| 319 | echo "--------------------------" |
| 320 | cat "$dotest/final-commit" |
| 321 | echo "--------------------------" |
Jason Riedy | 9754563 | 2005-12-06 14:21:52 -0800 | [diff] [blame] | 322 | 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] | 323 | read reply |
| 324 | case "$reply" in |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 325 | [yY]*) action=yes ;; |
| 326 | [aA]*) action=yes interactive= ;; |
| 327 | [nN]*) action=skip ;; |
| 328 | [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 329 | action=again ;; |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 330 | [vV]*) action=again |
| 331 | LESS=-S ${PAGER:-less} "$dotest/patch" ;; |
| 332 | *) action=again ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 333 | esac |
| 334 | done |
| 335 | else |
| 336 | action=yes |
| 337 | fi |
| 338 | |
| 339 | if test $action = skip |
| 340 | then |
| 341 | go_next |
| 342 | continue |
| 343 | fi |
| 344 | |
| 345 | if test -x "$GIT_DIR"/hooks/applypatch-msg |
| 346 | then |
| 347 | "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" || |
| 348 | stop_here $this |
| 349 | fi |
| 350 | |
| 351 | echo |
| 352 | echo "Applying '$SUBJECT'" |
| 353 | echo |
| 354 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 355 | case "$resolved" in |
| 356 | '') |
Junio C Hamano | 8c31cb8 | 2006-02-28 20:26:25 -0800 | [diff] [blame] | 357 | git-apply $binary --index $ws "$dotest/patch" |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 358 | apply_status=$? |
| 359 | ;; |
| 360 | t) |
| 361 | # Resolved means the user did all the hard work, and |
| 362 | # we do not have to do any patch application. Just |
| 363 | # trust what the user has in the index file and the |
| 364 | # working tree. |
| 365 | resolved= |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 366 | changed="$(git-diff-index --cached --name-only HEAD)" |
| 367 | if test '' = "$changed" |
| 368 | then |
| 369 | echo "No changes - did you forget update-index?" |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 370 | stop_here_user_resolve $this |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 371 | fi |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 372 | unmerged=$(git-ls-files -u) |
| 373 | if test -n "$unmerged" |
| 374 | then |
| 375 | echo "You still have unmerged paths in your index" |
| 376 | echo "did you forget update-index?" |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 377 | stop_here_user_resolve $this |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 378 | fi |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 379 | apply_status=0 |
| 380 | ;; |
| 381 | esac |
| 382 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 383 | if test $apply_status = 1 && test "$threeway" = t |
| 384 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 385 | if (fall_back_3way) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 386 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 387 | # Applying the patch to an earlier tree and merging the |
| 388 | # result may have produced the same tree as ours. |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 389 | changed="$(git-diff-index --cached --name-only HEAD)" |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 390 | if test '' = "$changed" |
| 391 | then |
| 392 | echo No changes -- Patch already applied. |
| 393 | go_next |
| 394 | continue |
| 395 | fi |
| 396 | # clear apply_status -- we have successfully merged. |
| 397 | apply_status=0 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 398 | fi |
| 399 | fi |
| 400 | if test $apply_status != 0 |
| 401 | then |
| 402 | echo Patch failed at $msgnum. |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 403 | stop_here_user_resolve $this |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 404 | fi |
| 405 | |
| 406 | if test -x "$GIT_DIR"/hooks/pre-applypatch |
| 407 | then |
| 408 | "$GIT_DIR"/hooks/pre-applypatch || stop_here $this |
| 409 | fi |
| 410 | |
| 411 | tree=$(git-write-tree) && |
| 412 | echo Wrote tree $tree && |
| 413 | parent=$(git-rev-parse --verify HEAD) && |
| 414 | commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") && |
| 415 | echo Committed: $commit && |
Shawn Pearce | 67644a4 | 2006-05-19 05:16:18 -0400 | [diff] [blame] | 416 | git-update-ref -m "am: $SUBJECT" HEAD $commit $parent || |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 417 | stop_here $this |
| 418 | |
| 419 | if test -x "$GIT_DIR"/hooks/post-applypatch |
| 420 | then |
| 421 | "$GIT_DIR"/hooks/post-applypatch |
| 422 | fi |
| 423 | |
| 424 | go_next |
| 425 | done |
| 426 | |
| 427 | rm -fr "$dotest" |