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