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= |
Nicolas Vigier | 8833662 | 2014-02-01 02:18:00 +0000 | [diff] [blame] | 7 | OPTIONS_STUCKLONG=t |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 8 | OPTIONS_SPEC="\ |
Štěpán Němec | 0adda93 | 2010-10-08 19:31:17 +0200 | [diff] [blame] | 9 | git am [options] [(<mbox>|<Maildir>)...] |
Kevin Bracey | 8ceb6fb | 2013-06-26 23:06:41 +0300 | [diff] [blame] | 10 | git am [options] (--continue | --skip | --abort) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 11 | -- |
Junio C Hamano | 66006c6 | 2007-11-08 23:04:31 -0800 | [diff] [blame] | 12 | i,interactive run interactively |
Jay Soffian | 98ef23b | 2009-01-28 10:03:10 -0500 | [diff] [blame] | 13 | b,binary* (historical option -- no-op) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 14 | 3,3way allow fall back on 3way merging if needed |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 15 | q,quiet be quiet |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 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 |
Thomas Rast | f7e5ea1 | 2012-01-16 11:53:00 +0100 | [diff] [blame] | 19 | keep-non-patch pass -b flag to git-mailinfo |
Stefan-W. Hahn | ad2c928 | 2010-02-27 15:20:26 +0100 | [diff] [blame] | 20 | keep-cr pass --keep-cr flag to git-mailsplit for mbox format |
Stefan-W. Hahn | e80d4cb | 2010-02-27 15:20:27 +0100 | [diff] [blame] | 21 | no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr |
Junio C Hamano | 017678b | 2009-08-26 21:36:05 -0700 | [diff] [blame] | 22 | c,scissors strip everything before a scissors line |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 23 | whitespace= pass it through git-apply |
Giuseppe Bilotta | 86c91f9 | 2009-08-04 13:16:49 +0200 | [diff] [blame] | 24 | ignore-space-change pass it through git-apply |
| 25 | ignore-whitespace pass it through git-apply |
Junio C Hamano | b47dfe9 | 2009-01-11 22:21:48 -0800 | [diff] [blame] | 26 | directory= pass it through git-apply |
maximilian attems | 77e9e49 | 2011-08-03 11:37:29 +0200 | [diff] [blame] | 27 | exclude= pass it through git-apply |
Johannes Berg | 58725ef | 2012-03-28 13:11:28 +0200 | [diff] [blame] | 28 | include= pass it through git-apply |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 29 | C= pass it through git-apply |
| 30 | p= pass it through git-apply |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 31 | patch-format= format the patch(es) are in |
martin f. krafft | b80da42 | 2009-01-23 11:31:21 +1100 | [diff] [blame] | 32 | reject pass it through git-apply |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 33 | resolvemsg= override error message when patch failure occurs |
Jeff King | c8089af | 2010-02-11 17:27:14 -0500 | [diff] [blame] | 34 | continue continue applying patches after resolving a conflict |
| 35 | r,resolved synonyms for --continue |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 36 | skip skip the current patch |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 37 | abort restore the original branch and abort the patching operation. |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 38 | committer-date-is-author-date lie about committer date |
Nanako Shiraishi | a79ec62 | 2009-01-24 10:18:02 +0900 | [diff] [blame] | 39 | ignore-date use current timestamp for author date |
Junio C Hamano | cb6020b | 2009-12-04 00:20:48 -0800 | [diff] [blame] | 40 | rerere-autoupdate update the index with reused conflict resolution if possible |
Nicolas Vigier | 3b4e395f | 2014-02-01 02:18:01 +0000 | [diff] [blame] | 41 | S,gpg-sign? GPG-sign commits |
Jay Soffian | 98ef23b | 2009-01-28 10:03:10 -0500 | [diff] [blame] | 42 | rebasing* (internal use for git-rebase)" |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 43 | |
freku045@student.liu.se | cf1fe88 | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 44 | . git-sh-setup |
Ævar Arnfjörð Bjarmason | b9a9726 | 2011-05-21 18:43:42 +0000 | [diff] [blame] | 45 | . git-sh-i18n |
Junio C Hamano | bb034f8 | 2008-03-04 00:25:04 -0800 | [diff] [blame] | 46 | prefix=$(git rev-parse --show-prefix) |
Shawn O. Pearce | f947413 | 2006-12-28 02:34:48 -0500 | [diff] [blame] | 47 | set_reflog_action am |
Shawn O. Pearce | 7eff28a | 2006-12-30 23:32:38 -0500 | [diff] [blame] | 48 | require_work_tree |
Jeff King | c149184 | 2008-03-01 01:22:55 -0500 | [diff] [blame] | 49 | cd_to_toplevel |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 50 | |
Stephan Beyer | 460abee | 2008-07-12 17:46:59 +0200 | [diff] [blame] | 51 | git var GIT_COMMITTER_IDENT >/dev/null || |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 52 | die "$(gettext "You need to set your committer info first")" |
Junio C Hamano | d64e6b0 | 2006-02-18 20:51:26 -0800 | [diff] [blame] | 53 | |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 54 | if git rev-parse --verify -q HEAD >/dev/null |
| 55 | then |
| 56 | HAS_HEAD=yes |
| 57 | else |
| 58 | HAS_HEAD= |
| 59 | fi |
| 60 | |
Ramkumar Ramachandra | d2c4631 | 2010-06-02 10:33:35 +0200 | [diff] [blame] | 61 | cmdline="git am" |
| 62 | if test '' != "$interactive" |
| 63 | then |
| 64 | cmdline="$cmdline -i" |
| 65 | fi |
| 66 | if test '' != "$threeway" |
| 67 | then |
| 68 | cmdline="$cmdline -3" |
| 69 | fi |
| 70 | |
Junio C Hamano | b47dfe9 | 2009-01-11 22:21:48 -0800 | [diff] [blame] | 71 | sq () { |
Christian Couder | 47c9739 | 2009-04-24 08:29:01 +0200 | [diff] [blame] | 72 | git rev-parse --sq-quote "$@" |
Junio C Hamano | b47dfe9 | 2009-01-11 22:21:48 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 75 | stop_here () { |
| 76 | echo "$1" >"$dotest/next" |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 77 | git rev-parse --verify -q HEAD >"$dotest/abort-safety" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 78 | exit 1 |
| 79 | } |
| 80 | |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 81 | safe_to_abort () { |
| 82 | if test -f "$dotest/dirtyindex" |
| 83 | then |
| 84 | return 1 |
| 85 | fi |
| 86 | |
| 87 | if ! test -s "$dotest/abort-safety" |
| 88 | then |
| 89 | return 0 |
| 90 | fi |
| 91 | |
| 92 | abort_safety=$(cat "$dotest/abort-safety") |
| 93 | if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety" |
| 94 | then |
| 95 | return 0 |
| 96 | fi |
Jiang Xin | 42e6504 | 2012-07-25 22:53:11 +0800 | [diff] [blame] | 97 | gettextln "You seem to have moved HEAD since the last 'am' failure. |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 98 | Not rewinding to ORIG_HEAD" >&2 |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 99 | return 1 |
| 100 | } |
| 101 | |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 102 | stop_here_user_resolve () { |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 103 | if [ -n "$resolvemsg" ]; then |
Jeff King | a23bfae | 2007-05-26 00:33:03 -0700 | [diff] [blame] | 104 | printf '%s\n' "$resolvemsg" |
Sean | cc12005 | 2006-05-13 23:34:08 -0400 | [diff] [blame] | 105 | stop_here $1 |
| 106 | fi |
Kevin Bracey | 8ceb6fb | 2013-06-26 23:06:41 +0300 | [diff] [blame] | 107 | eval_gettextln "When you have resolved this problem, run \"\$cmdline --continue\". |
Jiang Xin | c7108bf | 2012-07-25 22:53:08 +0800 | [diff] [blame] | 108 | If you prefer to skip this patch, run \"\$cmdline --skip\" instead. |
| 109 | To restore the original branch and stop patching, run \"\$cmdline --abort\"." |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 110 | |
| 111 | stop_here $1 |
| 112 | } |
| 113 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 114 | go_next () { |
| 115 | rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \ |
| 116 | "$dotest/patch" "$dotest/info" |
| 117 | echo "$next" >"$dotest/next" |
| 118 | this=$next |
| 119 | } |
| 120 | |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 121 | cannot_fallback () { |
| 122 | echo "$1" |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 123 | gettextln "Cannot fall back to three-way merge." |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 124 | exit 1 |
| 125 | } |
| 126 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 127 | fall_back_3way () { |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 128 | O_OBJECT=$(cd "$GIT_OBJECT_DIRECTORY" && pwd) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 129 | |
| 130 | rm -fr "$dotest"/patch-merge-* |
| 131 | mkdir "$dotest/patch-merge-tmp-dir" |
| 132 | |
| 133 | # First see if the patch records the index info that we can use. |
Junio C Hamano | 4056afb | 2012-02-22 21:55:06 -0800 | [diff] [blame] | 134 | cmd="git apply $git_apply_opt --build-fake-ancestor" && |
| 135 | cmd="$cmd "'"$dotest/patch-merge-tmp-index" "$dotest/patch"' && |
| 136 | eval "$cmd" && |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 137 | GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 138 | git write-tree >"$dotest/patch-merge-base+" || |
Ævar Arnfjörð Bjarmason | a424ca1 | 2011-05-21 18:43:48 +0000 | [diff] [blame] | 139 | cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")" |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 140 | |
Jiang Xin | 42e6504 | 2012-07-25 22:53:11 +0800 | [diff] [blame] | 141 | say "$(gettext "Using index info to reconstruct a base tree...")" |
Junio C Hamano | 4056afb | 2012-02-22 21:55:06 -0800 | [diff] [blame] | 142 | |
| 143 | cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"' |
Junio C Hamano | 5d86861 | 2012-03-28 09:55:21 -0700 | [diff] [blame] | 144 | |
| 145 | if test -z "$GIT_QUIET" |
| 146 | then |
| 147 | eval "$cmd git diff-index --cached --diff-filter=AM --name-status HEAD" |
| 148 | fi |
| 149 | |
Junio C Hamano | 4056afb | 2012-02-22 21:55:06 -0800 | [diff] [blame] | 150 | cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"' |
| 151 | if eval "$cmd" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 152 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 153 | mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base" |
| 154 | mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index" |
Junio C Hamano | fd7bcfb | 2006-08-12 16:16:47 -0700 | [diff] [blame] | 155 | else |
Ævar Arnfjörð Bjarmason | a424ca1 | 2011-05-21 18:43:48 +0000 | [diff] [blame] | 156 | cannot_fallback "$(gettext "Did you hand edit your patch? |
| 157 | It does not apply to blobs recorded in its index.")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 158 | fi |
| 159 | |
| 160 | test -f "$dotest/patch-merge-index" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 161 | 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] | 162 | orig_tree=$(cat "$dotest/patch-merge-base") && |
| 163 | rm -fr "$dotest"/patch-merge-* || exit 1 |
| 164 | |
Ævar Arnfjörð Bjarmason | 865207a | 2011-05-21 18:43:51 +0000 | [diff] [blame] | 165 | say "$(gettext "Falling back to patching base and 3-way merge...")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 166 | |
| 167 | # This is not so wrong. Depending on which base we picked, |
| 168 | # orig_tree may be wildly different from ours, but his_tree |
| 169 | # has the same set of wildly different changes in parts the |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 170 | # patch did not touch, so recursive ends up canceling them, |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 171 | # saying that we reverted all those changes. |
| 172 | |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 173 | eval GITHEAD_$his_tree='"$FIRSTLINE"' |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 174 | export GITHEAD_$his_tree |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 175 | if test -n "$GIT_QUIET" |
| 176 | then |
Junio C Hamano | 69ae92b | 2010-10-13 11:36:36 -0700 | [diff] [blame] | 177 | GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 178 | fi |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 179 | git-merge-recursive $orig_tree -- HEAD $his_tree || { |
Junio C Hamano | cb6020b | 2009-12-04 00:20:48 -0800 | [diff] [blame] | 180 | git rerere $allow_rerere_autoupdate |
Jiang Xin | 42e6504 | 2012-07-25 22:53:11 +0800 | [diff] [blame] | 181 | die "$(gettext "Failed to merge in the changes.")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 182 | } |
Shawn O. Pearce | 579c9bb | 2006-12-28 02:35:27 -0500 | [diff] [blame] | 183 | unset GITHEAD_$his_tree |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Giuseppe Bilotta | 0cd29a0 | 2009-05-27 11:25:19 +0200 | [diff] [blame] | 186 | clean_abort () { |
| 187 | test $# = 0 || echo >&2 "$@" |
| 188 | rm -fr "$dotest" |
| 189 | exit 1 |
| 190 | } |
| 191 | |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 192 | patch_format= |
| 193 | |
| 194 | check_patch_format () { |
| 195 | # early return if patch_format was set from the command line |
| 196 | if test -n "$patch_format" |
| 197 | then |
| 198 | return 0 |
| 199 | fi |
Giuseppe Bilotta | 15ced75 | 2009-05-27 23:20:12 +0200 | [diff] [blame] | 200 | |
| 201 | # we default to mbox format if input is from stdin and for |
| 202 | # directories |
| 203 | if test $# = 0 || test "x$1" = "x-" || test -d "$1" |
| 204 | then |
| 205 | patch_format=mbox |
| 206 | return 0 |
| 207 | fi |
| 208 | |
David Barr | 0e8341f | 2011-08-08 04:49:04 +0200 | [diff] [blame] | 209 | # otherwise, check the first few non-blank lines of the first |
| 210 | # patch to try to detect its format |
Giuseppe Bilotta | 15ced75 | 2009-05-27 23:20:12 +0200 | [diff] [blame] | 211 | { |
David Barr | 0e8341f | 2011-08-08 04:49:04 +0200 | [diff] [blame] | 212 | # Start from first line containing non-whitespace |
| 213 | l1= |
| 214 | while test -z "$l1" |
| 215 | do |
Jim Meyering | f0c5793 | 2012-02-25 18:34:26 +0100 | [diff] [blame] | 216 | read l1 || break |
David Barr | 0e8341f | 2011-08-08 04:49:04 +0200 | [diff] [blame] | 217 | done |
Giuseppe Bilotta | 15ced75 | 2009-05-27 23:20:12 +0200 | [diff] [blame] | 218 | read l2 |
| 219 | read l3 |
| 220 | case "$l1" in |
| 221 | "From "* | "From: "*) |
| 222 | patch_format=mbox |
| 223 | ;; |
| 224 | '# This series applies on GIT commit'*) |
| 225 | patch_format=stgit-series |
| 226 | ;; |
| 227 | "# HG changeset patch") |
| 228 | patch_format=hg |
| 229 | ;; |
| 230 | *) |
| 231 | # if the second line is empty and the third is |
| 232 | # a From, Author or Date entry, this is very |
| 233 | # likely an StGIT patch |
| 234 | case "$l2,$l3" in |
| 235 | ,"From: "* | ,"Author: "* | ,"Date: "*) |
| 236 | patch_format=stgit |
| 237 | ;; |
| 238 | *) |
| 239 | ;; |
| 240 | esac |
| 241 | ;; |
| 242 | esac |
Junio C Hamano | 0fcb2ca | 2009-08-06 20:08:12 -0500 | [diff] [blame] | 243 | if test -z "$patch_format" && |
| 244 | test -n "$l1" && |
| 245 | test -n "$l2" && |
| 246 | test -n "$l3" |
| 247 | then |
| 248 | # This begins with three non-empty lines. Is this a |
| 249 | # piece of e-mail a-la RFC2822? Grab all the headers, |
| 250 | # discarding the indented remainder of folded lines, |
| 251 | # and see if it looks like that they all begin with the |
| 252 | # header field names... |
Stephen Boyd | e3f67d3 | 2010-01-25 16:33:59 -0800 | [diff] [blame] | 253 | tr -d '\015' <"$1" | |
| 254 | sed -n -e '/^$/q' -e '/^[ ]/d' -e p | |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 255 | sane_egrep -v '^[!-9;-~]+:' >/dev/null || |
Junio C Hamano | 0fcb2ca | 2009-08-06 20:08:12 -0500 | [diff] [blame] | 256 | patch_format=mbox |
| 257 | fi |
Giuseppe Bilotta | 0cd29a0 | 2009-05-27 11:25:19 +0200 | [diff] [blame] | 258 | } < "$1" || clean_abort |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | split_patches () { |
| 262 | case "$patch_format" in |
| 263 | mbox) |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 264 | if test t = "$keepcr" |
Stefan-W. Hahn | ad2c928 | 2010-02-27 15:20:26 +0100 | [diff] [blame] | 265 | then |
| 266 | keep_cr=--keep-cr |
| 267 | else |
| 268 | keep_cr= |
| 269 | fi |
Junio C Hamano | c2ca1d7 | 2009-08-04 22:31:59 -0500 | [diff] [blame] | 270 | git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" || |
Giuseppe Bilotta | 0cd29a0 | 2009-05-27 11:25:19 +0200 | [diff] [blame] | 271 | clean_abort |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 272 | ;; |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 273 | stgit-series) |
| 274 | if test $# -ne 1 |
| 275 | then |
Ævar Arnfjörð Bjarmason | d62a146 | 2011-05-21 18:43:49 +0000 | [diff] [blame] | 276 | clean_abort "$(gettext "Only one StGIT patch series can be applied at once")" |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 277 | fi |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 278 | series_dir=$(dirname "$1") |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 279 | series_file="$1" |
| 280 | shift |
| 281 | { |
| 282 | set x |
| 283 | while read filename |
| 284 | do |
| 285 | set "$@" "$series_dir/$filename" |
| 286 | done |
| 287 | # remove the safety x |
| 288 | shift |
| 289 | # remove the arg coming from the first-line comment |
| 290 | shift |
Giuseppe Bilotta | 0cd29a0 | 2009-05-27 11:25:19 +0200 | [diff] [blame] | 291 | } < "$series_file" || clean_abort |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 292 | # set the patch format appropriately |
| 293 | patch_format=stgit |
| 294 | # now handle the actual StGIT patches |
| 295 | split_patches "$@" |
| 296 | ;; |
| 297 | stgit) |
| 298 | this=0 |
| 299 | for stgit in "$@" |
| 300 | do |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 301 | this=$(expr "$this" + 1) |
| 302 | msgnum=$(printf "%0${prec}d" $this) |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 303 | # Perl version of StGIT parse_patch. The first nonemptyline |
| 304 | # not starting with Author, From or Date is the |
| 305 | # subject, and the body starts with the next nonempty |
| 306 | # line not starting with Author, From or Date |
Jeff King | fcb06a8 | 2013-10-28 21:19:59 -0400 | [diff] [blame] | 307 | @@PERL@@ -ne 'BEGIN { $subject = 0 } |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 308 | if ($subject > 1) { print ; } |
| 309 | elsif (/^\s+$/) { next ; } |
Giuseppe Bilotta | 45d51dc | 2011-08-29 18:44:07 +0200 | [diff] [blame] | 310 | elsif (/^Author:/) { s/Author/From/ ; print ;} |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 311 | elsif (/^(From|Date)/) { print ; } |
| 312 | elsif ($subject) { |
| 313 | $subject = 2 ; |
| 314 | print "\n" ; |
| 315 | print ; |
| 316 | } else { |
| 317 | print "Subject: ", $_ ; |
| 318 | $subject = 1; |
| 319 | } |
Giuseppe Bilotta | 0cd29a0 | 2009-05-27 11:25:19 +0200 | [diff] [blame] | 320 | ' < "$stgit" > "$dotest/$msgnum" || clean_abort |
Giuseppe Bilotta | c574e68 | 2009-05-27 11:25:18 +0200 | [diff] [blame] | 321 | done |
| 322 | echo "$this" > "$dotest/last" |
| 323 | this= |
| 324 | msgnum= |
| 325 | ;; |
Giuseppe Bilotta | 0cfd112 | 2011-08-29 18:44:06 +0200 | [diff] [blame] | 326 | hg) |
| 327 | this=0 |
| 328 | for hg in "$@" |
| 329 | do |
| 330 | this=$(( $this + 1 )) |
| 331 | msgnum=$(printf "%0${prec}d" $this) |
| 332 | # hg stores changeset metadata in #-commented lines preceding |
| 333 | # the commit message and diff(s). The only metadata we care about |
| 334 | # are the User and Date (Node ID and Parent are hashes which are |
| 335 | # only relevant to the hg repository and thus not useful to us) |
| 336 | # Since we cannot guarantee that the commit message is in |
| 337 | # git-friendly format, we put no Subject: line and just consume |
| 338 | # all of the message as the body |
Jeff King | fcb06a8 | 2013-10-28 21:19:59 -0400 | [diff] [blame] | 339 | LANG=C LC_ALL=C @@PERL@@ -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 } |
Giuseppe Bilotta | 0cfd112 | 2011-08-29 18:44:06 +0200 | [diff] [blame] | 340 | if ($subject) { print ; } |
| 341 | elsif (/^\# User /) { s/\# User/From:/ ; print ; } |
| 342 | elsif (/^\# Date /) { |
| 343 | my ($hashsign, $str, $time, $tz) = split ; |
| 344 | $tz = sprintf "%+05d", (0-$tz)/36; |
| 345 | print "Date: " . |
| 346 | strftime("%a, %d %b %Y %H:%M:%S ", |
| 347 | localtime($time)) |
| 348 | . "$tz\n"; |
| 349 | } elsif (/^\# /) { next ; } |
| 350 | else { |
| 351 | print "\n", $_ ; |
| 352 | $subject = 1; |
| 353 | } |
| 354 | ' <"$hg" >"$dotest/$msgnum" || clean_abort |
| 355 | done |
| 356 | echo "$this" >"$dotest/last" |
| 357 | this= |
| 358 | msgnum= |
| 359 | ;; |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 360 | *) |
Giuseppe Bilotta | dff4b0e | 2011-08-29 17:22:06 +0200 | [diff] [blame] | 361 | if test -n "$patch_format" |
| 362 | then |
Ævar Arnfjörð Bjarmason | d62a146 | 2011-05-21 18:43:49 +0000 | [diff] [blame] | 363 | clean_abort "$(eval_gettext "Patch format \$patch_format is not supported.")" |
Nicolas Sebrecht | 46caf50 | 2009-08-06 20:08:13 -0500 | [diff] [blame] | 364 | else |
Ævar Arnfjörð Bjarmason | d62a146 | 2011-05-21 18:43:49 +0000 | [diff] [blame] | 365 | clean_abort "$(gettext "Patch format detection failed.")" |
Nicolas Sebrecht | 46caf50 | 2009-08-06 20:08:13 -0500 | [diff] [blame] | 366 | fi |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 367 | ;; |
| 368 | esac |
| 369 | } |
| 370 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 371 | prec=4 |
Johannes Schindelin | 51ef1da | 2008-07-21 12:51:02 +0200 | [diff] [blame] | 372 | dotest="$GIT_DIR/rebase-apply" |
Stefan-W. Hahn | ad2c928 | 2010-02-27 15:20:26 +0100 | [diff] [blame] | 373 | sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort= |
Lukas Sandström | d25e515 | 2009-11-20 17:12:47 +0100 | [diff] [blame] | 374 | resolvemsg= resume= scissors= no_inbody_headers= |
Michael S. Tsirkin | 67dad68 | 2007-02-08 15:57:08 +0200 | [diff] [blame] | 375 | git_apply_opt= |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 376 | committer_date_is_author_date= |
Nanako Shiraishi | a79ec62 | 2009-01-24 10:18:02 +0900 | [diff] [blame] | 377 | ignore_date= |
Junio C Hamano | cb6020b | 2009-12-04 00:20:48 -0800 | [diff] [blame] | 378 | allow_rerere_autoupdate= |
Nicolas Vigier | 3b4e395f | 2014-02-01 02:18:01 +0000 | [diff] [blame] | 379 | gpg_sign_opt= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 380 | |
Stefan-W. Hahn | e80d4cb | 2010-02-27 15:20:27 +0100 | [diff] [blame] | 381 | if test "$(git config --bool --get am.keepcr)" = true |
| 382 | then |
| 383 | keepcr=t |
| 384 | fi |
| 385 | |
David Kastrup | 822f7c7 | 2007-09-23 22:42:08 +0200 | [diff] [blame] | 386 | while test $# != 0 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 387 | do |
| 388 | case "$1" in |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 389 | -i|--interactive) |
| 390 | interactive=t ;; |
| 391 | -b|--binary) |
Jiang Xin | 42e6504 | 2012-07-25 22:53:11 +0800 | [diff] [blame] | 392 | gettextln >&2 "The -b/--binary option has been a no-op for long time, and |
| 393 | it will be removed. Please do not use it anymore." |
Thomas Rast | 4eeb1de | 2012-03-12 22:47:19 +0100 | [diff] [blame] | 394 | ;; |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 395 | -3|--3way) |
| 396 | threeway=t ;; |
Johannes Sixt | dfdd7e6 | 2007-11-06 21:33:58 +0100 | [diff] [blame] | 397 | -s|--signoff) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 398 | sign=t ;; |
| 399 | -u|--utf8) |
| 400 | utf8=t ;; # this is now default |
| 401 | --no-utf8) |
| 402 | utf8= ;; |
| 403 | -k|--keep) |
| 404 | keep=t ;; |
Thomas Rast | f7e5ea1 | 2012-01-16 11:53:00 +0100 | [diff] [blame] | 405 | --keep-non-patch) |
| 406 | keep=b ;; |
Junio C Hamano | 017678b | 2009-08-26 21:36:05 -0700 | [diff] [blame] | 407 | -c|--scissors) |
| 408 | scissors=t ;; |
| 409 | --no-scissors) |
| 410 | scissors=f ;; |
Jeff King | c8089af | 2010-02-11 17:27:14 -0500 | [diff] [blame] | 411 | -r|--resolved|--continue) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 412 | resolved=t ;; |
| 413 | --skip) |
| 414 | skip=t ;; |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 415 | --abort) |
| 416 | abort=t ;; |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 417 | --rebasing) |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 418 | rebasing=t threeway=t ;; |
Nicolas Vigier | 8833662 | 2014-02-01 02:18:00 +0000 | [diff] [blame] | 419 | --resolvemsg=*) |
| 420 | resolvemsg="${1#--resolvemsg=}" ;; |
| 421 | --whitespace=*|--directory=*|--exclude=*|--include=*) |
| 422 | git_apply_opt="$git_apply_opt $(sq "$1")" ;; |
| 423 | -C*|-p*) |
| 424 | git_apply_opt="$git_apply_opt $(sq "$1")" ;; |
| 425 | --patch-format=*) |
| 426 | patch_format="${1#--patch-format=}" ;; |
Giuseppe Bilotta | 86c91f9 | 2009-08-04 13:16:49 +0200 | [diff] [blame] | 427 | --reject|--ignore-whitespace|--ignore-space-change) |
martin f. krafft | b80da42 | 2009-01-23 11:31:21 +1100 | [diff] [blame] | 428 | git_apply_opt="$git_apply_opt $1" ;; |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 429 | --committer-date-is-author-date) |
| 430 | committer_date_is_author_date=t ;; |
Nanako Shiraishi | a79ec62 | 2009-01-24 10:18:02 +0900 | [diff] [blame] | 431 | --ignore-date) |
| 432 | ignore_date=t ;; |
Junio C Hamano | cb6020b | 2009-12-04 00:20:48 -0800 | [diff] [blame] | 433 | --rerere-autoupdate|--no-rerere-autoupdate) |
| 434 | allow_rerere_autoupdate="$1" ;; |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 435 | -q|--quiet) |
| 436 | GIT_QUIET=t ;; |
Stefan-W. Hahn | ad2c928 | 2010-02-27 15:20:26 +0100 | [diff] [blame] | 437 | --keep-cr) |
| 438 | keepcr=t ;; |
Stefan-W. Hahn | e80d4cb | 2010-02-27 15:20:27 +0100 | [diff] [blame] | 439 | --no-keep-cr) |
| 440 | keepcr=f ;; |
Nicolas Vigier | 3b4e395f | 2014-02-01 02:18:01 +0000 | [diff] [blame] | 441 | --gpg-sign) |
| 442 | gpg_sign_opt=-S ;; |
| 443 | --gpg-sign=*) |
| 444 | gpg_sign_opt="-S${1#--gpg-sign=}" ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 445 | --) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 446 | shift; break ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 447 | *) |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 448 | usage ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 449 | esac |
Pierre Habouzit | 78443d9 | 2007-11-04 11:30:57 +0100 | [diff] [blame] | 450 | shift |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 451 | done |
| 452 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 453 | # If the dotest directory exists, but we have finished applying all the |
| 454 | # patches in them, clear it out. |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 455 | if test -d "$dotest" && |
Ramkumar Ramachandra | c30754f | 2013-05-12 17:26:35 +0530 | [diff] [blame] | 456 | test -f "$dotest/last" && |
| 457 | test -f "$dotest/next" && |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 458 | last=$(cat "$dotest/last") && |
| 459 | next=$(cat "$dotest/next") && |
| 460 | test $# != 0 && |
| 461 | test "$next" -gt "$last" |
| 462 | then |
| 463 | rm -fr "$dotest" |
| 464 | fi |
| 465 | |
Ramkumar Ramachandra | c30754f | 2013-05-12 17:26:35 +0530 | [diff] [blame] | 466 | if test -d "$dotest" && test -f "$dotest/last" && test -f "$dotest/next" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 467 | then |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 468 | case "$#,$skip$resolved$abort" in |
Junio C Hamano | c95b138 | 2006-09-15 23:19:02 -0700 | [diff] [blame] | 469 | 0,*t*) |
| 470 | # Explicit resume command and we do not have file, so |
| 471 | # we are happy. |
| 472 | : ;; |
| 473 | 0,) |
| 474 | # No file input but without resume parameters; catch |
| 475 | # user error to feed us a patch from standard input |
Junio C Hamano | e72c740 | 2008-03-04 00:25:05 -0800 | [diff] [blame] | 476 | # when there is already $dotest. This is somewhat |
Junio C Hamano | c95b138 | 2006-09-15 23:19:02 -0700 | [diff] [blame] | 477 | # unreliable -- stdin could be /dev/null for example |
| 478 | # and the caller did not intend to feed us a patch but |
| 479 | # wanted to continue unattended. |
Jay Soffian | 98ef23b | 2009-01-28 10:03:10 -0500 | [diff] [blame] | 480 | test -t 0 |
Junio C Hamano | c95b138 | 2006-09-15 23:19:02 -0700 | [diff] [blame] | 481 | ;; |
| 482 | *) |
| 483 | false |
| 484 | ;; |
| 485 | esac || |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 486 | die "$(eval_gettext "previous rebase directory \$dotest still exists but mbox given.")" |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 487 | resume=yes |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 488 | |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 489 | case "$skip,$abort" in |
Junio C Hamano | 2d56a13 | 2009-02-26 11:24:29 -0800 | [diff] [blame] | 490 | t,t) |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 491 | die "$(gettext "Please make up your mind. --skip or --abort?")" |
Junio C Hamano | 2d56a13 | 2009-02-26 11:24:29 -0800 | [diff] [blame] | 492 | ;; |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 493 | t,) |
| 494 | git rerere clear |
| 495 | git read-tree --reset -u HEAD HEAD |
| 496 | orig_head=$(cat "$GIT_DIR/ORIG_HEAD") |
| 497 | git reset HEAD |
| 498 | git update-ref ORIG_HEAD $orig_head |
| 499 | ;; |
| 500 | ,t) |
Junio C Hamano | 2d56a13 | 2009-02-26 11:24:29 -0800 | [diff] [blame] | 501 | if test -f "$dotest/rebasing" |
| 502 | then |
| 503 | exec git rebase --abort |
| 504 | fi |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 505 | git rerere clear |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 506 | if safe_to_abort |
| 507 | then |
Michael J Gruber | c767184 | 2009-02-26 10:52:53 +0100 | [diff] [blame] | 508 | git read-tree --reset -u HEAD ORIG_HEAD |
| 509 | git reset ORIG_HEAD |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 510 | fi |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 511 | rm -fr "$dotest" |
| 512 | exit ;; |
| 513 | esac |
Michael J Gruber | c767184 | 2009-02-26 10:52:53 +0100 | [diff] [blame] | 514 | rm -f "$dotest/dirtyindex" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 515 | else |
Ramkumar Ramachandra | b141f3c | 2013-06-15 18:13:11 +0530 | [diff] [blame] | 516 | # Possible stray $dotest directory in the independent-run |
| 517 | # case; in the --rebasing case, it is upto the caller |
| 518 | # (git-rebase--am) to take care of stray directories. |
| 519 | if test -d "$dotest" && test -z "$rebasing" |
| 520 | then |
| 521 | case "$skip,$resolved,$abort" in |
| 522 | ,,t) |
| 523 | rm -fr "$dotest" |
| 524 | exit 0 |
| 525 | ;; |
| 526 | *) |
| 527 | die "$(eval_gettext "Stray \$dotest directory found. |
| 528 | Use \"git am --abort\" to remove it.")" |
| 529 | ;; |
| 530 | esac |
| 531 | fi |
| 532 | |
Justin Lebar | 0168990 | 2014-03-31 15:11:46 -0700 | [diff] [blame] | 533 | # Make sure we are not given --skip, --continue, or --abort |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 534 | test "$skip$resolved$abort" = "" || |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 535 | die "$(gettext "Resolve operation not in progress, we are not resuming.")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 536 | |
| 537 | # Start afresh. |
| 538 | mkdir -p "$dotest" || exit |
| 539 | |
Junio C Hamano | bb034f8 | 2008-03-04 00:25:04 -0800 | [diff] [blame] | 540 | if test -n "$prefix" && test $# != 0 |
| 541 | then |
| 542 | first=t |
| 543 | for arg |
| 544 | do |
| 545 | test -n "$first" && { |
| 546 | set x |
| 547 | first= |
| 548 | } |
Pat Thoyts | 5e9677c | 2010-09-30 14:24:07 +0100 | [diff] [blame] | 549 | if is_absolute_path "$arg" |
| 550 | then |
| 551 | set "$@" "$arg" |
| 552 | else |
| 553 | set "$@" "$prefix$arg" |
| 554 | fi |
Junio C Hamano | bb034f8 | 2008-03-04 00:25:04 -0800 | [diff] [blame] | 555 | done |
| 556 | shift |
| 557 | fi |
Giuseppe Bilotta | a5a6755 | 2009-05-27 11:25:16 +0200 | [diff] [blame] | 558 | |
| 559 | check_patch_format "$@" |
| 560 | |
| 561 | split_patches "$@" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 562 | |
Junio C Hamano | 017678b | 2009-08-26 21:36:05 -0700 | [diff] [blame] | 563 | # -i can and must be given when resuming; everything |
| 564 | # else is kept |
Junio C Hamano | 9b9f5a2 | 2008-12-05 11:19:43 -0800 | [diff] [blame] | 565 | echo " $git_apply_opt" >"$dotest/apply-opt" |
Junio C Hamano | 22db240 | 2008-12-04 15:38:27 -0800 | [diff] [blame] | 566 | echo "$threeway" >"$dotest/threeway" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 567 | echo "$sign" >"$dotest/sign" |
| 568 | echo "$utf8" >"$dotest/utf8" |
| 569 | echo "$keep" >"$dotest/keep" |
Junio C Hamano | 017678b | 2009-08-26 21:36:05 -0700 | [diff] [blame] | 570 | echo "$scissors" >"$dotest/scissors" |
Lukas Sandström | d25e515 | 2009-11-20 17:12:47 +0100 | [diff] [blame] | 571 | echo "$no_inbody_headers" >"$dotest/no_inbody_headers" |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 572 | echo "$GIT_QUIET" >"$dotest/quiet" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 573 | echo 1 >"$dotest/next" |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 574 | if test -n "$rebasing" |
| 575 | then |
| 576 | : >"$dotest/rebasing" |
| 577 | else |
| 578 | : >"$dotest/applying" |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 579 | if test -n "$HAS_HEAD" |
| 580 | then |
| 581 | git update-ref ORIG_HEAD HEAD |
| 582 | else |
| 583 | git update-ref -d ORIG_HEAD >/dev/null 2>&1 |
| 584 | fi |
Junio C Hamano | 3041c32 | 2008-03-04 00:25:06 -0800 | [diff] [blame] | 585 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 586 | fi |
| 587 | |
Jeff King | 2a6f08a | 2011-08-15 17:13:07 -0700 | [diff] [blame] | 588 | git update-index -q --refresh |
| 589 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 590 | case "$resolved" in |
| 591 | '') |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 592 | case "$HAS_HEAD" in |
| 593 | '') |
| 594 | files=$(git ls-files) ;; |
| 595 | ?*) |
| 596 | files=$(git diff-index --cached --name-only HEAD --) ;; |
| 597 | esac || exit |
Michael J Gruber | c767184 | 2009-02-26 10:52:53 +0100 | [diff] [blame] | 598 | if test "$files" |
| 599 | then |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 600 | test -n "$HAS_HEAD" && : >"$dotest/dirtyindex" |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 601 | die "$(eval_gettext "Dirty index: cannot apply patches (dirty: \$files)")" |
Michael J Gruber | c767184 | 2009-02-26 10:52:53 +0100 | [diff] [blame] | 602 | fi |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 603 | esac |
| 604 | |
Thomas Rast | f7e5ea1 | 2012-01-16 11:53:00 +0100 | [diff] [blame] | 605 | # Now, decide what command line options we will give to the git |
| 606 | # commands we invoke, based on the result of parsing command line |
| 607 | # options and previous invocation state stored in $dotest/ files. |
| 608 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 609 | if test "$(cat "$dotest/utf8")" = t |
| 610 | then |
| 611 | utf8=-u |
Junio C Hamano | bb1091a | 2007-01-09 21:31:36 -0800 | [diff] [blame] | 612 | else |
| 613 | utf8=-n |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 614 | fi |
Thomas Rast | f7e5ea1 | 2012-01-16 11:53:00 +0100 | [diff] [blame] | 615 | keep=$(cat "$dotest/keep") |
| 616 | case "$keep" in |
| 617 | t) |
| 618 | keep=-k ;; |
| 619 | b) |
| 620 | keep=-b ;; |
| 621 | *) |
| 622 | keep= ;; |
| 623 | esac |
Junio C Hamano | 017678b | 2009-08-26 21:36:05 -0700 | [diff] [blame] | 624 | case "$(cat "$dotest/scissors")" in |
| 625 | t) |
| 626 | scissors=--scissors ;; |
| 627 | f) |
| 628 | scissors=--no-scissors ;; |
| 629 | esac |
Lukas Sandström | d25e515 | 2009-11-20 17:12:47 +0100 | [diff] [blame] | 630 | if test "$(cat "$dotest/no_inbody_headers")" = t |
| 631 | then |
| 632 | no_inbody_headers=--no-inbody-headers |
| 633 | else |
| 634 | no_inbody_headers= |
| 635 | fi |
Stephen Boyd | 0e987a1 | 2009-06-16 15:33:01 -0700 | [diff] [blame] | 636 | if test "$(cat "$dotest/quiet")" = t |
| 637 | then |
| 638 | GIT_QUIET=t |
| 639 | fi |
Junio C Hamano | 22db240 | 2008-12-04 15:38:27 -0800 | [diff] [blame] | 640 | if test "$(cat "$dotest/threeway")" = t |
| 641 | then |
| 642 | threeway=t |
| 643 | fi |
Junio C Hamano | 9b9f5a2 | 2008-12-05 11:19:43 -0800 | [diff] [blame] | 644 | git_apply_opt=$(cat "$dotest/apply-opt") |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 645 | if test "$(cat "$dotest/sign")" = t |
| 646 | then |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 647 | SIGNOFF=$(git var GIT_COMMITTER_IDENT | sed -e ' |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 648 | s/>.*/>/ |
| 649 | s/^/Signed-off-by: /' |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 650 | ) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 651 | else |
| 652 | SIGNOFF= |
| 653 | fi |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 654 | |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 655 | last=$(cat "$dotest/last") |
| 656 | this=$(cat "$dotest/next") |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 657 | if test "$skip" = t |
| 658 | then |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 659 | this=$(expr "$this" + 1) |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 660 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 661 | fi |
| 662 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 663 | while test "$this" -le "$last" |
| 664 | do |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 665 | msgnum=$(printf "%0${prec}d" $this) |
| 666 | next=$(expr "$this" + 1) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 667 | test -f "$dotest/$msgnum" || { |
Jan Harkes | 6922471 | 2005-12-17 01:01:06 -0500 | [diff] [blame] | 668 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 669 | go_next |
| 670 | continue |
| 671 | } |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 672 | |
| 673 | # If we are not resuming, parse and extract the patch information |
| 674 | # into separate files: |
| 675 | # - info records the authorship and title |
| 676 | # - msg is the rest of commit log message |
| 677 | # - patch is the patch body. |
| 678 | # |
| 679 | # When we are resuming, these files are either already prepared |
Kevin Bracey | 8ceb6fb | 2013-06-26 23:06:41 +0300 | [diff] [blame] | 680 | # by the user, or the user can tell us to do so by --continue flag. |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 681 | case "$resume" in |
| 682 | '') |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 683 | if test -f "$dotest/rebasing" |
| 684 | then |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 685 | commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \ |
| 686 | -e q "$dotest/$msgnum") && |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 687 | test "$(git cat-file -t "$commit")" = commit || |
| 688 | stop_here $this |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 689 | git cat-file commit "$commit" | |
| 690 | sed -e '1,/^$/d' >"$dotest/msg-clean" |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 691 | echo "$commit" >"$dotest/original-commit" |
| 692 | get_author_ident_from_commit "$commit" >"$dotest/author-script" |
Junio C Hamano | 4ae6d46 | 2013-01-31 19:26:21 -0800 | [diff] [blame] | 693 | git diff-tree --root --binary --full-index "$commit" >"$dotest/patch" |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 694 | else |
Martin von Zweigbergk | 0fbb95d | 2012-06-26 07:51:57 -0700 | [diff] [blame] | 695 | git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \ |
| 696 | <"$dotest/$msgnum" >"$dotest/info" || |
| 697 | stop_here $this |
| 698 | |
| 699 | # skip pine's internal folder data |
| 700 | sane_grep '^Author: Mail System Internal Data$' \ |
| 701 | <"$dotest"/info >/dev/null && |
| 702 | go_next && continue |
| 703 | |
| 704 | test -s "$dotest/patch" || { |
| 705 | eval_gettextln "Patch is empty. Was it split wrong? |
| 706 | If you would prefer to skip this patch, instead run \"\$cmdline --skip\". |
| 707 | To restore the original branch and stop patching run \"\$cmdline --abort\"." |
| 708 | stop_here $this |
| 709 | } |
| 710 | rm -f "$dotest/original-commit" "$dotest/author-script" |
Junio C Hamano | c970a6f | 2009-11-27 15:06:37 -0800 | [diff] [blame] | 711 | { |
| 712 | sed -n '/^Subject/ s/Subject: //p' "$dotest/info" |
| 713 | echo |
| 714 | cat "$dotest/msg" |
| 715 | } | |
| 716 | git stripspace > "$dotest/msg-clean" |
Junio C Hamano | 5e835ca | 2008-04-16 12:50:48 -0700 | [diff] [blame] | 717 | fi |
Junio C Hamano | 271440e | 2005-10-25 23:35:37 -0700 | [diff] [blame] | 718 | ;; |
| 719 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 720 | |
Jay Soffian | 43c2325 | 2010-06-16 03:12:40 -0400 | [diff] [blame] | 721 | if test -f "$dotest/author-script" |
| 722 | then |
| 723 | eval $(cat "$dotest/author-script") |
| 724 | else |
| 725 | GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")" |
| 726 | GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")" |
| 727 | GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")" |
| 728 | fi |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 729 | |
Junio C Hamano | 3b78959 | 2007-12-05 13:16:35 -0800 | [diff] [blame] | 730 | if test -z "$GIT_AUTHOR_EMAIL" |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 731 | then |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 732 | gettextln "Patch does not have a valid e-mail address." |
Junio C Hamano | e0e3ba2 | 2005-12-14 16:31:06 -0800 | [diff] [blame] | 733 | stop_here $this |
| 734 | fi |
| 735 | |
Junio C Hamano | 2c67419 | 2005-10-20 22:31:56 -0700 | [diff] [blame] | 736 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 737 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 738 | case "$resume" in |
| 739 | '') |
| 740 | if test '' != "$SIGNOFF" |
| 741 | then |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 742 | LAST_SIGNED_OFF_BY=$( |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 743 | sed -ne '/^Signed-off-by: /p' \ |
| 744 | "$dotest/msg-clean" | |
Jeff King | b4ce54f | 2008-03-12 17:34:34 -0400 | [diff] [blame] | 745 | sed -ne '$p' |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 746 | ) |
| 747 | ADD_SIGNOFF=$( |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 748 | test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 749 | test '' = "$LAST_SIGNED_OFF_BY" && echo |
| 750 | echo "$SIGNOFF" |
Elia Pinto | 75ee3d7 | 2014-03-25 10:22:22 -0700 | [diff] [blame] | 751 | }) |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 752 | else |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 753 | ADD_SIGNOFF= |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 754 | fi |
| 755 | { |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 756 | if test -s "$dotest/msg-clean" |
| 757 | then |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 758 | cat "$dotest/msg-clean" |
| 759 | fi |
| 760 | if test '' != "$ADD_SIGNOFF" |
| 761 | then |
| 762 | echo "$ADD_SIGNOFF" |
| 763 | fi |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 764 | } >"$dotest/final-commit" |
| 765 | ;; |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 766 | *) |
Junio C Hamano | 6d28644 | 2006-02-23 22:14:47 -0800 | [diff] [blame] | 767 | case "$resolved$interactive" in |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 768 | tt) |
| 769 | # This is used only for interactive view option. |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 770 | git diff-index -p --cached HEAD -- >"$dotest/patch" |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 771 | ;; |
| 772 | esac |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 773 | esac |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 774 | |
Junio C Hamano | 4bfb6b6 | 2005-11-08 00:41:37 -0800 | [diff] [blame] | 775 | resume= |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 776 | if test "$interactive" = t |
| 777 | then |
Junio C Hamano | a145110 | 2005-10-12 18:31:41 -0700 | [diff] [blame] | 778 | test -t 0 || |
Ævar Arnfjörð Bjarmason | 7908725 | 2011-05-21 18:43:47 +0000 | [diff] [blame] | 779 | die "$(gettext "cannot be interactive without stdin connected to a terminal.")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 780 | action=again |
| 781 | while test "$action" = again |
| 782 | do |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 783 | gettextln "Commit Body is:" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 784 | echo "--------------------------" |
| 785 | cat "$dotest/final-commit" |
| 786 | echo "--------------------------" |
Ævar Arnfjörð Bjarmason | 7a74d04 | 2011-05-21 18:43:50 +0000 | [diff] [blame] | 787 | # TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a] |
| 788 | # in your translation. The program will only accept English |
| 789 | # input at this point. |
| 790 | gettext "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] | 791 | read reply |
| 792 | case "$reply" in |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 793 | [yY]*) action=yes ;; |
| 794 | [aA]*) action=yes interactive= ;; |
| 795 | [nN]*) action=skip ;; |
Adam Roben | ef0c2ab | 2007-07-19 22:09:35 -0700 | [diff] [blame] | 796 | [eE]*) git_editor "$dotest/final-commit" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 797 | action=again ;; |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 798 | [vV]*) action=again |
Jonathan Nieder | f6dff11 | 2010-02-14 23:04:13 -0600 | [diff] [blame] | 799 | git_pager "$dotest/patch" ;; |
Junio C Hamano | f89ad67 | 2005-10-25 23:43:59 -0700 | [diff] [blame] | 800 | *) action=again ;; |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 801 | esac |
| 802 | done |
| 803 | else |
| 804 | action=yes |
| 805 | fi |
Ramkumar Ramachandra | 92f65e6 | 2010-06-02 10:33:37 +0200 | [diff] [blame] | 806 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 807 | if test $action = skip |
| 808 | then |
| 809 | go_next |
| 810 | continue |
| 811 | fi |
| 812 | |
| 813 | if test -x "$GIT_DIR"/hooks/applypatch-msg |
| 814 | then |
| 815 | "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" || |
| 816 | stop_here $this |
| 817 | fi |
| 818 | |
Simon Ruderich | b34a912 | 2013-03-21 03:40:17 +0100 | [diff] [blame] | 819 | if test -f "$dotest/final-commit" |
| 820 | then |
| 821 | FIRSTLINE=$(sed 1q "$dotest/final-commit") |
| 822 | else |
| 823 | FIRSTLINE="" |
| 824 | fi |
| 825 | |
Ævar Arnfjörð Bjarmason | dff1a98 | 2011-05-21 18:43:52 +0000 | [diff] [blame] | 826 | say "$(eval_gettext "Applying: \$FIRSTLINE")" |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 827 | |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 828 | case "$resolved" in |
| 829 | '') |
Stephen Boyd | 3ddd170 | 2009-06-16 15:32:58 -0700 | [diff] [blame] | 830 | # When we are allowed to fall back to 3-way later, don't give |
| 831 | # false errors during the initial attempt. |
| 832 | squelch= |
| 833 | if test "$threeway" = t |
| 834 | then |
| 835 | squelch='>/dev/null 2>&1 ' |
| 836 | fi |
| 837 | eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"' |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 838 | apply_status=$? |
| 839 | ;; |
| 840 | t) |
| 841 | # Resolved means the user did all the hard work, and |
| 842 | # we do not have to do any patch application. Just |
| 843 | # trust what the user has in the index file and the |
| 844 | # working tree. |
| 845 | resolved= |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 846 | git diff-index --quiet --cached HEAD -- && { |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 847 | gettextln "No changes - did you forget to use 'git add'? |
Ævar Arnfjörð Bjarmason | bd8643a | 2011-05-21 18:43:44 +0000 | [diff] [blame] | 848 | If there is nothing left to stage, chances are that something else |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 849 | already introduced the same changes; you might want to skip this patch." |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 850 | stop_here_user_resolve $this |
Alex Riesen | 06aff47 | 2007-03-25 01:56:13 +0100 | [diff] [blame] | 851 | } |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 852 | unmerged=$(git ls-files -u) |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 853 | if test -n "$unmerged" |
| 854 | then |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 855 | gettextln "You still have unmerged paths in your index |
| 856 | did you forget to use 'git add'?" |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 857 | stop_here_user_resolve $this |
Junio C Hamano | c1d1128 | 2006-04-28 02:32:44 -0700 | [diff] [blame] | 858 | fi |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 859 | apply_status=0 |
Johannes Schindelin | b4372ef | 2007-07-06 13:05:59 +0100 | [diff] [blame] | 860 | git rerere |
Junio C Hamano | 0c15cc9 | 2005-11-16 00:19:32 -0800 | [diff] [blame] | 861 | ;; |
| 862 | esac |
| 863 | |
Junio C Hamano | 0ba17dd | 2010-04-09 16:58:28 -0700 | [diff] [blame] | 864 | if test $apply_status != 0 && test "$threeway" = t |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 865 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 866 | if (fall_back_3way) |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 867 | then |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 868 | # Applying the patch to an earlier tree and merging the |
| 869 | # result may have produced the same tree as ours. |
Junio C Hamano | 38762c4 | 2007-11-28 16:15:04 -0800 | [diff] [blame] | 870 | git diff-index --quiet --cached HEAD -- && { |
Ævar Arnfjörð Bjarmason | dff1a98 | 2011-05-21 18:43:52 +0000 | [diff] [blame] | 871 | say "$(gettext "No changes -- Patch already applied.")" |
Alex Riesen | 06aff47 | 2007-03-25 01:56:13 +0100 | [diff] [blame] | 872 | go_next |
| 873 | continue |
| 874 | } |
Junio C Hamano | 7331903 | 2005-10-13 11:46:43 -0700 | [diff] [blame] | 875 | # clear apply_status -- we have successfully merged. |
| 876 | apply_status=0 |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 877 | fi |
| 878 | fi |
| 879 | if test $apply_status != 0 |
| 880 | then |
Jon Seymour | de88c1c | 2011-08-07 21:58:14 +1000 | [diff] [blame] | 881 | eval_gettextln 'Patch failed at $msgnum $FIRSTLINE' |
Paul Gortmaker | 14bf2d5 | 2012-07-13 11:51:30 -0400 | [diff] [blame] | 882 | if test "$(git config --bool advice.amworkdir)" != false |
| 883 | then |
Nguyễn Thái Ngọc Duy | a312a27 | 2012-08-22 21:48:03 +0700 | [diff] [blame] | 884 | eval_gettextln 'The copy of the patch that failed is found in: |
| 885 | $dotest/patch' |
Paul Gortmaker | 14bf2d5 | 2012-07-13 11:51:30 -0400 | [diff] [blame] | 886 | fi |
Robert Shearman | ced9456 | 2006-05-02 13:32:43 +0100 | [diff] [blame] | 887 | stop_here_user_resolve $this |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 888 | fi |
| 889 | |
| 890 | if test -x "$GIT_DIR"/hooks/pre-applypatch |
| 891 | then |
| 892 | "$GIT_DIR"/hooks/pre-applypatch || stop_here $this |
| 893 | fi |
| 894 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 895 | tree=$(git write-tree) && |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 896 | commit=$( |
Nanako Shiraishi | a79ec62 | 2009-01-24 10:18:02 +0900 | [diff] [blame] | 897 | if test -n "$ignore_date" |
| 898 | then |
| 899 | GIT_AUTHOR_DATE= |
| 900 | fi |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 901 | parent=$(git rev-parse --verify -q HEAD) || |
Ævar Arnfjörð Bjarmason | dff1a98 | 2011-05-21 18:43:52 +0000 | [diff] [blame] | 902 | say >&2 "$(gettext "applying to an empty history")" |
Nanako Shiraishi | f79d4c8 | 2009-04-10 09:34:42 +0900 | [diff] [blame] | 903 | |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 904 | if test -n "$committer_date_is_author_date" |
| 905 | then |
| 906 | GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" |
| 907 | export GIT_COMMITTER_DATE |
| 908 | fi && |
Nicolas Vigier | 3b4e395f | 2014-02-01 02:18:01 +0000 | [diff] [blame] | 909 | git commit-tree ${parent:+-p} $parent ${gpg_sign_opt:+"$gpg_sign_opt"} $tree \ |
| 910 | <"$dotest/final-commit" |
Junio C Hamano | 3f01ad6 | 2009-01-22 16:14:58 -0800 | [diff] [blame] | 911 | ) && |
Linus Torvalds | 2e6e3e829 | 2008-04-15 12:56:50 -0700 | [diff] [blame] | 912 | git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 913 | stop_here $this |
| 914 | |
Thomas Rast | 96e1948 | 2010-03-12 18:04:29 +0100 | [diff] [blame] | 915 | if test -f "$dotest/original-commit"; then |
| 916 | echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten" |
| 917 | fi |
| 918 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 919 | if test -x "$GIT_DIR"/hooks/post-applypatch |
| 920 | then |
| 921 | "$GIT_DIR"/hooks/post-applypatch |
| 922 | fi |
| 923 | |
Junio C Hamano | d1c5f2a | 2005-10-07 03:44:18 -0700 | [diff] [blame] | 924 | go_next |
| 925 | done |
| 926 | |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 927 | if test -s "$dotest"/rewritten; then |
| 928 | git notes copy --for-rewrite=rebase < "$dotest"/rewritten |
| 929 | if test -x "$GIT_DIR"/hooks/post-rewrite; then |
Thomas Rast | 96e1948 | 2010-03-12 18:04:29 +0100 | [diff] [blame] | 930 | "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 931 | fi |
Thomas Rast | 96e1948 | 2010-03-12 18:04:29 +0100 | [diff] [blame] | 932 | fi |
| 933 | |
Ramkumar Ramachandra | a1549e1 | 2013-05-12 17:26:38 +0530 | [diff] [blame] | 934 | # If am was called with --rebasing (from git-rebase--am), it's up to |
| 935 | # the caller to take care of housekeeping. |
| 936 | if ! test -f "$dotest/rebasing" |
| 937 | then |
| 938 | rm -fr "$dotest" |
| 939 | git gc --auto |
| 940 | fi |