Skip to content

HTTPS clone URL

Subversion checkout URL

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