Skip to content

Commit 980a3d3

Browse files
committed
Merge branch 'pt/am-tests'
* pt/am-tests: t3901: test git-am encoding conversion t3418: non-interactive rebase --continue with rerere enabled t4150: tests for am --[no-]scissors t4150: am with post-applypatch hook t4150: am with pre-applypatch hook t4150: am with applypatch-msg hook t4150: am --resolved fails if index has unmerged entries t4150: am --resolved fails if index has no changes t4150: am refuses patches when paused t4151: am --abort will keep dirty index intact t4150: am fails if index is dirty t4150: am.messageid really adds the message id
2 parents 461c119 + 5b05b92 commit 980a3d3

File tree

4 files changed

+313
-0
lines changed

4 files changed

+313
-0
lines changed

t/t3418-rebase-continue.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ test_expect_success 'non-interactive rebase --continue works with touched file'
4040
git rebase --continue
4141
'
4242

43+
test_expect_success 'non-interactive rebase --continue with rerere enabled' '
44+
test_config rerere.enabled true &&
45+
test_when_finished "test_might_fail git rebase --abort" &&
46+
git reset --hard commit-new-file-F2-on-topic-branch &&
47+
git checkout master &&
48+
rm -fr .git/rebase-* &&
49+
50+
test_must_fail git rebase --onto master master topic &&
51+
echo "Resolved" >F2 &&
52+
git add F2 &&
53+
cp F2 F2.expected &&
54+
git rebase --continue &&
55+
56+
git reset --hard commit-new-file-F2-on-topic-branch &&
57+
git checkout master &&
58+
test_must_fail git rebase --onto master master topic &&
59+
test_cmp F2.expected F2
60+
'
61+
4362
test_expect_success 'rebase --continue can not be used with other options' '
4463
test_must_fail git rebase -v --continue &&
4564
test_must_fail git rebase --continue -v

t/t3901-i18n-patch.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,66 @@ test_expect_success 'rebase --merge (L/U)' '
251251
check_encoding 2 8859
252252
'
253253

254+
test_expect_success 'am (U/U)' '
255+
# Apply UTF-8 patches with UTF-8 commitencoding
256+
git config i18n.commitencoding UTF-8 &&
257+
. "$TEST_DIRECTORY"/t3901-utf8.txt &&
258+
259+
git reset --hard master &&
260+
git am out-u1 out-u2 &&
261+
262+
check_encoding 2
263+
'
264+
265+
test_expect_success !MINGW 'am (L/L)' '
266+
# Apply ISO-8859-1 patches with ISO-8859-1 commitencoding
267+
git config i18n.commitencoding ISO8859-1 &&
268+
. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
269+
270+
git reset --hard master &&
271+
git am out-l1 out-l2 &&
272+
273+
check_encoding 2 8859
274+
'
275+
276+
test_expect_success 'am (U/L)' '
277+
# Apply ISO-8859-1 patches with UTF-8 commitencoding
278+
git config i18n.commitencoding UTF-8 &&
279+
. "$TEST_DIRECTORY"/t3901-utf8.txt &&
280+
git reset --hard master &&
281+
282+
# am specifies --utf8 by default.
283+
git am out-l1 out-l2 &&
284+
285+
check_encoding 2
286+
'
287+
288+
test_expect_success 'am --no-utf8 (U/L)' '
289+
# Apply ISO-8859-1 patches with UTF-8 commitencoding
290+
git config i18n.commitencoding UTF-8 &&
291+
. "$TEST_DIRECTORY"/t3901-utf8.txt &&
292+
293+
git reset --hard master &&
294+
git am --no-utf8 out-l1 out-l2 2>err &&
295+
296+
# commit-tree will warn that the commit message does not contain valid UTF-8
297+
# as mailinfo did not convert it
298+
grep "did not conform" err &&
299+
300+
check_encoding 2
301+
'
302+
303+
test_expect_success !MINGW 'am (L/U)' '
304+
# Apply UTF-8 patches with ISO-8859-1 commitencoding
305+
git config i18n.commitencoding ISO8859-1 &&
306+
. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
307+
308+
git reset --hard master &&
309+
# mailinfo will re-code the commit message to the charset specified by
310+
# i18n.commitencoding
311+
git am out-u1 out-u2 &&
312+
313+
check_encoding 2 8859
314+
'
315+
254316
test_done

