summaryrefslogtreecommitdiff
path: root/t/t4150-am.sh
diff options
context:
space:
mode:
author徐沛文 (Aleen) <aleen42@vip.qq.com>2021-12-09 07:25:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-12-16 01:04:19 (GMT)
commit9e7e41bf19ed10469f9adb60669b1699c81b8ea6 (patch)
tree38c8ff55fb6b3b4280b09c6b87dcbdfa96da0d3a /t/t4150-am.sh
parent7c096b8d61e1276acb6f84bf446cfe74578382a0 (diff)
downloadgit-9e7e41bf19ed10469f9adb60669b1699c81b8ea6.zip
git-9e7e41bf19ed10469f9adb60669b1699c81b8ea6.tar.gz
git-9e7e41bf19ed10469f9adb60669b1699c81b8ea6.tar.bz2
am: support --allow-empty to record specific empty patches
This option helps to record specific empty patches in the middle of an am session, which does create empty commits only when: 1. the index has not changed 2. lacking a branch When the index has changed, "--allow-empty" will create a non-empty commit like passing "--continue" or "--resolved". Signed-off-by: 徐沛文 (Aleen) <aleen42@vip.qq.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4150-am.sh')
-rwxr-xr-xt/t4150-am.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index f2a7a68..2db2c5d 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -1202,4 +1202,61 @@ test_expect_success 'record as an empty commit when meeting e-mail message that
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