2007-10-03 07:03:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Carl D. Worth
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='git ls-files test (--with-tree).
|
|
|
|
|
|
|
|
This test runs git ls-files --with-tree and in particular in
|
|
|
|
a scenario known to trigger a crash with some versions of git.
|
|
|
|
'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
# The bug we are exercising requires a fair number of entries
|
|
|
|
# in a sub-directory so that add_index_entry will trigger a
|
|
|
|
# realloc.
|
|
|
|
|
|
|
|
echo file >expected &&
|
|
|
|
mkdir sub &&
|
|
|
|
for n in 0 1 2 3 4 5
|
|
|
|
do
|
|
|
|
for m in 0 1 2 3 4 5 6 7 8 9
|
|
|
|
do
|
|
|
|
num=00$n$m &&
|
|
|
|
>sub/file-$num &&
|
2015-03-25 05:30:17 +00:00
|
|
|
echo file-$num >>expected ||
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
done &&
|
2007-10-03 07:03:53 +00:00
|
|
|
git add . &&
|
|
|
|
git commit -m "add a bunch of files" &&
|
|
|
|
|
|
|
|
# We remove them all so that we will have something to add
|
|
|
|
# back with --with-tree and so that we will definitely be
|
|
|
|
# under the realloc size to trigger the bug.
|
|
|
|
rm -rf sub &&
|
|
|
|
git commit -a -m "remove them all" &&
|
|
|
|
|
|
|
|
# The bug also requires some entry before our directory so that
|
|
|
|
# prune_path will modify the_index.cache
|
|
|
|
|
|
|
|
mkdir a_directory_that_sorts_before_sub &&
|
|
|
|
>a_directory_that_sorts_before_sub/file &&
|
|
|
|
mkdir sub &&
|
|
|
|
>sub/file &&
|
|
|
|
git add .
|
|
|
|
'
|
|
|
|
|
2021-03-20 22:37:45 +00:00
|
|
|
test_expect_success 'usage' '
|
|
|
|
test_expect_code 128 git ls-files --with-tree=HEAD -u &&
|
|
|
|
test_expect_code 128 git ls-files --with-tree=HEAD -s &&
|
|
|
|
test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD
|
|
|
|
'
|
|
|
|
|
2019-11-06 04:18:09 +00:00
|
|
|
test_expect_success 'git ls-files --with-tree should succeed from subdir' '
|
2010-09-07 01:42:54 +00:00
|
|
|
# We have to run from a sub-directory to trigger prune_path
|
|
|
|
# Then we finally get to run our --with-tree test
|
|
|
|
(
|
|
|
|
cd sub &&
|
|
|
|
git ls-files --with-tree=HEAD~1 >../output
|
|
|
|
)
|
2007-10-03 07:03:53 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success \
|
2019-11-06 04:18:09 +00:00
|
|
|
'git ls-files --with-tree should add entries from named tree.' \
|
2008-03-12 21:36:36 +00:00
|
|
|
'test_cmp expected output'
|
2007-10-03 07:03:53 +00:00
|
|
|
|
2021-03-20 22:37:45 +00:00
|
|
|
test_expect_success 'no duplicates in --with-tree output' '
|
|
|
|
git ls-files --with-tree=HEAD >actual &&
|
|
|
|
sort -u actual >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup: output in a conflict' '
|
|
|
|
test_create_repo conflict &&
|
|
|
|
test_commit -C conflict BASE file &&
|
|
|
|
test_commit -C conflict A file foo &&
|
|
|
|
git -C conflict reset --hard BASE &&
|
|
|
|
test_commit -C conflict B file bar
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'output in a conflict' '
|
|
|
|
test_must_fail git -C conflict merge A B &&
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
file
|
|
|
|
file
|
|
|
|
file
|
|
|
|
file
|
|
|
|
EOF
|
|
|
|
git -C conflict ls-files --with-tree=HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'output with removed .git/index' '
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
file
|
|
|
|
EOF
|
|
|
|
rm conflict/.git/index &&
|
|
|
|
git -C conflict ls-files --with-tree=HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2007-10-03 07:03:53 +00:00
|
|
|
test_done
|