mirror of
https://github.com/git/git.git
synced 2024-11-25 19:04:18 +08:00
c6587bddc4
Since shell loops may drop the exit code of failed commands inside the loop, some tests try to keep track of the status by setting a variable. This can end up cumbersome and hard to read; it is much simpler to just exit directly from the loop using "return 1" (since each case is either in a helper function or inside a test snippet). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
64 lines
1.5 KiB
Bash
Executable File
64 lines
1.5 KiB
Bash
Executable File
#!/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 &&
|
|
echo file-$num >>expected ||
|
|
return 1
|
|
done
|
|
done &&
|
|
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 .
|
|
'
|
|
|
|
test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
|
|
# 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
|
|
)
|
|
'
|
|
|
|
test_expect_success \
|
|
'git -ls-files --with-tree should add entries from named tree.' \
|
|
'test_cmp expected output'
|
|
|
|
test_done
|