summaryrefslogtreecommitdiffstats
path: root/t/t4126-apply-empty.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:34:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:34:27 +0000
commit4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f (patch)
tree47c1d492e9c956c1cd2b74dbd3b9d8b0db44dc4e /t/t4126-apply-empty.sh
parentInitial commit. (diff)
downloadgit-4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f.tar.xz
git-4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f.zip
Adding upstream version 1:2.43.0.upstream/1%2.43.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 't/t4126-apply-empty.sh')
-rwxr-xr-xt/t4126-apply-empty.sh69
1 files changed, 69 insertions, 0 deletions
diff --git a/t/t4126-apply-empty.sh b/t/t4126-apply-empty.sh
new file mode 100755
index 0000000..ece9fae
--- /dev/null
+++ b/t/t4126-apply-empty.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+test_description='apply empty'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+test_expect_success setup '
+ >empty &&
+ git add empty &&
+ test_tick &&
+ git commit -m initial &&
+ git commit --allow-empty -m "empty commit" &&
+ git format-patch --always HEAD~ >empty.patch &&
+ test_write_lines a b c d e >empty &&
+ cat empty >expect &&
+ git diff |
+ sed -e "/^diff --git/d" \
+ -e "/^index /d" \
+ -e "s|a/empty|empty.orig|" \
+ -e "s|b/empty|empty|" >patch0 &&
+ sed -e "s|empty|missing|" patch0 >patch1 &&
+ >empty &&
+ git update-index --refresh
+'
+
+test_expect_success 'apply empty' '
+ rm -f missing &&
+ test_when_finished "git reset --hard" &&
+ git apply patch0 &&
+ test_cmp expect empty
+'
+
+test_expect_success 'apply empty patch fails' '
+ test_when_finished "git reset --hard" &&
+ test_must_fail git apply empty.patch &&
+ test_must_fail git apply - </dev/null
+'
+
+test_expect_success 'apply with --allow-empty succeeds' '
+ test_when_finished "git reset --hard" &&
+ git apply --allow-empty empty.patch &&
+ git apply --allow-empty - </dev/null
+'
+
+test_expect_success 'apply --index empty' '
+ rm -f missing &&
+ test_when_finished "git reset --hard" &&
+ git apply --index patch0 &&
+ test_cmp expect empty &&
+ git diff --exit-code
+'
+
+test_expect_success 'apply create' '
+ rm -f missing &&
+ test_when_finished "git reset --hard" &&
+ git apply patch1 &&
+ test_cmp expect missing
+'
+
+test_expect_success 'apply --index create' '
+ rm -f missing &&
+ test_when_finished "git reset --hard" &&
+ git apply --index patch1 &&
+ test_cmp expect missing &&
+ git diff --exit-code
+'
+
+test_done