1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-20 02:56:12 +02:00
git/t/t4252-am-options.sh
Rubén Justo 71c7916053 apply: plug a leak in apply_data
We have an execution path in apply_data that leaks the local struct
image.  Plug it.

This leak can be triggered with:

    $ echo foo >file
    $ git add file && git commit -m file
    $ echo bar >file
    $ git diff file >diff
    $ sed s/foo/frotz/ <diff >baddiff
    $ git apply --cached <baddiff

Fixing this leak allows us to mark as leak-free the following tests:

    + t2016-checkout-patch.sh
    + t4103-apply-binary.sh
    + t4104-apply-boundary.sh
    + t4113-apply-ending.sh
    + t4117-apply-reject.sh
    + t4123-apply-shrink.sh
    + t4252-am-options.sh
    + t4258-am-quoted-cr.sh

Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix
promply any new leak that may be introduced and triggered by them in the
future.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-04-22 16:27:42 -07:00

81 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
test_description='git am with options and not losing them'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
tm="$TEST_DIRECTORY/t4252"
test_expect_success setup '
cp "$tm/file-1-0" file-1 &&
cp "$tm/file-2-0" file-2 &&
git add file-1 file-2 &&
test_tick &&
git commit -m initial &&
git tag initial
'
test_expect_success 'interrupted am --whitespace=fix' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am --whitespace=fix "$tm"/am-test-1-? &&
git am --skip &&
grep 3 file-1 &&
grep "^Six$" file-2
'
test_expect_success 'interrupted am -C1' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am -C1 "$tm"/am-test-2-? &&
git am --skip &&
grep 3 file-1 &&
grep "^Three$" file-2
'
test_expect_success 'interrupted am -p2' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am -p2 "$tm"/am-test-3-? &&
git am --skip &&
grep 3 file-1 &&
grep "^Three$" file-2
'
test_expect_success 'interrupted am -C1 -p2' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am -p2 -C1 "$tm"/am-test-4-? &&
git am --skip &&
grep 3 file-1 &&
grep "^Three$" file-2
'
test_expect_success 'interrupted am --directory="frotz nitfol"' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am --directory="frotz nitfol" "$tm"/am-test-5-? &&
git am --skip &&
grep One "frotz nitfol/file-5"
'
test_expect_success 'apply to a funny path' '
with_sq="with'\''sq" &&
rm -fr .git/rebase-apply &&
git reset --hard initial &&
git am --directory="$with_sq" "$tm"/am-test-5-2 &&
test -f "$with_sq/file-5"
'
test_expect_success 'am --reject' '
rm -rf .git/rebase-apply &&
git reset --hard initial &&
test_must_fail git am --reject "$tm"/am-test-6-1 &&
grep "@@ -1,3 +1,3 @@" file-2.rej &&
test_must_fail git diff-files --exit-code --quiet file-2 &&
grep "[-]-reject" .git/rebase-apply/apply-opt
'
test_done