t/t4150-am.sh

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ test_expect_success 'setup: messages' '
6767
6868
EOF
6969
70+
cat >scissors-msg <<-\EOF &&
71+
Test git-am with scissors line
72+
73+
This line should be included in the commit message.
74+
EOF
75+
76+
cat - scissors-msg >no-scissors-msg <<-\EOF &&
77+
This line should not be included in the commit message with --scissors enabled.
78+
79+
- - >8 - - remove everything above this line - - >8 - -
80+
81+
EOF
82+
7083
signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
7184
'
7285

@@ -137,6 +150,20 @@ test_expect_success setup '
137150
} >patch1-hg.eml &&
138151
139152
153+
echo scissors-file >scissors-file &&
154+
git add scissors-file &&
155+
git commit -F scissors-msg &&
156+
git tag scissors &&
157+
git format-patch --stdout scissors^ >scissors-patch.eml &&
158+
git reset --hard HEAD^ &&
159+
160+
echo no-scissors-file >no-scissors-file &&
161+
git add no-scissors-file &&
162+
git commit -F no-scissors-msg &&
163+
git tag no-scissors &&
164+
git format-patch --stdout no-scissors^ >no-scissors-patch.eml &&
165+
git reset --hard HEAD^ &&
166+
140167
sed -n -e "3,\$p" msg >file &&
141168
git add file &&
142169
test_tick &&
@@ -186,6 +213,18 @@ test_expect_success 'am applies patch correctly' '
186213
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
187214
'
188215

216+
test_expect_success 'am fails if index is dirty' '
217+
test_when_finished "rm -f dirtyfile" &&
218+
rm -fr .git/rebase-apply &&
219+
git reset --hard &&
220+
git checkout first &&
221+
echo dirtyfile >dirtyfile &&
222+
git add dirtyfile &&
223+
test_must_fail git am patch1 &&
224+
test_path_is_dir .git/rebase-apply &&
225+
test_cmp_rev first HEAD
226+
'
227+
189228
test_expect_success 'am applies patch e-mail not in a mbox' '
190229
rm -fr .git/rebase-apply &&
191230
git reset --hard &&
@@ -269,6 +308,133 @@ test_expect_success 'am --patch-format=hg applies hg patch' '
269308
test_cmp_rev second^ HEAD^
270309
'
271310

