1
0
mirror of https://github.com/git/git.git synced 2024-11-15 17:03:14 +01:00
git/t/t3009-ls-files-others-nonsubmodule.sh
Ævar Arnfjörð Bjarmason 03267e8656 commit: discard partial cache before (re-)reading it
The read_cache() in prepare_to_commit() would end up clobbering the
pointer we had for a previously populated "the_index.cache_tree" in
the very common case of "git commit" stressed by e.g. the tests being
changed here.

We'd populate "the_index.cache_tree" by calling
"update_main_cache_tree" in prepare_index(), but would not end up with
a "fully prepared" index. What constitutes an existing index is
clearly overly fuzzy, here we'll check "active_nr" (aka
"the_index.cache_nr"), but our "the_index.cache_tree" might have been
malloc()'d already.

Thus the code added in 11c8a74a64a (commit: write cache-tree data when
writing index anyway, 2011-12-06) would end up allocating the
"cache_tree", and would interact here with code added in
7168624c353 (Do not generate full commit log message if it is not
going to be used, 2007-11-28). The result was a very common memory
leak.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-21 12:32:48 +09:00

52 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
test_description='test git ls-files --others with non-submodule repositories
This test runs git ls-files --others with the following working tree:
nonrepo-no-files/
plain directory with no files
nonrepo-untracked-file/
plain directory with an untracked file
repo-no-commit-no-files/
git repository without a commit or a file
repo-no-commit-untracked-file/
git repository without a commit but with an untracked file
repo-with-commit-no-files/
git repository with a commit and no untracked files
repo-with-commit-untracked-file/
git repository with a commit and an untracked file
'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup: directories' '
mkdir nonrepo-no-files/ &&
mkdir nonrepo-untracked-file &&
: >nonrepo-untracked-file/untracked &&
git init repo-no-commit-no-files &&
git init repo-no-commit-untracked-file &&
: >repo-no-commit-untracked-file/untracked &&
git init repo-with-commit-no-files &&
git -C repo-with-commit-no-files commit --allow-empty -mmsg &&
git init repo-with-commit-untracked-file &&
test_commit -C repo-with-commit-untracked-file msg &&
: >repo-with-commit-untracked-file/untracked
'
test_expect_success 'ls-files --others handles untracked git repositories' '
git ls-files -o >output &&
cat >expect <<-EOF &&
nonrepo-untracked-file/untracked
output
repo-no-commit-no-files/
repo-no-commit-untracked-file/
repo-with-commit-no-files/
repo-with-commit-untracked-file/
EOF
test_cmp expect output
'
test_done