| 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 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | test_expect_success 'setup' ' |
| 15 | |
| 16 | # The bug we are exercising requires a fair number of entries |
| 17 | # in a sub-directory so that add_index_entry will trigger a |
| 18 | # realloc. |
| 19 | |
| 20 | echo file >expected && |
| 21 | mkdir sub && |
| 22 | for n in 0 1 2 3 4 5 |
| 23 | do |
| 24 | for m in 0 1 2 3 4 5 6 7 8 9 |
| 25 | do |
| 26 | num=00$n$m && |
| 27 | >sub/file-$num && |
| 28 | echo file-$num >>expected || |
| 29 | return 1 |
| 30 | done |
| 31 | done && |
| 32 | git add . && |
| 33 | git commit -m "add a bunch of files" && |
| 34 | |
| 35 | # We remove them all so that we will have something to add |
| 36 | # back with --with-tree and so that we will definitely be |
| 37 | # under the realloc size to trigger the bug. |
| 38 | rm -rf sub && |
| 39 | git commit -a -m "remove them all" && |
| 40 | |
| 41 | # The bug also requires some entry before our directory so that |
| 42 | # prune_index will modify the_repository->index.cache |
| 43 | |
| 44 | mkdir a_directory_that_sorts_before_sub && |
| 45 | >a_directory_that_sorts_before_sub/file && |
| 46 | mkdir sub && |
| 47 | >sub/file && |
| 48 | git add . |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'usage' ' |
| 52 | test_expect_code 128 git ls-files --with-tree=HEAD -u && |
| 53 | test_expect_code 128 git ls-files --with-tree=HEAD -s && |
| 54 | test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'git ls-files --with-tree should succeed from subdir' ' |
| 58 | # We have to run from a sub-directory to trigger prune_index |
| 59 | # Then we finally get to run our --with-tree test |
| 60 | ( |
| 61 | cd sub && |
| 62 | git ls-files --with-tree=HEAD~1 >../output |
| 63 | ) |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'git ls-files --with-tree should add entries from named tree.' ' |
| 67 | test_cmp expected output |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'no duplicates in --with-tree output' ' |
| 71 | git ls-files --with-tree=HEAD >actual && |
| 72 | sort -u actual >expected && |
| 73 | test_cmp expected actual |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'setup: output in a conflict' ' |
| 77 | test_create_repo conflict && |
| 78 | test_commit -C conflict BASE file && |
| 79 | test_commit -C conflict A file foo && |
| 80 | git -C conflict reset --hard BASE && |
| 81 | test_commit -C conflict B file bar |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'output in a conflict' ' |
| 85 | test_must_fail git -C conflict merge A B && |
| 86 | cat >expected <<-\EOF && |
| 87 | file |
| 88 | file |
| 89 | file |
| 90 | file |
| 91 | EOF |
| 92 | git -C conflict ls-files --with-tree=HEAD >actual && |
| 93 | test_cmp expected actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'output with removed .git/index' ' |
| 97 | cat >expected <<-\EOF && |
| 98 | file |
| 99 | EOF |
| 100 | rm conflict/.git/index && |
| 101 | git -C conflict ls-files --with-tree=HEAD >actual && |
| 102 | test_cmp expected actual |
| 103 | ' |
| 104 | |
| 105 | test_done |