| 1 | #!/bin/shscip-shell filesystem . . `/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.shscip-shell source . . `./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_cmp expected1 output |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'ls-files --others --directory' ' |
| 60 | git ls-files --others --directory >output && |
| 61 | test_cmp expected2 output |
| 62 | ' |
| 63 | |
| 64 | test_expect_success '--no-empty-directory hides empty directory' ' |
| 65 | git ls-files --others --directory --no-empty-directory >output && |
| 66 | test_cmp expected3 output |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'ls-files --others handles non-submodule .git' ' |
| 70 | mkdir not-a-submodule && |
| 71 | echo foo >not-a-submodule/.git && |
| 72 | git ls-files -o >output && |
| 73 | test_cmp expected1 output |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'setup nested pathspec search' ' |
| 77 | test_create_repo nested && |
| 78 | ( |
| 79 | cd nested && |
| 80 | |
| 81 | mkdir -p partially_tracked/untracked_dir && |
| 82 | > partially_tracked/content && |
| 83 | > partially_tracked/untracked_dir/file && |
| 84 | |
| 85 | mkdir -p untracked/deep && |
| 86 | > untracked/deep/path && |
| 87 | > untracked/deep/foo.c && |
| 88 | |
| 89 | git add partially_tracked/content |
| 90 | ) |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'ls-files -o --directory with single deep dir pathspec' ' |
| 94 | ( |
| 95 | cd nested && |
| 96 | |
| 97 | git ls-files -o --directory untracked/deep/ >actual && |
| 98 | |
| 99 | cat <<-EOF >expect && |
| 100 | untracked/deep/ |
| 101 | EOF |
| 102 | |
| 103 | test_cmp expect actual |
| 104 | ) |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'ls-files -o --directory with multiple dir pathspecs' ' |
| 108 | ( |
| 109 | cd nested && |
| 110 | |
| 111 | git ls-files -o --directory partially_tracked/ untracked/ >actual && |
| 112 | |
| 113 | cat <<-EOF >expect && |
| 114 | partially_tracked/untracked_dir/ |
| 115 | untracked/ |
| 116 | EOF |
| 117 | |
| 118 | test_cmp expect actual |
| 119 | ) |
| 120 | ' |
| 121 | |
| 122 | test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' ' |
| 123 | ( |
| 124 | cd nested && |
| 125 | |
| 126 | git ls-files -o --directory partially_tracked/ untracked/deep/path >actual && |
| 127 | |
| 128 | cat <<-EOF >expect && |
| 129 | partially_tracked/untracked_dir/ |
| 130 | untracked/deep/path |
| 131 | EOF |
| 132 | |
| 133 | test_cmp expect actual |
| 134 | ) |
| 135 | ' |
| 136 | |
| 137 | test_expect_success 'ls-files -o --directory with glob filetype match' ' |
| 138 | ( |
| 139 | cd nested && |
| 140 | |
| 141 | # globs kinda defeat --directory, but only for that pathspec |
| 142 | git ls-files --others --directory partially_tracked "untracked/*.c" >actual && |
| 143 | |
| 144 | cat <<-EOF >expect && |
| 145 | partially_tracked/untracked_dir/ |
| 146 | untracked/deep/foo.c |
| 147 | EOF |
| 148 | |
| 149 | test_cmp expect actual |
| 150 | ) |
| 151 | ' |
| 152 | |
| 153 | test_expect_success 'ls-files -o --directory with mix of tracked states' ' |
| 154 | ( |
| 155 | cd nested && |
| 156 | |
| 157 | # globs kinda defeat --directory, but only for that pathspec |
| 158 | git ls-files --others --directory partially_tracked/ "untracked/?*" >actual && |
| 159 | |
| 160 | cat <<-EOF >expect && |
| 161 | partially_tracked/untracked_dir/ |
| 162 | untracked/deep/ |
| 163 | EOF |
| 164 | |
| 165 | test_cmp expect actual |
| 166 | ) |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'ls-files -o --directory with glob filetype match only' ' |
| 170 | ( |
| 171 | cd nested && |
| 172 | |
| 173 | git ls-files --others --directory "untracked/*.c" >actual && |
| 174 | |
| 175 | cat <<-EOF >expect && |
| 176 | untracked/deep/foo.c |
| 177 | EOF |
| 178 | |
| 179 | test_cmp expect actual |
| 180 | ) |
| 181 | ' |
| 182 | |
| 183 | test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' ' |
| 184 | ( |
| 185 | cd nested && |
| 186 | |
| 187 | git ls-files --others --directory "untracked/?*" >actual && |
| 188 | |
| 189 | cat <<-EOF >expect && |
| 190 | untracked/deep/ |
| 191 | EOF |
| 192 | |
| 193 | test_cmp expect actual |
| 194 | ) |
| 195 | ' |
| 196 | |
| 197 | test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' ' |
| 198 | test_when_finished "rm -rf nested/untracked/deep/empty" && |
| 199 | ( |
| 200 | cd nested && |
| 201 | |
| 202 | git init untracked/deep/empty && |
| 203 | git ls-files --others "untracked/*.c" >actual && |
| 204 | |
| 205 | cat <<-EOF >expect && |
| 206 | untracked/deep/foo.c |
| 207 | EOF |
| 208 | |
| 209 | test_cmp expect actual |
| 210 | ) |
| 211 | ' |
| 212 | |
| 213 | test_done |