Skip to content

HTTPS clone URL

Subversion checkout URL

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