311+
test_expect_success 'am with applypatch-msg hook' '
312+
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
313+
rm -fr .git/rebase-apply &&
314+
git reset --hard &&
315+
git checkout first &&
316+
mkdir -p .git/hooks &&
317+
write_script .git/hooks/applypatch-msg <<-\EOF &&
318+
cat "$1" >actual-msg &&
319+
echo hook-message >"$1"
320+
EOF
321+
git am patch1 &&
322+
test_path_is_missing .git/rebase-apply &&
323+
git diff --exit-code second &&
324+
echo hook-message >expected &&
325+
git log -1 --format=format:%B >actual &&
326+
test_cmp expected actual &&
327+
git log -1 --format=format:%B second >expected &&
328+
test_cmp expected actual-msg
329+
'
330+
331+
test_expect_success 'am with failing applypatch-msg hook' '
332+
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
333+
rm -fr .git/rebase-apply &&
334+
git reset --hard &&
335+
git checkout first &&
336+
mkdir -p .git/hooks &&
337+
write_script .git/hooks/applypatch-msg <<-\EOF &&
338+
exit 1
339+
EOF
340+
test_must_fail git am patch1 &&
341+
test_path_is_dir .git/rebase-apply &&
342+
git diff --exit-code first &&
343+
test_cmp_rev first HEAD
344+
'
345+
346+
test_expect_success 'am with pre-applypatch hook' '
347+
test_when_finished "rm -f .git/hooks/pre-applypatch" &&
348+
rm -fr .git/rebase-apply &&
349+
git reset --hard &&
350+
git checkout first &&
351+
mkdir -p .git/hooks &&
352+
write_script .git/hooks/pre-applypatch <<-\EOF &&
353+
git diff first >diff.actual
354+
exit 0
355+
EOF
356+
git am patch1 &&
357+
test_path_is_missing .git/rebase-apply &&
358+
git diff --exit-code second &&
359+
test_cmp_rev second HEAD &&
360+
git diff first..second >diff.expected &&
361+
test_cmp diff.expected diff.actual
362+
'
363+
364+
test_expect_success 'am with failing pre-applypatch hook' '
365+
test_when_finished "rm -f .git/hooks/pre-applypatch" &&
366+
rm -fr .git/rebase-apply &&
367+
git reset --hard &&
368+
git checkout first &&
369+
mkdir -p .git/hooks &&
370+
write_script .git/hooks/pre-applypatch <<-\EOF &&
371+
exit 1
372+
EOF
373+
test_must_fail git am patch1 &&
374+
test_path_is_dir .git/rebase-apply &&
375+
git diff --exit-code second &&
376+
test_cmp_rev first HEAD
377+
'
378+
379+
test_expect_success 'am with post-applypatch hook' '
380+
test_when_finished "rm -f .git/hooks/post-applypatch" &&
381+
rm -fr .git/rebase-apply &&
382+
git reset --hard &&
383+
git checkout first &&
384+
mkdir -p .git/hooks &&
385+
write_script .git/hooks/post-applypatch <<-\EOF &&
386+
git rev-parse HEAD >head.actual
387+
git diff second >diff.actual
388+
exit 0
389+
EOF
390+
git am patch1 &&
391+
test_path_is_missing .git/rebase-apply &&
392+
test_cmp_rev second HEAD &&
393+
git rev-parse second >head.expected &&
394+
test_cmp head.expected head.actual &&
395+
git diff second >diff.expected &&
396+
test_cmp diff.expected diff.actual
397+
'
398+
399+
test_expect_success 'am with failing post-applypatch hook' '
400+
test_when_finished "rm -f .git/hooks/post-applypatch" &&
401+
rm -fr .git/rebase-apply &&
402+
git reset --hard &&
403+
git checkout first &&
404+
mkdir -p .git/hooks &&
405+
write_script .git/hooks/post-applypatch <<-\EOF &&
406+
git rev-parse HEAD >head.actual
407+
exit 1
408+
EOF
409+
git am patch1 &&
410+
test_path_is_missing .git/rebase-apply &&
411+
git diff --exit-code second &&
412+
test_cmp_rev second HEAD &&
413+
git rev-parse second >head.expected &&
414+
test_cmp head.expected head.actual
415+
'
416+
417+
test_expect_success 'am --scissors cuts the message at the scissors line' '
418+
rm -fr .git/rebase-apply &&
419+
git reset --hard &&
420+
git checkout second &&
421+
git am --scissors scissors-patch.eml &&
422+
test_path_is_missing .git/rebase-apply &&
423+
git diff --exit-code scissors &&
424+
test_cmp_rev scissors HEAD
425+
'
426+
427+
test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
428+
rm -fr .git/rebase-apply &&
429+
git reset --hard &&
430+
git checkout second &&
431+
test_config mailinfo.scissors true &&
432+
git am --no-scissors no-scissors-patch.eml &&
433+
test_path_is_missing .git/rebase-apply &&
434+
git diff --exit-code no-scissors &&
435+
test_cmp_rev no-scissors HEAD
436+
'
437+
272438
test_expect_success 'setup: new author and committer' '
273439
GIT_AUTHOR_NAME="Another Thor" &&
274440
GIT_AUTHOR_EMAIL="[email protected]" &&
@@ -448,6 +614,20 @@ test_expect_success 'am --abort removes a stray directory' '
448614
test_path_is_missing .git/rebase-apply
449615
'
450616

