Skip to content

Commit b809c3d

Browse files
committed
Merge branch 'en/am-abort-fix' into maint
When "git am --abort" fails to abort correctly, it still exited with exit status of 0, which has been corrected. * en/am-abort-fix: am: fix incorrect exit status on am fail to abort t4151: add a few am --abort tests git-am.txt: clarify --abort behavior
2 parents b5f309d + c5ead19 commit b809c3d

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Documentation/git-am.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ default. You can use `--no-utf8` to override this.
178178

179179
--abort::
180180
Restore the original branch and abort the patching operation.
181+
Revert contents of files involved in the am operation to their
182+
pre-am state.
181183

182184
--quit::
183185
Abort the patching operation but keep HEAD and the index

builtin/am.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,8 @@ static void am_abort(struct am_state *state)
21062106
if (!has_orig_head)
21072107
oidcpy(&orig_head, the_hash_algo->empty_tree);
21082108

2109-
clean_index(&curr_head, &orig_head);
2109+
if (clean_index(&curr_head, &orig_head))
2110+
die(_("failed to clean index"));
21102111

21112112
if (has_orig_head)
21122113
update_ref("am --abort", "HEAD", &orig_head,

t/t4151-am-abort.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ test_expect_success setup '
2323
test_tick &&
2424
git commit -a -m $i || return 1
2525
done &&
26+
git branch changes &&
2627
git format-patch --no-numbered initial &&
28+
git checkout -b conflicting initial &&
29+
echo different >>file-1 &&
30+
echo whatever >new-file &&
31+
git add file-1 new-file &&
32+
git commit -m different &&
2733
git checkout -b side initial &&
2834
echo local change >file-2-expect
2935
'
@@ -191,4 +197,37 @@ test_expect_success 'am --abort leaves index stat info alone' '
191197
git diff-files --exit-code --quiet
192198
'
193199

200+
test_expect_success 'git am --abort return failed exit status when it fails' '
201+
test_when_finished "rm -rf file-2/ && git reset --hard && git am --abort" &&
202+
git checkout changes &&
203+
git format-patch -1 --stdout conflicting >changes.mbox &&
204+
test_must_fail git am --3way changes.mbox &&
205+
206+
git rm file-2 &&
207+
mkdir file-2 &&
208+
echo precious >file-2/somefile &&
209+
test_must_fail git am --abort &&
210+
test_path_is_dir file-2/
211+
'
212+
213+
test_expect_success 'git am --abort cleans relevant files' '
214+
git checkout changes &&
215+
git format-patch -1 --stdout conflicting >changes.mbox &&
216+
test_must_fail git am --3way changes.mbox &&
217+
218+
test_path_is_file new-file &&
219+
echo further changes >>file-1 &&
220+
echo change other file >>file-2 &&
221+
222+
# Abort, and expect the files touched by am to be reverted
223+
git am --abort &&
224+
225+
test_path_is_missing new-file &&
226+
227+
# Files not involved in am operation are left modified
228+
git diff --name-only changes >actual &&
229+
test_write_lines file-2 >expect &&
230+
test_cmp expect actual
231+
'
232+
194233
test_done

0 commit comments

Comments
 (0)