2008-05-17 11:02:44 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='apply empty'
|
|
|
|
|
2022-04-13 22:01:51 +02:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2008-05-17 11:02:44 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
>empty &&
|
|
|
|
git add empty &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m initial &&
|
2021-12-13 23:03:27 +01:00
|
|
|
git commit --allow-empty -m "empty commit" &&
|
|
|
|
git format-patch --always HEAD~ >empty.patch &&
|
2021-12-09 06:11:05 +01:00
|
|
|
test_write_lines a b c d e >empty &&
|
2008-05-17 11:02:44 +02:00
|
|
|
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 &&
|
2021-12-13 23:03:27 +01:00
|
|
|
test_when_finished "git reset --hard" &&
|
2008-05-17 11:02:44 +02:00
|
|
|
git apply patch0 &&
|
|
|
|
test_cmp expect empty
|
|
|
|
'
|
|
|
|
|
2021-12-13 23:03:27 +01:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2008-05-17 11:02:44 +02:00
|
|
|
test_expect_success 'apply --index empty' '
|
|
|
|
rm -f missing &&
|
2021-12-13 23:03:27 +01:00
|
|
|
test_when_finished "git reset --hard" &&
|
2008-05-17 11:02:44 +02:00
|
|
|
git apply --index patch0 &&
|
|
|
|
test_cmp expect empty &&
|
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply create' '
|
|
|
|
rm -f missing &&
|
2021-12-13 23:03:27 +01:00
|
|
|
test_when_finished "git reset --hard" &&
|
2008-05-17 11:02:44 +02:00
|
|
|
git apply patch1 &&
|
|
|
|
test_cmp expect missing
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply --index create' '
|
|
|
|
rm -f missing &&
|
2021-12-13 23:03:27 +01:00
|
|
|
test_when_finished "git reset --hard" &&
|
2008-05-17 11:02:44 +02:00
|
|
|
git apply --index patch1 &&
|
|
|
|
test_cmp expect missing &&
|
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|