diff options
Diffstat (limited to 't/t4150-am.sh')
-rwxr-xr-x | t/t4150-am.sh | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 2aaaa0d7de..6caff0ca39 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -116,7 +116,7 @@ test_expect_success setup ' git format-patch --stdout first | sed -e "1d" } | append_cr >patch1-crlf.eml && { - printf "%255s\\n" "" + printf "%255s\\n" "" && echo "X-Fake-Field: Line One" && echo "X-Fake-Field: Line Two" && echo "X-Fake-Field: Line Three" && @@ -196,6 +196,12 @@ test_expect_success setup ' git format-patch -M --stdout lorem^ >rename-add.patch && + git checkout -b empty-commit && + git commit -m "empty commit" --allow-empty && + + : >empty.patch && + git format-patch --always --stdout empty-commit^ >empty-commit.patch && + # reset time sane_unset test_tick && test_tick @@ -1152,4 +1158,105 @@ test_expect_success 'apply binary blob in partial clone' ' git -C client am ../patch ' +test_expect_success 'an empty input file is error regardless of --empty option' ' + test_when_finished "git am --abort || :" && + test_must_fail git am --empty=drop empty.patch 2>actual && + echo "Patch format detection failed." >expected && + test_cmp expected actual +' + +test_expect_success 'invalid when passing the --empty option alone' ' + test_when_finished "git am --abort || :" && + git checkout empty-commit^ && + test_must_fail git am --empty empty-commit.patch 2>err && + echo "error: Invalid value for --empty: empty-commit.patch" >expected && + test_cmp expected err +' + +test_expect_success 'a message without a patch is an error (default)' ' + test_when_finished "git am --abort || :" && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty" err +' + +test_expect_success 'a message without a patch is an error where an explicit "--empty=stop" is given' ' + test_when_finished "git am --abort || :" && + test_must_fail git am --empty=stop empty-commit.patch >err && + grep "Patch is empty." err +' + +test_expect_success 'a message without a patch will be skipped when "--empty=drop" is given' ' + git am --empty=drop empty-commit.patch >output && + git rev-parse empty-commit^ >expected && + git rev-parse HEAD >actual && + test_cmp expected actual && + grep "Skipping: empty commit" output +' + +test_expect_success 'record as an empty commit when meeting e-mail message that lacks a patch' ' + git am --empty=keep empty-commit.patch >output && + test_path_is_missing .git/rebase-apply && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected && + grep "Creating an empty commit: empty commit" output +' + +test_expect_success 'skip an empty patch in the middle of an am session' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty." err && + grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git am --skip && + test_path_is_missing .git/rebase-apply && + git rev-parse empty-commit^ >expected && + git rev-parse HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'record an empty patch as an empty commit in the middle of an am session' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty." err && + grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git am --allow-empty >output && + grep "No changes - recorded it as an empty commit." output && + test_path_is_missing .git/rebase-apply && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected +' + +test_expect_success 'create an non-empty commit when the index IS changed though "--allow-empty" is given' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + : >empty-file && + git add empty-file && + git am --allow-empty && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected && + git diff HEAD^..HEAD --name-only +' + +test_expect_success 'cannot create empty commits when there is a clean index due to merge conflicts' ' + test_when_finished "git am --abort || :" && + git rev-parse HEAD >expected && + test_must_fail git am seq.patch && + test_must_fail git am --allow-empty >err && + ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git rev-parse HEAD >actual && + test_cmp actual expected +' + +test_expect_success 'cannot create empty commits when there is unmerged index due to merge conflicts' ' + test_when_finished "git am --abort || :" && + git rev-parse HEAD >expected && + test_must_fail git am -3 seq.patch && + test_must_fail git am --allow-empty >err && + ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git rev-parse HEAD >actual && + test_cmp actual expected +' + test_done |