mirror of
https://github.com/git/git.git
synced 2024-11-15 17:03:14 +01:00
9081a421a6
The "checkout" command is one of the main sources of leaks in the test suite, let's fix the common ones by not leaking from the "struct branch_info". Doing this is rather straightforward, albeit verbose, we need to xstrdup() constant strings going into the struct, and free() the ones we clobber as we go along. This also means that we can delete previous partial leak fixes in this area, i.e. the "path_to_free" accounting added by 96ec7b1e708 (Convert resolve_ref+xstrdup to new resolve_refdup function, 2011-12-13). There was some discussion about whether "we should retain the "const char *" here and cast at free() time, or have it be a "char *". Since this is not a public API with any sort of API boundary let's use "char *", as is already being done for the "refname" member of the same struct. The tests to mark as passing were found with: rm .prove; GIT_SKIP_TESTS=t0027 prove -j8 --state=save t[0-9]*.sh :: --immediate # apply & compile this change prove -j8 --state=failed :: --immediate I.e. the ones that were newly passing when the --state=failed command was run. I left out "t3040-subprojects-basic.sh" and "t4131-apply-fake-ancestor.sh" to to optimization-level related differences similar to the ones noted in[1], except that these would be something the current 'linux-leaks' job would run into. 1. https://lore.kernel.org/git/cover-v3-0.6-00000000000-20211022T175227Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
85 lines
2.3 KiB
Bash
Executable File
85 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='Basic subproject functionality'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup: create superproject' '
|
|
: >Makefile &&
|
|
git add Makefile &&
|
|
git commit -m "Superproject created"
|
|
'
|
|
|
|
test_expect_success 'setup: create subprojects' '
|
|
mkdir sub1 &&
|
|
( cd sub1 && git init && : >Makefile && git add * &&
|
|
git commit -q -m "subproject 1" ) &&
|
|
mkdir sub2 &&
|
|
( cd sub2 && git init && : >Makefile && git add * &&
|
|
git commit -q -m "subproject 2" ) &&
|
|
git update-index --add sub1 &&
|
|
git add sub2 &&
|
|
git commit -q -m "subprojects added" &&
|
|
GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
|
|
git branch save HEAD &&
|
|
cat >expected <<-\EOF &&
|
|
:000000 160000 00000... A sub1
|
|
:000000 160000 00000... A sub2
|
|
EOF
|
|
test_cmp expected current
|
|
'
|
|
|
|
test_expect_success 'check if fsck ignores the subprojects' '
|
|
git fsck --full
|
|
'
|
|
|
|
test_expect_success 'check if commit in a subproject detected' '
|
|
( cd sub1 &&
|
|
echo "all:" >>Makefile &&
|
|
echo " true" >>Makefile &&
|
|
git commit -q -a -m "make all" ) &&
|
|
test_expect_code 1 git diff-files --exit-code
|
|
'
|
|
|
|
test_expect_success 'check if a changed subproject HEAD can be committed' '
|
|
git commit -q -a -m "sub1 changed" &&
|
|
test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
|
|
'
|
|
|
|
test_expect_success 'check if diff-index works for subproject elements' '
|
|
test_expect_code 1 git diff-index --exit-code --cached save -- sub1
|
|
'
|
|
|
|
test_expect_success 'check if diff-tree works for subproject elements' '
|
|
test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- sub1
|
|
'
|
|
|
|
test_expect_success 'check if git diff works for subproject elements' '
|
|
test_expect_code 1 git diff --exit-code HEAD^ HEAD
|
|
'
|
|
|
|
test_expect_success 'check if clone works' '
|
|
git ls-files -s >expected &&
|
|
git clone -l -s . cloned &&
|
|
( cd cloned && git ls-files -s ) >current &&
|
|
test_cmp expected current
|
|
'
|
|
|
|
test_expect_success 'removing and adding subproject' '
|
|
git update-index --force-remove -- sub2 &&
|
|
mv sub2 sub3 &&
|
|
git add sub3 &&
|
|
git commit -q -m "renaming a subproject" &&
|
|
test_expect_code 1 git diff -M --name-status --exit-code HEAD^ HEAD
|
|
'
|
|
|
|
# the index must contain the object name the HEAD of the
|
|
# subproject sub1 was at the point "save"
|
|
test_expect_success 'checkout in superproject' '
|
|
git checkout save &&
|
|
git diff-index --exit-code --raw --cached save -- sub1
|
|
'
|
|
|
|
test_done
|