2009-08-20 15:46:58 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008 Nguyễn Thái Ngọc Duy
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='skip-worktree bit test'
|
|
|
|
|
commit: fix "author_ident" leak
Since 4c28e4ada03 (commit: die before asking to edit the log
message, 2010-12-20), we have been "leaking" the "author_ident" when
prepare_to_commit() fails. Instead of returning from right there,
introduce an exit status variable and jump to the clean-up label
at the end.
Instead of explicitly releasing the resource with strbuf_release(),
mark the variable with UNLEAK() at the end, together with two other
variables that are already marked as such. If this were in a
utility function that is called number of times, but these are
different, we should explicitly release resources that grow
proportionally to the size of the problem being solved, but
cmd_commit() is like main() and there is no point in spending extra
cycles to release individual pieces of resource at the end, just
before process exit will clean everything for us for free anyway.
This fixes a leak demonstrated by e.g. "t3505-cherry-pick-empty.sh",
but unfortunately we cannot mark it or other affected tests as passing
now with "TEST_PASSES_SANITIZE_LEAK=true" as we'll need to fix many
other memory leaks before doing so.
Incidentally there are two tests that always passes the leak checker
with or without this change. Mark them as such.
This is based on an earlier patch by Ævar, but takes a different
approach that is more maintainable.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-05-13 00:51:07 +02:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2009-08-20 15:46:58 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
cat >expect.full <<EOF
|
|
|
|
H 1
|
|
|
|
H 2
|
|
|
|
H init.t
|
|
|
|
H sub/1
|
|
|
|
H sub/2
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >expect.skip <<EOF
|
|
|
|
S 1
|
|
|
|
H 2
|
|
|
|
H init.t
|
|
|
|
S sub/1
|
|
|
|
H sub/2
|
|
|
|
EOF
|
|
|
|
|
|
|
|
setup_absent() {
|
|
|
|
test -f 1 && rm 1
|
|
|
|
git update-index --remove 1 &&
|
2016-07-16 07:06:25 +02:00
|
|
|
git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
|
2009-08-20 15:46:58 +02:00
|
|
|
git update-index --skip-worktree 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_absent() {
|
2016-07-16 07:06:25 +02:00
|
|
|
echo "100644 $EMPTY_BLOB 0 1" > expected &&
|
2009-08-20 15:46:58 +02:00
|
|
|
git ls-files --stage 1 > result &&
|
|
|
|
test_cmp expected result &&
|
|
|
|
test ! -f 1
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_dirty() {
|
|
|
|
git update-index --force-remove 1 &&
|
|
|
|
echo dirty > 1 &&
|
2016-07-16 07:06:25 +02:00
|
|
|
git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
|
2009-08-20 15:46:58 +02:00
|
|
|
git update-index --skip-worktree 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_dirty() {
|
2016-07-16 07:06:25 +02:00
|
|
|
echo "100644 $EMPTY_BLOB 0 1" > expected &&
|
2009-08-20 15:46:58 +02:00
|
|
|
git ls-files --stage 1 > result &&
|
|
|
|
test_cmp expected result &&
|
|
|
|
echo dirty > expected
|
|
|
|
test_cmp expected 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit init &&
|
|
|
|
mkdir sub &&
|
|
|
|
touch ./1 ./2 sub/1 sub/2 &&
|
|
|
|
git add 1 2 sub/1 sub/2 &&
|
|
|
|
git update-index --skip-worktree 1 sub/1 &&
|
|
|
|
git ls-files -t > result &&
|
|
|
|
test_cmp expect.skip result
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update-index' '
|
|
|
|
setup_absent &&
|
|
|
|
git update-index 1 &&
|
|
|
|
test_absent
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update-index' '
|
|
|
|
setup_dirty &&
|
|
|
|
git update-index 1 &&
|
|
|
|
test_dirty
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update-index --remove' '
|
|
|
|
setup_absent &&
|
|
|
|
git update-index --remove 1 &&
|
|
|
|
test -z "$(git ls-files 1)" &&
|
|
|
|
test ! -f 1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update-index --remove' '
|
|
|
|
setup_dirty &&
|
|
|
|
git update-index --remove 1 &&
|
|
|
|
test -z "$(git ls-files 1)" &&
|
|
|
|
echo dirty > expected &&
|
|
|
|
test_cmp expected 1
|
|
|
|
'
|
|
|
|
|
2013-06-30 12:45:25 +02:00
|
|
|
test_expect_success 'ls-files --deleted' '
|
2009-08-20 15:46:58 +02:00
|
|
|
setup_absent &&
|
|
|
|
test -z "$(git ls-files -d)"
|
|
|
|
'
|
|
|
|
|
2013-06-30 12:45:25 +02:00
|
|
|
test_expect_success 'ls-files --deleted' '
|
2009-08-20 15:46:58 +02:00
|
|
|
setup_dirty &&
|
|
|
|
test -z "$(git ls-files -d)"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ls-files --modified' '
|
|
|
|
setup_absent &&
|
|
|
|
test -z "$(git ls-files -m)"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ls-files --modified' '
|
|
|
|
setup_dirty &&
|
|
|
|
test -z "$(git ls-files -m)"
|
|
|
|
'
|
|
|
|
|
2018-05-13 04:24:13 +02:00
|
|
|
echo ":000000 100644 $ZERO_OID $EMPTY_BLOB A 1" > expected
|
2009-08-20 15:46:58 +02:00
|
|
|
test_expect_success 'diff-index does not examine skip-worktree absent entries' '
|
|
|
|
setup_absent &&
|
|
|
|
git diff-index HEAD -- 1 > result &&
|
|
|
|
test_cmp expected result
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff-index does not examine skip-worktree dirty entries' '
|
|
|
|
setup_dirty &&
|
|
|
|
git diff-index HEAD -- 1 > result &&
|
|
|
|
test_cmp expected result
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff-files does not examine skip-worktree absent entries' '
|
|
|
|
setup_absent &&
|
|
|
|
test -z "$(git diff-files -- one)"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff-files does not examine skip-worktree dirty entries' '
|
|
|
|
setup_dirty &&
|
|
|
|
test -z "$(git diff-files -- one)"
|
|
|
|
'
|
|
|
|
|
2009-12-14 12:43:59 +01:00
|
|
|
test_expect_success 'commit on skip-worktree absent entries' '
|
2009-08-20 15:46:58 +02:00
|
|
|
git reset &&
|
|
|
|
setup_absent &&
|
|
|
|
test_must_fail git commit -m null 1
|
|
|
|
'
|
|
|
|
|
2009-12-14 12:43:59 +01:00
|
|
|
test_expect_success 'commit on skip-worktree dirty entries' '
|
2009-08-20 15:46:58 +02:00
|
|
|
git reset &&
|
|
|
|
setup_dirty &&
|
|
|
|
test_must_fail git commit -m null 1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|