Skip to content

Commit

Permalink
Merge branch 'rr/am-quit-empty-then-abort-fix'
Browse files Browse the repository at this point in the history
Recent "rebase --autostash" update made it impossible to recover
with "git am --abort" from a repository where "git am" without mbox
was run by mistake and then was killed with "^C".

* rr/am-quit-empty-then-abort-fix:
  t/am: use test_path_is_missing() where appropriate
  am: handle stray $dotest directory
  • Loading branch information
Junio C Hamano committed Jun 24, 2013
2 parents 001d116 + 61e0eb9 commit 76689ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
17 changes: 17 additions & 0 deletions git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,23 @@ then
esac
rm -f "$dotest/dirtyindex"
else
# Possible stray $dotest directory in the independent-run
# case; in the --rebasing case, it is upto the caller
# (git-rebase--am) to take care of stray directories.
if test -d "$dotest" && test -z "$rebasing"
then
case "$skip,$resolved,$abort" in
,,t)
rm -fr "$dotest"
exit 0
;;
*)
die "$(eval_gettext "Stray \$dotest directory found.
Use \"git am --abort\" to remove it.")"
;;
esac
fi

# Make sure we are not given --skip, --resolved, nor --abort
test "$skip$resolved$abort" = "" ||
die "$(gettext "Resolve operation not in progress, we are not resuming.")"
Expand Down
40 changes: 23 additions & 17 deletions t/t4150-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ test_expect_success 'am applies patch correctly' '
git checkout first &&
test_tick &&
git am <patch1 &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
Expand All @@ -158,7 +158,7 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
git reset --hard &&
git checkout first &&
git am patch1.eml &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
Expand All @@ -169,7 +169,7 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
git reset --hard &&
git checkout first &&
git am patch1-crlf.eml &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
Expand All @@ -180,7 +180,7 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '
git reset --hard &&
git checkout first &&
git am patch1-ws.eml &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
Expand All @@ -206,7 +206,7 @@ test_expect_success 'am changes committer and keeps author' '
git reset --hard &&
git checkout first &&
git am patch2 &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
git diff --exit-code master..HEAD &&
git diff --exit-code master^..HEAD^ &&
Expand Down Expand Up @@ -258,7 +258,7 @@ test_expect_success 'am --keep really keeps the subject' '
git reset --hard &&
git checkout HEAD^ &&
git am --keep patch4 &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git cat-file commit HEAD >actual &&
grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
'
Expand All @@ -268,7 +268,7 @@ test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
git reset --hard &&
git checkout HEAD^ &&
git am --keep-non-patch patch4 &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git cat-file commit HEAD >actual &&
grep "^\[foo\] third" actual
'
Expand All @@ -283,7 +283,7 @@ test_expect_success 'am -3 falls back to 3-way merge' '
test_tick &&
git commit -m "copied stuff" &&
git am -3 lorem-move.patch &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code lorem
'

Expand All @@ -297,7 +297,7 @@ test_expect_success 'am -3 -p0 can read --no-prefix patch' '
test_tick &&
git commit -m "copied stuff" &&
git am -3 -p0 lorem-zero.patch &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code lorem
'

Expand All @@ -307,7 +307,7 @@ test_expect_success 'am can rename a file' '
git reset --hard &&
git checkout lorem^0 &&
git am rename.patch &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
'
Expand All @@ -318,7 +318,7 @@ test_expect_success 'am -3 can rename a file' '
git reset --hard &&
git checkout lorem^0 &&
git am -3 rename.patch &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
'
Expand All @@ -329,7 +329,7 @@ test_expect_success 'am -3 can rename a file after falling back to 3-way merge'
git reset --hard &&
git checkout lorem^0 &&
git am -3 rename-add.patch &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
'
Expand Down Expand Up @@ -358,11 +358,17 @@ test_expect_success 'am pauses on conflict' '
test_expect_success 'am --skip works' '
echo goodbye >expected &&
git am --skip &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code lorem2^^ -- file &&
test_cmp expected another
'

test_expect_success 'am --abort removes a stray directory' '
mkdir .git/rebase-apply &&
git am --abort &&
test_path_is_missing .git/rebase-apply
'

test_expect_success 'am --resolved works' '
echo goodbye >expected &&
rm -fr .git/rebase-apply &&
Expand All @@ -373,7 +379,7 @@ test_expect_success 'am --resolved works' '
echo resolved >>file &&
git add file &&
git am --resolved &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
test_cmp expected another
'

Expand All @@ -382,7 +388,7 @@ test_expect_success 'am takes patches from a Pine mailbox' '
git reset --hard &&
git checkout first &&
cat pine patch1 | git am &&
! test -d .git/rebase-apply &&
test_path_is_missing .git/rebase-apply &&
git diff --exit-code master^..HEAD
'

Expand All @@ -391,7 +397,7 @@ test_expect_success 'am fails on mail without patch' '
git reset --hard &&
test_must_fail git am <failmail &&
git am --abort &&
! test -d .git/rebase-apply
test_path_is_missing .git/rebase-apply
'

test_expect_success 'am fails on empty patch' '
Expand All @@ -400,7 +406,7 @@ test_expect_success 'am fails on empty patch' '
echo "---" >>failmail &&
test_must_fail git am <failmail &&
git am --skip &&
! test -d .git/rebase-apply
test_path_is_missing .git/rebase-apply
'

test_expect_success 'am works from stdin in subdirectory' '
Expand Down

0 comments on commit 76689ab

Please sign in to comment.