1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-18 21:46:26 +02:00
git/t/t7106-reset-unborn-branch.sh
Ævar Arnfjörð Bjarmason 7615cf94d2 various: add missing clear_pathspec(), fix leaks
Fix memory leaks resulting from a missing clear_pathspec().

- archive.c: Plug a leak in the "struct archiver_args", and
  clear_pathspec() the "pathspec" member that the "parse_pathspec_arg()"
  call in this function populates.

- builtin/clean.c: Fix a memory leak that's been with us since
  893d839970 (clean: convert to use parse_pathspec, 2013-07-14).

- builtin/reset.c: Add clear_pathspec() calls to cmd_reset(),
  including to the codepaths where we'd return early.

- builtin/stash.c: Call clear_pathspec() on the pathspec initialized
  in push_stash().

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-06 15:34:37 -08:00

70 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
test_description='git reset should work on unborn branch'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
echo a >a &&
echo b >b
'
test_expect_success 'reset' '
git add a b &&
git reset &&
git ls-files >actual &&
test_must_be_empty actual
'
test_expect_success 'reset HEAD' '
rm .git/index &&
git add a b &&
test_must_fail git reset HEAD
'
test_expect_success 'reset $file' '
rm .git/index &&
git add a b &&
git reset a &&
echo b >expect &&
git ls-files >actual &&
test_cmp expect actual
'
test_expect_success PERL 'reset -p' '
rm .git/index &&
git add a &&
echo y >yes &&
git reset -p <yes >output &&
git ls-files >actual &&
test_must_be_empty actual &&
test_i18ngrep "Unstage" output
'
test_expect_success 'reset --soft is a no-op' '
rm .git/index &&
git add a &&
git reset --soft &&
echo a >expect &&
git ls-files >actual &&
test_cmp expect actual
'
test_expect_success 'reset --hard' '
rm .git/index &&
git add a &&
test_when_finished "echo a >a" &&
git reset --hard &&
git ls-files >actual &&
test_must_be_empty actual &&
test_path_is_missing a
'
test_done