3 test_description
='am --abort'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success setup
'
9 test_write_lines a b c d e f g >file-1 &&
12 git add file-1 file-2 &&
13 git commit -m initial &&
15 git format-patch --stdout --root initial >initial.patch &&
19 echo $i >otherfile-$i &&
20 git add otherfile-$i &&
22 git commit -a -m $i || return 1
25 git format-patch --no-numbered initial &&
26 git checkout -b conflicting initial &&
27 echo different >>file-1 &&
28 echo whatever >new-file &&
29 git add file-1 new-file &&
30 git commit -m different &&
31 git checkout -b side initial &&
32 echo local change >file-2-expect
37 test_expect_success
"am$with3 stops at a patch that does not apply" '
39 git reset --hard initial &&
40 cp file-2-expect file-2 &&
42 test_must_fail git am$with3 000[1245]-*.patch &&
43 git log --pretty=tformat:%s >actual &&
44 test_write_lines 3 2 initial >expect &&
45 test_cmp expect actual
48 test_expect_success
"am$with3 --skip continue after failed am$with3" '
49 test_must_fail git am$with3 --skip >output &&
50 test_grep "^Applying: 6$" output &&
51 test_cmp file-2-expect file-2 &&
52 test ! -f .git/MERGE_RR
55 test_expect_success
"am --abort goes back after failed am$with3" '
57 git rev-parse HEAD >actual &&
58 git rev-parse initial >expect &&
59 test_cmp expect actual &&
60 test_cmp file-2-expect file-2 &&
61 git diff-index --exit-code --cached HEAD &&
62 test ! -f .git/MERGE_RR
67 test_expect_success
'am -3 --skip removes otherfile-4' '
68 git reset --hard initial &&
69 test_must_fail git am -3 0003-*.patch &&
70 test 3 -eq $(git ls-files -u | wc -l) &&
71 test 4 = "$(cat otherfile-4)" &&
73 test_cmp_rev initial HEAD &&
74 test -z "$(git ls-files -u)" &&
75 test_path_is_missing otherfile-4
78 test_expect_success
'am -3 --abort removes otherfile-4' '
79 git reset --hard initial &&
80 test_must_fail git am -3 0003-*.patch &&
81 test 3 -eq $(git ls-files -u | wc -l) &&
82 test 4 = "$(cat otherfile-4)" &&
84 test_cmp_rev initial HEAD &&
85 test -z "$(git ls-files -u)" &&
86 test_path_is_missing otherfile-4
89 test_expect_success
'am --abort will keep the local commits intact' '
90 test_must_fail git am 0004-*.patch &&
91 test_commit unrelated &&
92 git rev-parse HEAD >expect &&
94 git rev-parse HEAD >actual &&
95 test_cmp expect actual
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 &&
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 &&
108 test_cmp_rev initial HEAD &&
109 test_path_is_file dirtyfile &&
110 test_cmp dirtyfile.expected dirtyfile
113 test_expect_success
'am -3 stops on conflict on unborn branch' '
114 git checkout -f --orphan orphan &&
117 test_must_fail git am -3 0003-*.patch &&
118 test 2 -eq $(git ls-files -u | wc -l) &&
119 test 4 = "$(cat otherfile-4)"
122 test_expect_success
'am -3 --skip clears index on unborn branch' '
123 test_path_is_dir .git/rebase-apply &&
124 echo tmpfile >tmpfile &&
127 test -z "$(git ls-files)" &&
128 test_path_is_missing otherfile-4 &&
129 test_path_is_missing tmpfile
132 test_expect_success
'am -3 --abort removes otherfile-4 on unborn branch' '
133 git checkout -f --orphan orphan &&
135 rm -f otherfile-4 file-1 &&
136 test_must_fail git am -3 0003-*.patch &&
137 test 2 -eq $(git ls-files -u | wc -l) &&
138 test 4 = "$(cat otherfile-4)" &&
140 test -z "$(git ls-files -u)" &&
141 test_path_is_missing otherfile-4
144 test_expect_success
'am -3 --abort on unborn branch removes applied commits' '
145 git checkout -f --orphan orphan &&
147 rm -f otherfile-4 otherfile-2 file-1 file-2 &&
148 test_must_fail git am -3 initial.patch 0003-*.patch &&
149 test 3 -eq $(git ls-files -u | wc -l) &&
150 test 4 = "$(cat otherfile-4)" &&
152 test -z "$(git ls-files -u)" &&
153 test_path_is_missing otherfile-4 &&
154 test_path_is_missing file-1 &&
155 test_path_is_missing file-2 &&
156 test 0 -eq $(git log --oneline 2>/dev/null | wc -l) &&
157 test refs/heads/orphan = "$(git symbolic-ref HEAD)"
160 test_expect_success
'am --abort on unborn branch will keep local commits intact' '
161 git checkout -f --orphan orphan &&
163 test_must_fail git am 0004-*.patch &&
164 test_commit unrelated2 &&
165 git rev-parse HEAD >expect &&
167 git rev-parse HEAD >actual &&
168 test_cmp expect actual
171 test_expect_success
'am --skip leaves index stat info alone' '
172 git checkout -f --orphan skip-stat-info &&
174 test_commit skip-should-be-untouched &&
175 test-tool chmtime =0 skip-should-be-untouched.t &&
176 git update-index --refresh &&
177 git diff-files --exit-code --quiet &&
178 test_must_fail git am 0001-*.patch &&
180 git diff-files --exit-code --quiet
183 test_expect_success
'am --abort leaves index stat info alone' '
184 git checkout -f --orphan abort-stat-info &&
186 test_commit abort-should-be-untouched &&
187 test-tool chmtime =0 abort-should-be-untouched.t &&
188 git update-index --refresh &&
189 git diff-files --exit-code --quiet &&
190 test_must_fail git am 0001-*.patch &&
192 git diff-files --exit-code --quiet
195 test_expect_success
'git am --abort return failed exit status when it fails' '
196 test_when_finished "rm -rf file-2/ && git reset --hard && git am --abort" &&
197 git checkout changes &&
198 git format-patch -1 --stdout conflicting >changes.mbox &&
199 test_must_fail git am --3way changes.mbox &&
203 echo precious >file-2/somefile &&
204 test_must_fail git am --abort &&
205 test_path_is_dir file-2/
208 test_expect_success
'git am --abort cleans relevant files' '
209 git checkout changes &&
210 git format-patch -1 --stdout conflicting >changes.mbox &&
211 test_must_fail git am --3way changes.mbox &&
213 test_path_is_file new-file &&
214 echo further changes >>file-1 &&
215 echo change other file >>file-2 &&
217 # Abort, and expect the files touched by am to be reverted
220 test_path_is_missing new-file &&
222 # Files not involved in am operation are left modified
223 git diff --name-only changes >actual &&
224 test_write_lines file-2 >expect &&
225 test_cmp expect actual