| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='basic tests for ls-files --others |
| 7 | |
| 8 | This test runs git ls-files --others with the following on the |
| 9 | filesystem. |
| 10 | |
| 11 | path0 - a file |
| 12 | path1 - a symlink |
| 13 | path2/file2 - a file in a directory |
| 14 | path3-junk - a file to confuse things |
| 15 | path3/file3 - a file in a directory |
| 16 | path4 - an empty directory |
| 17 | ' |
| 18 | |
| 19 | . ./test-lib.sh |
| 20 | |
| 21 | test_expect_success 'setup ' ' |
| 22 | date >path0 && |
| 23 | if test_have_prereq SYMLINKS |
| 24 | then |
| 25 | ln -s xyzzy path1 |
| 26 | else |
| 27 | date >path1 |
| 28 | fi && |
| 29 | mkdir path2 path3 path4 && |
| 30 | date >path2/file2 && |
| 31 | date >path2-junk && |
| 32 | date >path3/file3 && |
| 33 | date >path3-junk && |
| 34 | git update-index --add path3-junk path3/file3 |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'setup: expected output' ' |
| 38 | cat >expected1 <<-\EOF && |
| 39 | expected1 |
| 40 | expected2 |
| 41 | expected3 |
| 42 | output |
| 43 | path0 |
| 44 | path1 |
| 45 | path2-junk |
| 46 | path2/file2 |
| 47 | EOF |
| 48 | |
| 49 | sed -e "s|path2/file2|path2/|" <expected1 >expected2 && |
| 50 | cp expected2 expected3 && |
| 51 | echo path4/ >>expected2 |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'ls-files --others' ' |
| 55 | git ls-files --others >output && |
| 56 | test_filter_gitconfig output && |
| 57 | test_cmp expected1 output |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'ls-files --others --directory' ' |
| 61 | git ls-files --others --directory >output && |
| 62 | test_filter_gitconfig output && |
| 63 | test_cmp expected2 output |
| 64 | ' |
| 65 | |
| 66 | test_expect_success '--no-empty-directory hides empty directory' ' |
| 67 | git ls-files --others --directory --no-empty-directory >output && |
| 68 | test_filter_gitconfig output && |
| 69 | test_cmp expected3 output |
| 70 | ' |
| 71 | |
| 72 | test_expect_success 'ls-files --others handles non-submodule .git' ' |
| 73 | mkdir not-a-submodule && |
| 74 | echo foo >not-a-submodule/.git && |
| 75 | git ls-files -o >output && |
| 76 | test_filter_gitconfig output && |
| 77 | test_cmp expected1 output |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'setup nested pathspec search' ' |
| 81 | test_create_repo nested && |
| 82 | ( |
| 83 | cd nested && |
| 84 | |
| 85 | mkdir -p partially_tracked/untracked_dir && |
| 86 | > partially_tracked/content && |
| 87 | > partially_tracked/untracked_dir/file && |
| 88 | |
| 89 | mkdir -p untracked/deep && |
| 90 | > untracked/deep/path && |
| 91 | > untracked/deep/foo.c && |
| 92 | |
| 93 | git add partially_tracked/content |
| 94 | ) |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'ls-files -o --directory with single deep dir pathspec' ' |
| 98 | ( |
| 99 | cd nested && |
| 100 | |
| 101 | git ls-files -o --directory untracked/deep/ >actual && |
| 102 | |
| 103 | cat <<-EOF >expect && |
| 104 | untracked/deep/ |
| 105 | EOF |
| 106 | |
| 107 | test_cmp expect actual |
| 108 | ) |
| 109 | ' |
| 110 | |
| 111 | test_expect_success 'ls-files -o --directory with multiple dir pathspecs' ' |
| 112 | ( |
| 113 | cd nested && |
| 114 | |
| 115 | git ls-files -o --directory partially_tracked/ untracked/ >actual && |
| 116 | |
| 117 | cat <<-EOF >expect && |
| 118 | partially_tracked/untracked_dir/ |
| 119 | untracked/ |
| 120 | EOF |
| 121 | |
| 122 | test_cmp expect actual |
| 123 | ) |
| 124 | ' |
| 125 | |
| 126 | test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' ' |
| 127 | ( |
| 128 | cd nested && |
| 129 | |
| 130 | git ls-files -o --directory partially_tracked/ untracked/deep/path >actual && |
| 131 | |
| 132 | cat <<-EOF >expect && |
| 133 | partially_tracked/untracked_dir/ |
| 134 | untracked/deep/path |
| 135 | EOF |
| 136 | |
| 137 | test_cmp expect actual |
| 138 | ) |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'ls-files -o --directory with glob filetype match' ' |
| 142 | ( |
| 143 | cd nested && |
| 144 | |
| 145 | # globs kinda defeat --directory, but only for that pathspec |
| 146 | git ls-files --others --directory partially_tracked "untracked/*.c" >actual && |
| 147 | |
| 148 | cat <<-EOF >expect && |
| 149 | partially_tracked/untracked_dir/ |
| 150 | untracked/deep/foo.c |
| 151 | EOF |
| 152 | |
| 153 | test_cmp expect actual |
| 154 | ) |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'ls-files -o --directory with mix of tracked states' ' |
| 158 | ( |
| 159 | cd nested && |
| 160 | |
| 161 | # globs kinda defeat --directory, but only for that pathspec |
| 162 | git ls-files --others --directory partially_tracked/ "untracked/?*" >actual && |
| 163 | |
| 164 | cat <<-EOF >expect && |
| 165 | partially_tracked/untracked_dir/ |
| 166 | untracked/deep/ |
| 167 | EOF |
| 168 | |
| 169 | test_cmp expect actual |
| 170 | ) |
| 171 | ' |
| 172 | |
| 173 | test_expect_success 'ls-files -o --directory with glob filetype match only' ' |
| 174 | ( |
| 175 | cd nested && |
| 176 | |
| 177 | git ls-files --others --directory "untracked/*.c" >actual && |
| 178 | |
| 179 | cat <<-EOF >expect && |
| 180 | untracked/deep/foo.c |
| 181 | EOF |
| 182 | |
| 183 | test_cmp expect actual |
| 184 | ) |
| 185 | ' |
| 186 | |
| 187 | test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' ' |
| 188 | ( |
| 189 | cd nested && |
| 190 | |
| 191 | git ls-files --others --directory "untracked/?*" >actual && |
| 192 | |
| 193 | cat <<-EOF >expect && |
| 194 | untracked/deep/ |
| 195 | EOF |
| 196 | |
| 197 | test_cmp expect actual |
| 198 | ) |
| 199 | ' |
| 200 | |
| 201 | test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' ' |
| 202 | test_when_finished "rm -rf nested/untracked/deep/empty" && |
| 203 | ( |
| 204 | cd nested && |
| 205 | |
| 206 | git init untracked/deep/empty && |
| 207 | git ls-files --others "untracked/*.c" >actual && |
| 208 | |
| 209 | cat <<-EOF >expect && |
| 210 | untracked/deep/foo.c |
| 211 | EOF |
| 212 | |
| 213 | test_cmp expect actual |
| 214 | ) |
| 215 | ' |
| 216 | |
| 217 | test_done |