Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Carl D. Worth |
| 4 | # |
| 5 | |
| 6 | test_description='git ls-files test (--with-tree). |
| 7 | |
| 8 | This test runs git ls-files --with-tree and in particular in |
| 9 | a scenario known to trigger a crash with some versions of git. |
| 10 | ' |
Ævar Arnfjörð Bjarmason | c07ce06 | 2022-11-08 19:17:45 +0100 | [diff] [blame] | 11 | |
| 12 | TEST_PASSES_SANITIZE_LEAK=true |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 13 | . ./test-lib.sh |
| 14 | |
Li Linchao | 18337d4 | 2022-07-03 15:49:09 +0000 | [diff] [blame] | 15 | test_expect_success 'setup' ' |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 16 | |
| 17 | # The bug we are exercising requires a fair number of entries |
| 18 | # in a sub-directory so that add_index_entry will trigger a |
| 19 | # realloc. |
| 20 | |
| 21 | echo file >expected && |
| 22 | mkdir sub && |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 23 | for n in 0 1 2 3 4 5 |
| 24 | do |
| 25 | for m in 0 1 2 3 4 5 6 7 8 9 |
| 26 | do |
| 27 | num=00$n$m && |
| 28 | >sub/file-$num && |
Jeff King | c6587bd | 2015-03-25 01:30:17 -0400 | [diff] [blame] | 29 | echo file-$num >>expected || |
| 30 | return 1 |
| 31 | done |
| 32 | done && |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 33 | git add . && |
| 34 | git commit -m "add a bunch of files" && |
| 35 | |
| 36 | # We remove them all so that we will have something to add |
| 37 | # back with --with-tree and so that we will definitely be |
| 38 | # under the realloc size to trigger the bug. |
| 39 | rm -rf sub && |
| 40 | git commit -a -m "remove them all" && |
| 41 | |
| 42 | # The bug also requires some entry before our directory so that |
Andrei Rybak | 993d708 | 2023-03-31 16:36:03 +0200 | [diff] [blame] | 43 | # prune_index will modify the_repository->index.cache |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 44 | |
| 45 | mkdir a_directory_that_sorts_before_sub && |
| 46 | >a_directory_that_sorts_before_sub/file && |
| 47 | mkdir sub && |
| 48 | >sub/file && |
| 49 | git add . |
| 50 | ' |
| 51 | |
Ævar Arnfjörð Bjarmason | 8de7821 | 2021-03-20 23:37:45 +0100 | [diff] [blame] | 52 | test_expect_success 'usage' ' |
| 53 | test_expect_code 128 git ls-files --with-tree=HEAD -u && |
| 54 | test_expect_code 128 git ls-files --with-tree=HEAD -s && |
| 55 | test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD |
| 56 | ' |
| 57 | |
Nathan Stocks | 14c4776 | 2019-11-06 04:18:09 +0000 | [diff] [blame] | 58 | test_expect_success 'git ls-files --with-tree should succeed from subdir' ' |
Andrei Rybak | 993d708 | 2023-03-31 16:36:03 +0200 | [diff] [blame] | 59 | # We have to run from a sub-directory to trigger prune_index |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 60 | # Then we finally get to run our --with-tree test |
| 61 | ( |
| 62 | cd sub && |
| 63 | git ls-files --with-tree=HEAD~1 >../output |
| 64 | ) |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 65 | ' |
| 66 | |
Li Linchao | 18337d4 | 2022-07-03 15:49:09 +0000 | [diff] [blame] | 67 | test_expect_success 'git ls-files --with-tree should add entries from named tree.' ' |
| 68 | test_cmp expected output |
| 69 | ' |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 70 | |
Ævar Arnfjörð Bjarmason | 8de7821 | 2021-03-20 23:37:45 +0100 | [diff] [blame] | 71 | test_expect_success 'no duplicates in --with-tree output' ' |
| 72 | git ls-files --with-tree=HEAD >actual && |
| 73 | sort -u actual >expected && |
| 74 | test_cmp expected actual |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'setup: output in a conflict' ' |
| 78 | test_create_repo conflict && |
| 79 | test_commit -C conflict BASE file && |
| 80 | test_commit -C conflict A file foo && |
| 81 | git -C conflict reset --hard BASE && |
| 82 | test_commit -C conflict B file bar |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'output in a conflict' ' |
| 86 | test_must_fail git -C conflict merge A B && |
| 87 | cat >expected <<-\EOF && |
| 88 | file |
| 89 | file |
| 90 | file |
| 91 | file |
| 92 | EOF |
| 93 | git -C conflict ls-files --with-tree=HEAD >actual && |
| 94 | test_cmp expected actual |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'output with removed .git/index' ' |
| 98 | cat >expected <<-\EOF && |
| 99 | file |
| 100 | EOF |
| 101 | rm conflict/.git/index && |
| 102 | git -C conflict ls-files --with-tree=HEAD >actual && |
| 103 | test_cmp expected actual |
| 104 | ' |
| 105 | |
Carl Worth | 54e1abc | 2007-10-03 00:03:53 -0700 | [diff] [blame] | 106 | test_done |