Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 846 lines (780 sloc) 20.156 kb
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
1 #!/bin/sh
2 #
d64e6b0 Keep Porcelainish from failing by broken ident after making changes.
Junio C Hamano authored
3 # Copyright (c) 2005, 2006 Junio C Hamano
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
4
c149184 @peff allow git-am to run in a subdirectory
peff authored
5 SUBDIRECTORY_OK=Yes
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
6 OPTIONS_KEEPDASHDASH=
7 OPTIONS_SPEC="\
0adda93 Use parentheses and `...' where appropriate
Štěpán Němec authored
8 git am [options] [(<mbox>|<Maildir>)...]
09f8d05 @sbeyer git-am: Mention --abort in usage string part of OPTIONS_SPEC
sbeyer authored
9 git am [options] (--resolved | --skip | --abort)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
10 --
66006c6 @gitster git-am: -i does not take a string parameter.
authored
11 i,interactive run interactively
98ef23b @jaysoffian git-am: minor cleanups
jaysoffian authored
12 b,binary* (historical option -- no-op)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
13 3,3way allow fall back on 3way merging if needed
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
14 q,quiet be quiet
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
15 s,signoff add a Signed-off-by line to the commit message
16 u,utf8 recode into utf8 (default)
fe1fa94 git-am: fix type in its usage string
Jörg Sommer authored
17 k,keep pass -k flag to git-mailinfo
ad2c928 git-am: Add command line parameter `--keep-cr` passing it to git-mailspl...
Stefan-W. Hahn authored
18 keep-cr pass --keep-cr flag to git-mailsplit for mbox format
e80d4cb git-am: Add am.keepcr and --no-keep-cr to override it
Stefan-W. Hahn authored
19 no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
017678b @gitster am/mailinfo: Disable scissors processing by default
authored
20 c,scissors strip everything before a scissors line
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
21 whitespace= pass it through git-apply
86c91f9 @Oblomov git apply: option to ignore whitespace differences
Oblomov authored
22 ignore-space-change pass it through git-apply
23 ignore-whitespace pass it through git-apply
b47dfe9 @gitster git-am: add --directory=<dir> option
authored
24 directory= pass it through git-apply
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
25 C= pass it through git-apply
26 p= pass it through git-apply
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
27 patch-format= format the patch(es) are in
b80da42 @madduck git-am: implement --reject option passed to git-apply
madduck authored
28 reject pass it through git-apply
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
29 resolvemsg= override error message when patch failure occurs
c8089af @peff am: switch --resolved to --continue
peff authored
30 continue continue applying patches after resolving a conflict
31 r,resolved synonyms for --continue
3041c32 @gitster am: --rebasing
authored
32 skip skip the current patch
3e5057a git am --abort
Nanako Shiraishi authored
33 abort restore the original branch and abort the patching operation.
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
34 committer-date-is-author-date lie about committer date
a79ec62 git-am: Add --ignore-date option
Nanako Shiraishi authored
35 ignore-date use current timestamp for author date
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
36 rerere-autoupdate update the index with reused conflict resolution if possible
98ef23b @jaysoffian git-am: minor cleanups
jaysoffian authored
37 rebasing* (internal use for git-rebase)"
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
38
cf1fe88 git-am: Usage string clean-up
freku045@student.liu.se authored
39 . git-sh-setup
b9a9726 @avar i18n: git-am add git-sh-i18n
avar authored
40 . git-sh-i18n
bb034f8 @gitster am: read from the right mailbox when started from a subdirectory
authored
41 prefix=$(git rev-parse --show-prefix)
f947413 @spearce Use GIT_REFLOG_ACTION environment variable instead.
spearce authored
42 set_reflog_action am
7eff28a @spearce Disallow working directory commands in a bare repository.
spearce authored
43 require_work_tree
c149184 @peff allow git-am to run in a subdirectory
peff authored
44 cd_to_toplevel
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
45
460abee @sbeyer git-am: Do not exit silently if committer is unset
sbeyer authored
46 git var GIT_COMMITTER_IDENT >/dev/null ||
7908725 @avar i18n: git-am die messages
avar authored
47 die "$(gettext "You need to set your committer info first")"
d64e6b0 Keep Porcelainish from failing by broken ident after making changes.
Junio C Hamano authored
48
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
49 if git rev-parse --verify -q HEAD >/dev/null
50 then
51 HAS_HEAD=yes
52 else
53 HAS_HEAD=
54 fi
55
d2c4631 @artagnon git am: Set cmdline globally
artagnon authored
56 cmdline="git am"
57 if test '' != "$interactive"
58 then
59 cmdline="$cmdline -i"
60 fi
61 if test '' != "$threeway"
62 then
63 cmdline="$cmdline -3"
64 fi
65
b47dfe9 @gitster git-am: add --directory=<dir> option
authored
66 sq () {
47c9739 @chriscool am: simplify "sq" function by using "git rev-parse --sq-quote"
chriscool authored
67 git rev-parse --sq-quote "$@"
b47dfe9 @gitster git-am: add --directory=<dir> option
authored
68 }
69
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
70 stop_here () {
71 echo "$1" >"$dotest/next"
7b3b7e3 @gitster am --abort: keep unrelated commits since the last failure and warn
authored
72 git rev-parse --verify -q HEAD >"$dotest/abort-safety"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
73 exit 1
74 }
75
7b3b7e3 @gitster am --abort: keep unrelated commits since the last failure and warn
authored
76 safe_to_abort () {
77 if test -f "$dotest/dirtyindex"
78 then
79 return 1
80 fi
81
82 if ! test -s "$dotest/abort-safety"
83 then
84 return 0
85 fi
86
87 abort_safety=$(cat "$dotest/abort-safety")
88 if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
89 then
90 return 0
91 fi
22fdd11 @avar i18n: git-am gettext + gettext to stderr message
avar authored
92 (
93 gettext "You seem to have moved HEAD since the last 'am' failure.
94 Not rewinding to ORIG_HEAD" &&
95 echo
96 ) >&2
7b3b7e3 @gitster am --abort: keep unrelated commits since the last failure and warn
authored
97 return 1
98 }
99
ced9456 Give the user a hint for how to continue in the case that git-am fails b...
Robert Shearman authored
100 stop_here_user_resolve () {
cc12005 @loops Make git rebase interactive help match documentation.
loops authored
101 if [ -n "$resolvemsg" ]; then
a23bfae @peff More echo "$user_message" fixes.
peff authored
102 printf '%s\n' "$resolvemsg"
cc12005 @loops Make git rebase interactive help match documentation.
loops authored
103 stop_here $1
104 fi
a4372c3 @avar i18n: git-am eval_gettext messages
avar authored
105 eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\".
106 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
107 To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
ced9456 Give the user a hint for how to continue in the case that git-am fails b...
Robert Shearman authored
108
109 stop_here $1
110 }
111
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
112 go_next () {
113 rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
114 "$dotest/patch" "$dotest/info"
115 echo "$next" >"$dotest/next"
116 this=$next
117 }
118
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
119 cannot_fallback () {
120 echo "$1"
81dd2fe @avar i18n: git-am one-line gettext $msg; echo
avar authored
121 gettext "Cannot fall back to three-way merge."; echo
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
122 exit 1
123 }
124
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
125 fall_back_3way () {
126 O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
127
128 rm -fr "$dotest"/patch-merge-*
129 mkdir "$dotest/patch-merge-tmp-dir"
130
131 # First see if the patch records the index info that we can use.
7a98869 @dscho apply: get rid of --index-info in favor of --build-fake-ancestor
dscho authored
132 git apply --build-fake-ancestor "$dotest/patch-merge-tmp-index" \
133 "$dotest/patch" &&
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
134 GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
135 git write-tree >"$dotest/patch-merge-base+" ||
a424ca1 @avar i18n: git-am cannot_fallback messages
avar authored
136 cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")"
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
137
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
138 say Using index info to reconstruct a base tree...
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
139 if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
cb3a160 @sbeyer git-am: ignore --binary option
sbeyer authored
140 git apply --cached <"$dotest/patch"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
141 then
142 mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
143 mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
fd7bcfb git-am: give better diagnostics when the patch does not apply during --3...
Junio C Hamano authored
144 else
a424ca1 @avar i18n: git-am cannot_fallback messages
avar authored
145 cannot_fallback "$(gettext "Did you hand edit your patch?
146 It does not apply to blobs recorded in its index.")"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
147 fi
148
149 test -f "$dotest/patch-merge-index" &&
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
150 his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) &&
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
151 orig_tree=$(cat "$dotest/patch-merge-base") &&
152 rm -fr "$dotest"/patch-merge-* || exit 1
153
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
154 say Falling back to patching base and 3-way merge...
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
155
156 # This is not so wrong. Depending on which base we picked,
157 # orig_tree may be wildly different from ours, but his_tree
158 # has the same set of wildly different changes in parts the
579c9bb @spearce Use merge-recursive in git-am -3.
spearce authored
159 # patch did not touch, so recursive ends up canceling them,
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
160 # saying that we reverted all those changes.
161
2e6e3e8 @torvalds git-am: cope better with an empty Subject: line
torvalds authored
162 eval GITHEAD_$his_tree='"$FIRSTLINE"'
579c9bb @spearce Use merge-recursive in git-am -3.
spearce authored
163 export GITHEAD_$his_tree
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
164 if test -n "$GIT_QUIET"
165 then
69ae92b @gitster shell portability: no "export VAR=VAL"
authored
166 GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
167 fi
579c9bb @spearce Use merge-recursive in git-am -3.
spearce authored
168 git-merge-recursive $orig_tree -- HEAD $his_tree || {
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
169 git rerere $allow_rerere_autoupdate
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
170 echo Failed to merge in the changes.
171 exit 1
172 }
579c9bb @spearce Use merge-recursive in git-am -3.
spearce authored
173 unset GITHEAD_$his_tree
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
174 }
175
0cd29a0 @Oblomov git-am: refactor 'cleaning up and aborting'
Oblomov authored
176 clean_abort () {
177 test $# = 0 || echo >&2 "$@"
178 rm -fr "$dotest"
179 exit 1
180 }
181
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
182 patch_format=
183
184 check_patch_format () {
185 # early return if patch_format was set from the command line
186 if test -n "$patch_format"
187 then
188 return 0
189 fi
15ced75 @Oblomov git-am foreign patch support: autodetect some patch formats
Oblomov authored
190
191 # we default to mbox format if input is from stdin and for
192 # directories
193 if test $# = 0 || test "x$1" = "x-" || test -d "$1"
194 then
195 patch_format=mbox
196 return 0
197 fi
198
199 # otherwise, check the first few lines of the first patch to try
200 # to detect its format
201 {
202 read l1
203 read l2
204 read l3
205 case "$l1" in
206 "From "* | "From: "*)
207 patch_format=mbox
208 ;;
209 '# This series applies on GIT commit'*)
210 patch_format=stgit-series
211 ;;
212 "# HG changeset patch")
213 patch_format=hg
214 ;;
215 *)
216 # if the second line is empty and the third is
217 # a From, Author or Date entry, this is very
218 # likely an StGIT patch
219 case "$l2,$l3" in
220 ,"From: "* | ,"Author: "* | ,"Date: "*)
221 patch_format=stgit
222 ;;
223 *)
224 ;;
225 esac
226 ;;
227 esac
0fcb2ca @gitster am: allow individual e-mail files as input
authored
228 if test -z "$patch_format" &&
229 test -n "$l1" &&
230 test -n "$l2" &&
231 test -n "$l3"
232 then
233 # This begins with three non-empty lines. Is this a
234 # piece of e-mail a-la RFC2822? Grab all the headers,
235 # discarding the indented remainder of folded lines,
236 # and see if it looks like that they all begin with the
237 # header field names...
e3f67d3 @bebarino am: fix patch format detection for Thunderbird "Save As" emails
bebarino authored
238 tr -d '\015' <"$1" |
239 sed -n -e '/^$/q' -e '/^[ ]/d' -e p |
e1622bf @gitster Protect scripted Porcelains from GREP_OPTIONS insanity
authored
240 sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
0fcb2ca @gitster am: allow individual e-mail files as input
authored
241 patch_format=mbox
242 fi
0cd29a0 @Oblomov git-am: refactor 'cleaning up and aborting'
Oblomov authored
243 } < "$1" || clean_abort
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
244 }
245
246 split_patches () {
247 case "$patch_format" in
248 mbox)
e80d4cb git-am: Add am.keepcr and --no-keep-cr to override it
Stefan-W. Hahn authored
249 if test -n "$rebasing" || test t = "$keepcr"
ad2c928 git-am: Add command line parameter `--keep-cr` passing it to git-mailspl...
Stefan-W. Hahn authored
250 then
251 keep_cr=--keep-cr
252 else
253 keep_cr=
254 fi
c2ca1d7 @gitster Allow mailsplit (and hence git-am) to handle mails with CRLF line-ending...
authored
255 git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
0cd29a0 @Oblomov git-am: refactor 'cleaning up and aborting'
Oblomov authored
256 clean_abort
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
257 ;;
c574e68 @Oblomov git-am foreign patch support: StGIT support
Oblomov authored
258 stgit-series)
259 if test $# -ne 1
260 then
d62a146 @avar i18n: git-am clean_abort messages
avar authored
261 clean_abort "$(gettext "Only one StGIT patch series can be applied at once")"
c574e68 @Oblomov git-am foreign patch support: StGIT support
Oblomov authored
262 fi
263 series_dir=`dirname "$1"`
264 series_file="$1"
265 shift
266 {
267 set x
268 while read filename
269 do
270 set "$@" "$series_dir/$filename"
271 done
272 # remove the safety x
273 shift
274 # remove the arg coming from the first-line comment
275 shift
0cd29a0 @Oblomov git-am: refactor 'cleaning up and aborting'
Oblomov authored
276 } < "$series_file" || clean_abort
c574e68 @Oblomov git-am foreign patch support: StGIT support
Oblomov authored
277 # set the patch format appropriately
278 patch_format=stgit
279 # now handle the actual StGIT patches
280 split_patches "$@"
281 ;;
282 stgit)
283 this=0
284 for stgit in "$@"
285 do
286 this=`expr "$this" + 1`
287 msgnum=`printf "%0${prec}d" $this`
288 # Perl version of StGIT parse_patch. The first nonemptyline
289 # not starting with Author, From or Date is the
290 # subject, and the body starts with the next nonempty
291 # line not starting with Author, From or Date
292 perl -ne 'BEGIN { $subject = 0 }
293 if ($subject > 1) { print ; }
294 elsif (/^\s+$/) { next ; }
295 elsif (/^Author:/) { print s/Author/From/ ; }
296 elsif (/^(From|Date)/) { print ; }
297 elsif ($subject) {
298 $subject = 2 ;
299 print "\n" ;
300 print ;
301 } else {
302 print "Subject: ", $_ ;
303 $subject = 1;
304 }
0cd29a0 @Oblomov git-am: refactor 'cleaning up and aborting'
Oblomov authored
305 ' < "$stgit" > "$dotest/$msgnum" || clean_abort
c574e68 @Oblomov git-am foreign patch support: StGIT support
Oblomov authored
306 done
307 echo "$this" > "$dotest/last"
308 this=
309 msgnum=
310 ;;
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
311 *)
46caf50 @nicolas33 git-am: print fair error message when format detection fails
nicolas33 authored
312 if test -n "$parse_patch" ; then
d62a146 @avar i18n: git-am clean_abort messages
avar authored
313 clean_abort "$(eval_gettext "Patch format \$patch_format is not supported.")"
46caf50 @nicolas33 git-am: print fair error message when format detection fails
nicolas33 authored
314 else
d62a146 @avar i18n: git-am clean_abort messages
avar authored
315 clean_abort "$(gettext "Patch format detection failed.")"
46caf50 @nicolas33 git-am: print fair error message when format detection fails
nicolas33 authored
316 fi
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
317 ;;
318 esac
319 }
320
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
321 prec=4
51ef1da @dscho Rename .git/rebase to .git/rebase-apply
dscho authored
322 dotest="$GIT_DIR/rebase-apply"
ad2c928 git-am: Add command line parameter `--keep-cr` passing it to git-mailspl...
Stefan-W. Hahn authored
323 sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
d25e515 @luksan git am/mailinfo: Don't look at in-body headers when rebasing
luksan authored
324 resolvemsg= resume= scissors= no_inbody_headers=
67dad68 add -C[NUM] to git-am
Michael S. Tsirkin authored
325 git_apply_opt=
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
326 committer_date_is_author_date=
a79ec62 git-am: Add --ignore-date option
Nanako Shiraishi authored
327 ignore_date=
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
328 allow_rerere_autoupdate=
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
329
e80d4cb git-am: Add am.keepcr and --no-keep-cr to override it
Stefan-W. Hahn authored
330 if test "$(git config --bool --get am.keepcr)" = true
331 then
332 keepcr=t
333 fi
334
822f7c7 Supplant the "while case ... break ;; esac" idiom
David Kastrup authored
335 while test $# != 0
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
336 do
337 case "$1" in
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
338 -i|--interactive)
339 interactive=t ;;
340 -b|--binary)
cb3a160 @sbeyer git-am: ignore --binary option
sbeyer authored
341 : ;;
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
342 -3|--3way)
343 threeway=t ;;
dfdd7e6 Give git-am back the ability to add Signed-off-by lines.
Johannes Sixt authored
344 -s|--signoff)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
345 sign=t ;;
346 -u|--utf8)
347 utf8=t ;; # this is now default
348 --no-utf8)
349 utf8= ;;
350 -k|--keep)
351 keep=t ;;
017678b @gitster am/mailinfo: Disable scissors processing by default
authored
352 -c|--scissors)
353 scissors=t ;;
354 --no-scissors)
355 scissors=f ;;
c8089af @peff am: switch --resolved to --continue
peff authored
356 -r|--resolved|--continue)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
357 resolved=t ;;
358 --skip)
359 skip=t ;;
3e5057a git am --abort
Nanako Shiraishi authored
360 --abort)
361 abort=t ;;
3041c32 @gitster am: --rebasing
authored
362 --rebasing)
d25e515 @luksan git am/mailinfo: Don't look at in-body headers when rebasing
luksan authored
363 rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
364 -d|--dotest)
7908725 @avar i18n: git-am die messages
avar authored
365 die "$(gettext "-d option is no longer supported. Do not use.")"
e72c740 @gitster am: remove support for -d .dotest
authored
366 ;;
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
367 --resolvemsg)
368 shift; resolvemsg=$1 ;;
b47dfe9 @gitster git-am: add --directory=<dir> option
authored
369 --whitespace|--directory)
370 git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
371 -C|-p)
b47dfe9 @gitster git-am: add --directory=<dir> option
authored
372 git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
373 --patch-format)
374 shift ; patch_format="$1" ;;
86c91f9 @Oblomov git apply: option to ignore whitespace differences
Oblomov authored
375 --reject|--ignore-whitespace|--ignore-space-change)
b80da42 @madduck git-am: implement --reject option passed to git-apply
madduck authored
376 git_apply_opt="$git_apply_opt $1" ;;
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
377 --committer-date-is-author-date)
378 committer_date_is_author_date=t ;;
a79ec62 git-am: Add --ignore-date option
Nanako Shiraishi authored
379 --ignore-date)
380 ignore_date=t ;;
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
381 --rerere-autoupdate|--no-rerere-autoupdate)
382 allow_rerere_autoupdate="$1" ;;
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
383 -q|--quiet)
384 GIT_QUIET=t ;;
ad2c928 git-am: Add command line parameter `--keep-cr` passing it to git-mailspl...
Stefan-W. Hahn authored
385 --keep-cr)
386 keepcr=t ;;
e80d4cb git-am: Add am.keepcr and --no-keep-cr to override it
Stefan-W. Hahn authored
387 --no-keep-cr)
388 keepcr=f ;;
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
389 --)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
390 shift; break ;;
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
391 *)
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
392 usage ;;
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
393 esac
78443d9 @MadCoder Migrate git-am.sh to use git-rev-parse --parseopt
MadCoder authored
394 shift
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
395 done
396
0c15cc9 git-am: --resolved.
Junio C Hamano authored
397 # If the dotest directory exists, but we have finished applying all the
398 # patches in them, clear it out.
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
399 if test -d "$dotest" &&
400 last=$(cat "$dotest/last") &&
401 next=$(cat "$dotest/next") &&
402 test $# != 0 &&
403 test "$next" -gt "$last"
404 then
405 rm -fr "$dotest"
406 fi
407
408 if test -d "$dotest"
409 then
3e5057a git am --abort
Nanako Shiraishi authored
410 case "$#,$skip$resolved$abort" in
c95b138 Fix git-am safety checks
Junio C Hamano authored
411 0,*t*)
412 # Explicit resume command and we do not have file, so
413 # we are happy.
414 : ;;
415 0,)
416 # No file input but without resume parameters; catch
417 # user error to feed us a patch from standard input
e72c740 @gitster am: remove support for -d .dotest
authored
418 # when there is already $dotest. This is somewhat
c95b138 Fix git-am safety checks
Junio C Hamano authored
419 # unreliable -- stdin could be /dev/null for example
420 # and the caller did not intend to feed us a patch but
421 # wanted to continue unattended.
98ef23b @jaysoffian git-am: minor cleanups
jaysoffian authored
422 test -t 0
c95b138 Fix git-am safety checks
Junio C Hamano authored
423 ;;
424 *)
425 false
426 ;;
427 esac ||
7908725 @avar i18n: git-am die messages
avar authored
428 die "$(eval_gettext "previous rebase directory \$dotest still exists but mbox given.")"
271440e git-am: make it easier after fixing up an unapplicable patch.
Junio C Hamano authored
429 resume=yes
3e5057a git am --abort
Nanako Shiraishi authored
430
95f8ebb git am --skip: clean the index while preserving local changes
Olivier Marin authored
431 case "$skip,$abort" in
2d56a13 @gitster git-am: make --abort less dangerous
authored
432 t,t)
7908725 @avar i18n: git-am die messages
avar authored
433 die "$(gettext "Please make up your mind. --skip or --abort?")"
2d56a13 @gitster git-am: make --abort less dangerous
authored
434 ;;
95f8ebb git am --skip: clean the index while preserving local changes
Olivier Marin authored
435 t,)
436 git rerere clear
437 git read-tree --reset -u HEAD HEAD
438 orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
439 git reset HEAD
440 git update-ref ORIG_HEAD $orig_head
441 ;;
442 ,t)
2d56a13 @gitster git-am: make --abort less dangerous
authored
443 if test -f "$dotest/rebasing"
444 then
445 exec git rebase --abort
446 fi
3e5057a git am --abort
Nanako Shiraishi authored
447 git rerere clear
7b3b7e3 @gitster am --abort: keep unrelated commits since the last failure and warn
authored
448 if safe_to_abort
449 then
c767184 @mjg git-am: Keep index in case of abort with dirty index
mjg authored
450 git read-tree --reset -u HEAD ORIG_HEAD
451 git reset ORIG_HEAD
7b3b7e3 @gitster am --abort: keep unrelated commits since the last failure and warn
authored
452 fi
3e5057a git am --abort
Nanako Shiraishi authored
453 rm -fr "$dotest"
454 exit ;;
455 esac
c767184 @mjg git-am: Keep index in case of abort with dirty index
mjg authored
456 rm -f "$dotest/dirtyindex"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
457 else
3e5057a git am --abort
Nanako Shiraishi authored
458 # Make sure we are not given --skip, --resolved, nor --abort
459 test "$skip$resolved$abort" = "" ||
7908725 @avar i18n: git-am die messages
avar authored
460 die "$(gettext "Resolve operation not in progress, we are not resuming.")"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
461
462 # Start afresh.
463 mkdir -p "$dotest" || exit
464
bb034f8 @gitster am: read from the right mailbox when started from a subdirectory
authored
465 if test -n "$prefix" && test $# != 0
466 then
467 first=t
468 for arg
469 do
470 test -n "$first" && {
471 set x
472 first=
473 }
5e9677c @patthoyts git-am: fix detection of absolute paths for windows
patthoyts authored
474 if is_absolute_path "$arg"
475 then
476 set "$@" "$arg"
477 else
478 set "$@" "$prefix$arg"
479 fi
bb034f8 @gitster am: read from the right mailbox when started from a subdirectory
authored
480 done
481 shift
482 fi
a5a6755 @Oblomov git-am foreign patch support: introduce patch_format
Oblomov authored
483
484 check_patch_format "$@"
485
486 split_patches "$@"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
487
017678b @gitster am/mailinfo: Disable scissors processing by default
authored
488 # -i can and must be given when resuming; everything
489 # else is kept
9b9f5a2 @gitster git-am: rename apply_opt_extra file to apply-opt
authored
490 echo " $git_apply_opt" >"$dotest/apply-opt"
22db240 @gitster git-am: propagate --3way options as well
authored
491 echo "$threeway" >"$dotest/threeway"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
492 echo "$sign" >"$dotest/sign"
493 echo "$utf8" >"$dotest/utf8"
494 echo "$keep" >"$dotest/keep"
ad2c928 git-am: Add command line parameter `--keep-cr` passing it to git-mailspl...
Stefan-W. Hahn authored
495 echo "$keepcr" >"$dotest/keepcr"
017678b @gitster am/mailinfo: Disable scissors processing by default
authored
496 echo "$scissors" >"$dotest/scissors"
d25e515 @luksan git am/mailinfo: Don't look at in-body headers when rebasing
luksan authored
497 echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
498 echo "$GIT_QUIET" >"$dotest/quiet"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
499 echo 1 >"$dotest/next"
3041c32 @gitster am: --rebasing
authored
500 if test -n "$rebasing"
501 then
502 : >"$dotest/rebasing"
503 else
504 : >"$dotest/applying"
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
505 if test -n "$HAS_HEAD"
506 then
507 git update-ref ORIG_HEAD HEAD
508 else
509 git update-ref -d ORIG_HEAD >/dev/null 2>&1
510 fi
3041c32 @gitster am: --rebasing
authored
511 fi
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
512 fi
513
0c15cc9 git-am: --resolved.
Junio C Hamano authored
514 case "$resolved" in
515 '')
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
516 case "$HAS_HEAD" in
517 '')
518 files=$(git ls-files) ;;
519 ?*)
520 files=$(git diff-index --cached --name-only HEAD --) ;;
521 esac || exit
c767184 @mjg git-am: Keep index in case of abort with dirty index
mjg authored
522 if test "$files"
523 then
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
524 test -n "$HAS_HEAD" && : >"$dotest/dirtyindex"
7908725 @avar i18n: git-am die messages
avar authored
525 die "$(eval_gettext "Dirty index: cannot apply patches (dirty: \$files)")"
c767184 @mjg git-am: Keep index in case of abort with dirty index
mjg authored
526 fi
0c15cc9 git-am: --resolved.
Junio C Hamano authored
527 esac
528
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
529 if test "$(cat "$dotest/utf8")" = t
530 then
531 utf8=-u
bb1091a -u is now default for 'git-mailinfo'.
Junio C Hamano authored
532 else
533 utf8=-n
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
534 fi
535 if test "$(cat "$dotest/keep")" = t
536 then
537 keep=-k
538 fi
e80d4cb git-am: Add am.keepcr and --no-keep-cr to override it
Stefan-W. Hahn authored
539 case "$(cat "$dotest/keepcr")" in
540 t)
541 keepcr=--keep-cr ;;
542 f)
543 keepcr=--no-keep-cr ;;
544 esac
017678b @gitster am/mailinfo: Disable scissors processing by default
authored
545 case "$(cat "$dotest/scissors")" in
546 t)
547 scissors=--scissors ;;
548 f)
549 scissors=--no-scissors ;;
550 esac
d25e515 @luksan git am/mailinfo: Don't look at in-body headers when rebasing
luksan authored
551 if test "$(cat "$dotest/no_inbody_headers")" = t
552 then
553 no_inbody_headers=--no-inbody-headers
554 else
555 no_inbody_headers=
556 fi
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
557 if test "$(cat "$dotest/quiet")" = t
558 then
559 GIT_QUIET=t
560 fi
22db240 @gitster git-am: propagate --3way options as well
authored
561 if test "$(cat "$dotest/threeway")" = t
562 then
563 threeway=t
564 fi
9b9f5a2 @gitster git-am: rename apply_opt_extra file to apply-opt
authored
565 git_apply_opt=$(cat "$dotest/apply-opt")
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
566 if test "$(cat "$dotest/sign")" = t
567 then
5354a56 @tmzullinger Replace uses of "git-var" with "git var"
tmzullinger authored
568 SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
569 s/>.*/>/
570 s/^/Signed-off-by: /'
571 `
572 else
573 SIGNOFF=
574 fi
575
576 last=`cat "$dotest/last"`
577 this=`cat "$dotest/next"`
578 if test "$skip" = t
579 then
580 this=`expr "$this" + 1`
6922471 @jaharkes Fix git-am --skip
jaharkes authored
581 resume=
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
582 fi
583
584 while test "$this" -le "$last"
585 do
586 msgnum=`printf "%0${prec}d" $this`
587 next=`expr "$this" + 1`
588 test -f "$dotest/$msgnum" || {
6922471 @jaharkes Fix git-am --skip
jaharkes authored
589 resume=
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
590 go_next
591 continue
592 }
0c15cc9 git-am: --resolved.
Junio C Hamano authored
593
594 # If we are not resuming, parse and extract the patch information
595 # into separate files:
596 # - info records the authorship and title
597 # - msg is the rest of commit log message
598 # - patch is the patch body.
599 #
600 # When we are resuming, these files are either already prepared
601 # by the user, or the user can tell us to do so by --resolved flag.
271440e git-am: make it easier after fixing up an unapplicable patch.
Junio C Hamano authored
602 case "$resume" in
603 '')
d25e515 @luksan git am/mailinfo: Don't look at in-body headers when rebasing
luksan authored
604 git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
271440e git-am: make it easier after fixing up an unapplicable patch.
Junio C Hamano authored
605 <"$dotest/$msgnum" >"$dotest/info" ||
606 stop_here $this
ca193cf @dscho git am: skip pine's internal folder data
dscho authored
607
608 # skip pine's internal folder data
e1622bf @gitster Protect scripted Porcelains from GREP_OPTIONS insanity
authored
609 sane_grep '^Author: Mail System Internal Data$' \
ca193cf @dscho git am: skip pine's internal folder data
dscho authored
610 <"$dotest"/info >/dev/null &&
611 go_next && continue
612
28ed6e7 @dscho Rename ".dotest/" to ".git/rebase" and ".dotest-merge" to "rebase-merge"
dscho authored
613 test -s "$dotest/patch" || {
a4372c3 @avar i18n: git-am eval_gettext messages
avar authored
614 eval_gettext "Patch is empty. Was it split wrong?
615 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
616 To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
87ab799 builtin-mailinfo.c infrastrcture changes
Don Zickus authored
617 stop_here $this
618 }
43c2325 @jaysoffian am: use get_author_ident_from_commit instead of mailinfo when rebasing
jaysoffian authored
619 rm -f "$dotest/original-commit" "$dotest/author-script"
5e835ca @gitster rebase: do not munge commit log message
authored
620 if test -f "$dotest/rebasing" &&
621 commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
622 -e q "$dotest/$msgnum") &&
623 test "$(git cat-file -t "$commit")" = commit
624 then
625 git cat-file commit "$commit" |
626 sed -e '1,/^$/d' >"$dotest/msg-clean"
96e1948 @trast rebase: invoke post-rewrite hook
trast authored
627 echo "$commit" > "$dotest/original-commit"
43c2325 @jaysoffian am: use get_author_ident_from_commit instead of mailinfo when rebasing
jaysoffian authored
628 get_author_ident_from_commit "$commit" > "$dotest/author-script"
5e835ca @gitster rebase: do not munge commit log message
authored
629 else
c970a6f @gitster Remove dead code from "git am"
authored
630 {
631 sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
632 echo
633 cat "$dotest/msg"
634 } |
635 git stripspace > "$dotest/msg-clean"
5e835ca @gitster rebase: do not munge commit log message
authored
636 fi
271440e git-am: make it easier after fixing up an unapplicable patch.
Junio C Hamano authored
637 ;;
638 esac
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
639
43c2325 @jaysoffian am: use get_author_ident_from_commit instead of mailinfo when rebasing
jaysoffian authored
640 if test -f "$dotest/author-script"
641 then
642 eval $(cat "$dotest/author-script")
643 else
644 GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
645 GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
646 GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
647 fi
e0e3ba2 mailinfo and git-am: allow "John Doe <johndoe>"
Junio C Hamano authored
648
3b78959 @gitster Revert "git-am: catch missing author date early."
authored
649 if test -z "$GIT_AUTHOR_EMAIL"
e0e3ba2 mailinfo and git-am: allow "John Doe <johndoe>"
Junio C Hamano authored
650 then
81dd2fe @avar i18n: git-am one-line gettext $msg; echo
avar authored
651 gettext "Patch does not have a valid e-mail address."; echo
e0e3ba2 mailinfo and git-am: allow "John Doe <johndoe>"
Junio C Hamano authored
652 stop_here $this
653 fi
654
2c67419 Fix missing exports in git-am
Junio C Hamano authored
655 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
656
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
657 case "$resume" in
658 '')
659 if test '' != "$SIGNOFF"
660 then
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
661 LAST_SIGNED_OFF_BY=`
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
662 sed -ne '/^Signed-off-by: /p' \
663 "$dotest/msg-clean" |
b4ce54f @peff remove use of "tail -n 1" and "tail -1"
peff authored
664 sed -ne '$p'
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
665 `
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
666 ADD_SIGNOFF=`
667 test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
668 test '' = "$LAST_SIGNED_OFF_BY" && echo
669 echo "$SIGNOFF"
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
670 }`
671 else
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
672 ADD_SIGNOFF=
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
673 fi
674 {
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
675 if test -s "$dotest/msg-clean"
676 then
677 cat "$dotest/msg-clean"
678 fi
679 if test '' != "$ADD_SIGNOFF"
680 then
681 echo "$ADD_SIGNOFF"
682 fi
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
683 } >"$dotest/final-commit"
684 ;;
0c15cc9 git-am: --resolved.
Junio C Hamano authored
685 *)
6d28644 git-am: do not allow empty commits by mistake.
Junio C Hamano authored
686 case "$resolved$interactive" in
0c15cc9 git-am: --resolved.
Junio C Hamano authored
687 tt)
688 # This is used only for interactive view option.
38762c4 @gitster scripts: do not get confused with HEAD in work tree
authored
689 git diff-index -p --cached HEAD -- >"$dotest/patch"
0c15cc9 git-am: --resolved.
Junio C Hamano authored
690 ;;
691 esac
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
692 esac
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
693
4bfb6b6 git-am: do not lose already edited final-commit when resuming.
Junio C Hamano authored
694 resume=
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
695 if test "$interactive" = t
696 then
a145110 git-am: interactive should fail gracefully.
Junio C Hamano authored
697 test -t 0 ||
7908725 @avar i18n: git-am die messages
avar authored
698 die "$(gettext "cannot be interactive without stdin connected to a terminal.")"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
699 action=again
700 while test "$action" = again
701 do
81dd2fe @avar i18n: git-am one-line gettext $msg; echo
avar authored
702 gettext "Commit Body is:"; echo
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
703 echo "--------------------------"
704 cat "$dotest/final-commit"
705 echo "--------------------------"
9754563 Use printf rather than echo -n.
Jason Riedy authored
706 printf "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
707 read reply
708 case "$reply" in
f89ad67 Add [v]iew patch in git-am interactive.
Junio C Hamano authored
709 [yY]*) action=yes ;;
710 [aA]*) action=yes interactive= ;;
711 [nN]*) action=skip ;;
ef0c2ab @aroben Add GIT_EDITOR environment and core.editor configuration variables
aroben authored
712 [eE]*) git_editor "$dotest/final-commit"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
713 action=again ;;
f89ad67 Add [v]iew patch in git-am interactive.
Junio C Hamano authored
714 [vV]*) action=again
f6dff11 @jrn am: Fix launching of pager
jrn authored
715 git_pager "$dotest/patch" ;;
f89ad67 Add [v]iew patch in git-am interactive.
Junio C Hamano authored
716 *) action=again ;;
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
717 esac
718 done
719 else
720 action=yes
721 fi
92f65e6 @artagnon git am: Remove stray error message from sed
artagnon authored
722
723 if test -f "$dotest/final-commit"
724 then
725 FIRSTLINE=$(sed 1q "$dotest/final-commit")
726 else
727 FIRSTLINE=""
728 fi
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
729
730 if test $action = skip
731 then
732 go_next
733 continue
734 fi
735
736 if test -x "$GIT_DIR"/hooks/applypatch-msg
737 then
738 "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
739 stop_here $this
740 fi
741
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
742 say "Applying: $FIRSTLINE"
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
743
0c15cc9 git-am: --resolved.
Junio C Hamano authored
744 case "$resolved" in
745 '')
3ddd170 @bebarino am: suppress apply errors when using 3-way
bebarino authored
746 # When we are allowed to fall back to 3-way later, don't give
747 # false errors during the initial attempt.
748 squelch=
749 if test "$threeway" = t
750 then
751 squelch='>/dev/null 2>&1 '
752 fi
753 eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"'
0c15cc9 git-am: --resolved.
Junio C Hamano authored
754 apply_status=$?
755 ;;
756 t)
757 # Resolved means the user did all the hard work, and
758 # we do not have to do any patch application. Just
759 # trust what the user has in the index file and the
760 # working tree.
761 resolved=
38762c4 @gitster scripts: do not get confused with HEAD in work tree
authored
762 git diff-index --quiet --cached HEAD -- && {
bd8643a @avar i18n: git-am multi-line getttext $msg; echo
avar authored
763 gettext "No changes - did you forget to use 'git add'?
764 If there is nothing left to stage, chances are that something else
765 already introduced the same changes; you might want to skip this patch."; echo
ced9456 Give the user a hint for how to continue in the case that git-am fails b...
Robert Shearman authored
766 stop_here_user_resolve $this
06aff47 @raalkml Use diff* with --exit-code in git-am, git-rebase and git-merge-ours
raalkml authored
767 }
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
768 unmerged=$(git ls-files -u)
c1d1128 git-am --resolved: more usable error message.
Junio C Hamano authored
769 if test -n "$unmerged"
770 then
bd8643a @avar i18n: git-am multi-line getttext $msg; echo
avar authored
771 gettext "You still have unmerged paths in your index
772 did you forget to use 'git add'?"; echo
ced9456 Give the user a hint for how to continue in the case that git-am fails b...
Robert Shearman authored
773 stop_here_user_resolve $this
c1d1128 git-am --resolved: more usable error message.
Junio C Hamano authored
774 fi
0c15cc9 git-am: --resolved.
Junio C Hamano authored
775 apply_status=0
b4372ef @dscho Enable "git rerere" by the config variable rerere.enabled
dscho authored
776 git rerere
0c15cc9 git-am: --resolved.
Junio C Hamano authored
777 ;;
778 esac
779
0ba17dd @gitster am -3: recover the diagnostic messages for corrupt patches
authored
780 if test $apply_status != 0 && test "$threeway" = t
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
781 then
7331903 git-am: do not fail if 3-way fallback succeeds.
Junio C Hamano authored
782 if (fall_back_3way)
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
783 then
7331903 git-am: do not fail if 3-way fallback succeeds.
Junio C Hamano authored
784 # Applying the patch to an earlier tree and merging the
785 # result may have produced the same tree as ours.
38762c4 @gitster scripts: do not get confused with HEAD in work tree
authored
786 git diff-index --quiet --cached HEAD -- && {
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
787 say No changes -- Patch already applied.
06aff47 @raalkml Use diff* with --exit-code in git-am, git-rebase and git-merge-ours
raalkml authored
788 go_next
789 continue
790 }
7331903 git-am: do not fail if 3-way fallback succeeds.
Junio C Hamano authored
791 # clear apply_status -- we have successfully merged.
792 apply_status=0
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
793 fi
794 fi
795 if test $apply_status != 0
796 then
4d2e283 @gitster git-am: re-fix the diag message printing
authored
797 printf 'Patch failed at %s %s\n' "$msgnum" "$FIRSTLINE"
ced9456 Give the user a hint for how to continue in the case that git-am fails b...
Robert Shearman authored
798 stop_here_user_resolve $this
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
799 fi
800
801 if test -x "$GIT_DIR"/hooks/pre-applypatch
802 then
803 "$GIT_DIR"/hooks/pre-applypatch || stop_here $this
804 fi
805
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
806 tree=$(git write-tree) &&
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
807 commit=$(
a79ec62 git-am: Add --ignore-date option
Nanako Shiraishi authored
808 if test -n "$ignore_date"
809 then
810 GIT_AUTHOR_DATE=
811 fi
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
812 parent=$(git rev-parse --verify -q HEAD) ||
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
813 say >&2 "applying to an empty history"
f79d4c8 git-am: teach git-am to apply a patch to an unborn branch
Nanako Shiraishi authored
814
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
815 if test -n "$committer_date_is_author_date"
816 then
817 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
818 export GIT_COMMITTER_DATE
819 fi &&
ea10b60 @bjj Work around ash "alternate value" expansion bug
bjj authored
820 git commit-tree $tree ${parent:+-p} $parent <"$dotest/final-commit"
3f01ad6 @gitster am: Add --committer-date-is-author-date option
authored
821 ) &&
2e6e3e8 @torvalds git-am: cope better with an empty Subject: line
torvalds authored
822 git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
823 stop_here $this
824
96e1948 @trast rebase: invoke post-rewrite hook
trast authored
825 if test -f "$dotest/original-commit"; then
826 echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
827 fi
828
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
829 if test -x "$GIT_DIR"/hooks/post-applypatch
830 then
831 "$GIT_DIR"/hooks/post-applypatch
832 fi
833
834 go_next
835 done
836
eb2151b @trast rebase: support automatic notes copying
trast authored
837 if test -s "$dotest"/rewritten; then
838 git notes copy --for-rewrite=rebase < "$dotest"/rewritten
839 if test -x "$GIT_DIR"/hooks/post-rewrite; then
96e1948 @trast rebase: invoke post-rewrite hook
trast authored
840 "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
eb2151b @trast rebase: support automatic notes copying
trast authored
841 fi
96e1948 @trast rebase: invoke post-rewrite hook
trast authored
842 fi
843
d1c5f2a Add git-am, applymbox replacement.
Junio C Hamano authored
844 rm -fr "$dotest"
29b6754 @jrn am: remove rebase-apply directory before gc
jrn authored
845 git gc --auto
Something went wrong with that request. Please try again.