617+
test_expect_success 'am refuses patches when paused' '
618+
rm -fr .git/rebase-apply &&
619+
git reset --hard &&
620+
git checkout lorem2^^ &&
621+
622+
test_must_fail git am lorem-move.patch &&
623+
test_path_is_dir .git/rebase-apply &&
624+
test_cmp_rev lorem2^^ HEAD &&
625+
626+
test_must_fail git am <lorem-move.patch &&
627+
test_path_is_dir .git/rebase-apply &&
628+
test_cmp_rev lorem2^^ HEAD
629+
'
630+
451631
test_expect_success 'am --resolved works' '
452632
echo goodbye >expected &&
453633
rm -fr .git/rebase-apply &&
@@ -462,6 +642,31 @@ test_expect_success 'am --resolved works' '
462642
test_cmp expected another
463643
'
464644

645+
test_expect_success 'am --resolved fails if index has no changes' '
646+
rm -fr .git/rebase-apply &&
647+
git reset --hard &&
648+
git checkout lorem2^^ &&
649+
test_must_fail git am lorem-move.patch &&
650+
test_path_is_dir .git/rebase-apply &&
651+
test_cmp_rev lorem2^^ HEAD &&
652+
test_must_fail git am --resolved &&
653+
test_path_is_dir .git/rebase-apply &&
654+
test_cmp_rev lorem2^^ HEAD
655+
'
656+
657+
test_expect_success 'am --resolved fails if index has unmerged entries' '
658+
rm -fr .git/rebase-apply &&
659+
git reset --hard &&
660+
git checkout second &&
661+
test_must_fail git am -3 lorem-move.patch &&
662+
test_path_is_dir .git/rebase-apply &&
663+
test_cmp_rev second HEAD &&
664+
test_must_fail git am --resolved >err &&
665+
test_path_is_dir .git/rebase-apply &&
666+
test_cmp_rev second HEAD &&
667+
test_i18ngrep "still have unmerged paths" err
668+
'
669+
465670
test_expect_success 'am takes patches from a Pine mailbox' '
466671
rm -fr .git/rebase-apply &&
467672
git reset --hard &&
@@ -626,6 +831,18 @@ test_expect_success 'am --message-id really adds the message id' '
626831
test_cmp expected actual
627832
'
628833

834+
test_expect_success 'am.messageid really adds the message id' '
835+
rm -fr .git/rebase-apply &&
836+
git reset --hard &&
837+
git checkout HEAD^ &&
838+
test_config am.messageid true &&
839+
git am patch1.eml &&
840+
test_path_is_missing .git/rebase-apply &&
841+
git cat-file commit HEAD | tail -n1 >actual &&
842+
grep Message-Id patch1.eml >expected &&
843+
test_cmp expected actual
844+
'
845+
629846
test_expect_success 'am --message-id -s signs off after the message id' '
630847
rm -fr .git/rebase-apply &&
631848
git reset --hard &&

t/t4151-am-abort.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ test_expect_success 'am --abort will keep the local commits intact' '
9595
test_cmp expect actual
9696
'
9797

98+
test_expect_success 'am --abort will keep dirty index intact' '
99+
git reset --hard initial &&
100+
echo dirtyfile >dirtyfile &&
101+
cp dirtyfile dirtyfile.expected &&
102+
git add dirtyfile &&
103+
test_must_fail git am 0001-*.patch &&
104+
test_cmp_rev initial HEAD &&
105+
test_path_is_file dirtyfile &&
106+
test_cmp dirtyfile.expected dirtyfile &&
107+
git am --abort &&
108+
test_cmp_rev initial HEAD &&
109+
test_path_is_file dirtyfile &&
110+
test_cmp dirtyfile.expected dirtyfile
111+
'
112+
98113
test_expect_success 'am -3 stops on conflict on unborn branch' '
99114
git checkout -f --orphan orphan &&
100115
git reset &&

0 commit comments

Comments
 (0)