Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Kyle Meyer | d8083e4 | 2019-04-10 11:28:57 -0400 | [diff] [blame] | 6 | test_description='basic tests for ls-files --others |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 7 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 8 | This test runs git ls-files --others with the following on the |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 9 | filesystem. |
| 10 | |
| 11 | path0 - a file |
| 12 | path1 - a symlink |
| 13 | path2/file2 - a file in a directory |
Junio C Hamano | 78c2cff | 2006-01-07 14:17:58 -0800 | [diff] [blame] | 14 | path3-junk - a file to confuse things |
| 15 | path3/file3 - a file in a directory |
Jeff King | 2fb6d6d | 2009-03-07 20:27:22 -0500 | [diff] [blame] | 16 | path4 - an empty directory |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 17 | ' |
Ævar Arnfjörð Bjarmason | 0b3481c | 2021-10-12 15:56:42 +0200 | [diff] [blame] | 18 | |
| 19 | TEST_PASSES_SANITIZE_LEAK=true |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 20 | . ./test-lib.sh |
| 21 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 22 | test_expect_success 'setup ' ' |
| 23 | date >path0 && |
| 24 | if test_have_prereq SYMLINKS |
| 25 | then |
| 26 | ln -s xyzzy path1 |
| 27 | else |
| 28 | date >path1 |
| 29 | fi && |
| 30 | mkdir path2 path3 path4 && |
| 31 | date >path2/file2 && |
| 32 | date >path2-junk && |
| 33 | date >path3/file3 && |
| 34 | date >path3-junk && |
| 35 | git update-index --add path3-junk path3/file3 |
| 36 | ' |
Junio C Hamano | 78c2cff | 2006-01-07 14:17:58 -0800 | [diff] [blame] | 37 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 38 | test_expect_success 'setup: expected output' ' |
| 39 | cat >expected1 <<-\EOF && |
| 40 | expected1 |
| 41 | expected2 |
| 42 | expected3 |
| 43 | output |
| 44 | path0 |
| 45 | path1 |
| 46 | path2-junk |
| 47 | path2/file2 |
| 48 | EOF |
Junio C Hamano | 78c2cff | 2006-01-07 14:17:58 -0800 | [diff] [blame] | 49 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 50 | sed -e "s|path2/file2|path2/|" <expected1 >expected2 && |
| 51 | cp expected2 expected3 && |
| 52 | echo path4/ >>expected2 |
| 53 | ' |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 54 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 55 | test_expect_success 'ls-files --others' ' |
| 56 | git ls-files --others >output && |
| 57 | test_cmp expected1 output |
| 58 | ' |
Junio C Hamano | 78c2cff | 2006-01-07 14:17:58 -0800 | [diff] [blame] | 59 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 60 | test_expect_success 'ls-files --others --directory' ' |
| 61 | git ls-files --others --directory >output && |
| 62 | test_cmp expected2 output |
| 63 | ' |
Junio C Hamano | 78c2cff | 2006-01-07 14:17:58 -0800 | [diff] [blame] | 64 | |
Jonathan Nieder | bcefed4 | 2010-07-10 23:20:25 -0500 | [diff] [blame] | 65 | test_expect_success '--no-empty-directory hides empty directory' ' |
| 66 | git ls-files --others --directory --no-empty-directory >output && |
| 67 | test_cmp expected3 output |
| 68 | ' |
Jeff King | 2fb6d6d | 2009-03-07 20:27:22 -0500 | [diff] [blame] | 69 | |
Jeff King | a2d5156 | 2016-01-22 17:29:30 -0500 | [diff] [blame] | 70 | test_expect_success 'ls-files --others handles non-submodule .git' ' |
| 71 | mkdir not-a-submodule && |
| 72 | echo foo >not-a-submodule/.git && |
| 73 | git ls-files -o >output && |
| 74 | test_cmp expected1 output |
| 75 | ' |
| 76 | |
Junio C Hamano | e5fa45c | 2011-10-17 11:43:30 -0700 | [diff] [blame] | 77 | test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' ' |
| 78 | git init super && |
| 79 | git init sub && |
| 80 | ( |
| 81 | cd sub && |
| 82 | >a && |
| 83 | git add a && |
| 84 | git commit -m sub && |
| 85 | git pack-refs --all |
| 86 | ) && |
| 87 | ( |
| 88 | cd super && |
Eric Sunshine | 3ea6737 | 2018-07-01 20:23:58 -0400 | [diff] [blame] | 89 | "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub && |
Junio C Hamano | e5fa45c | 2011-10-17 11:43:30 -0700 | [diff] [blame] | 90 | git ls-files --others --exclude-standard >../actual |
| 91 | ) && |
| 92 | echo sub/ >expect && |
| 93 | test_cmp expect actual |
| 94 | ' |
| 95 | |
Elijah Newren | 7260c7b | 2020-04-01 04:17:36 +0000 | [diff] [blame] | 96 | test_expect_success 'setup nested pathspec search' ' |
| 97 | test_create_repo nested && |
| 98 | ( |
| 99 | cd nested && |
| 100 | |
| 101 | mkdir -p partially_tracked/untracked_dir && |
| 102 | > partially_tracked/content && |
| 103 | > partially_tracked/untracked_dir/file && |
| 104 | |
| 105 | mkdir -p untracked/deep && |
| 106 | > untracked/deep/path && |
| 107 | > untracked/deep/foo.c && |
| 108 | |
| 109 | git add partially_tracked/content |
| 110 | ) |
| 111 | ' |
| 112 | |
| 113 | test_expect_success 'ls-files -o --directory with single deep dir pathspec' ' |
| 114 | ( |
| 115 | cd nested && |
| 116 | |
| 117 | git ls-files -o --directory untracked/deep/ >actual && |
| 118 | |
| 119 | cat <<-EOF >expect && |
| 120 | untracked/deep/ |
| 121 | EOF |
| 122 | |
| 123 | test_cmp expect actual |
| 124 | ) |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'ls-files -o --directory with multiple dir pathspecs' ' |
| 128 | ( |
| 129 | cd nested && |
| 130 | |
| 131 | git ls-files -o --directory partially_tracked/ untracked/ >actual && |
| 132 | |
| 133 | cat <<-EOF >expect && |
| 134 | partially_tracked/untracked_dir/ |
| 135 | untracked/ |
| 136 | EOF |
| 137 | |
| 138 | test_cmp expect actual |
| 139 | ) |
| 140 | ' |
| 141 | |
| 142 | test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' ' |
| 143 | ( |
| 144 | cd nested && |
| 145 | |
| 146 | git ls-files -o --directory partially_tracked/ untracked/deep/path >actual && |
| 147 | |
| 148 | cat <<-EOF >expect && |
| 149 | partially_tracked/untracked_dir/ |
| 150 | untracked/deep/path |
| 151 | EOF |
| 152 | |
| 153 | test_cmp expect actual |
| 154 | ) |
| 155 | ' |
| 156 | |
Elijah Newren | ed8268d | 2020-08-12 07:12:35 +0000 | [diff] [blame] | 157 | test_expect_success 'ls-files -o --directory with glob filetype match' ' |
Elijah Newren | 7260c7b | 2020-04-01 04:17:36 +0000 | [diff] [blame] | 158 | ( |
| 159 | cd nested && |
| 160 | |
| 161 | # globs kinda defeat --directory, but only for that pathspec |
| 162 | git ls-files --others --directory partially_tracked "untracked/*.c" >actual && |
| 163 | |
| 164 | cat <<-EOF >expect && |
| 165 | partially_tracked/untracked_dir/ |
| 166 | untracked/deep/foo.c |
| 167 | EOF |
| 168 | |
| 169 | test_cmp expect actual |
| 170 | ) |
| 171 | ' |
| 172 | |
Elijah Newren | ed8268d | 2020-08-12 07:12:35 +0000 | [diff] [blame] | 173 | test_expect_success 'ls-files -o --directory with mix of tracked states' ' |
Elijah Newren | 7260c7b | 2020-04-01 04:17:36 +0000 | [diff] [blame] | 174 | ( |
| 175 | cd nested && |
| 176 | |
| 177 | # globs kinda defeat --directory, but only for that pathspec |
| 178 | git ls-files --others --directory partially_tracked/ "untracked/?*" >actual && |
| 179 | |
| 180 | cat <<-EOF >expect && |
| 181 | partially_tracked/untracked_dir/ |
| 182 | untracked/deep/ |
| 183 | EOF |
| 184 | |
| 185 | test_cmp expect actual |
| 186 | ) |
| 187 | ' |
| 188 | |
Elijah Newren | ed8268d | 2020-08-12 07:12:35 +0000 | [diff] [blame] | 189 | test_expect_success 'ls-files -o --directory with glob filetype match only' ' |
Elijah Newren | 7260c7b | 2020-04-01 04:17:36 +0000 | [diff] [blame] | 190 | ( |
| 191 | cd nested && |
| 192 | |
| 193 | git ls-files --others --directory "untracked/*.c" >actual && |
| 194 | |
| 195 | cat <<-EOF >expect && |
| 196 | untracked/deep/foo.c |
| 197 | EOF |
| 198 | |
| 199 | test_cmp expect actual |
| 200 | ) |
| 201 | ' |
| 202 | |
Elijah Newren | ed8268d | 2020-08-12 07:12:35 +0000 | [diff] [blame] | 203 | test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' ' |
Elijah Newren | 7260c7b | 2020-04-01 04:17:36 +0000 | [diff] [blame] | 204 | ( |
| 205 | cd nested && |
| 206 | |
| 207 | git ls-files --others --directory "untracked/?*" >actual && |
| 208 | |
| 209 | cat <<-EOF >expect && |
| 210 | untracked/deep/ |
| 211 | EOF |
| 212 | |
| 213 | test_cmp expect actual |
| 214 | ) |
| 215 | ' |
| 216 | |
Elijah Newren | ab282aa | 2020-08-12 07:12:36 +0000 | [diff] [blame] | 217 | test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' ' |
| 218 | test_when_finished "rm -rf nested/untracked/deep/empty" && |
| 219 | ( |
| 220 | cd nested && |
| 221 | |
| 222 | git init untracked/deep/empty && |
| 223 | git ls-files --others "untracked/*.c" >actual && |
| 224 | |
| 225 | cat <<-EOF >expect && |
| 226 | untracked/deep/foo.c |
| 227 | EOF |
| 228 | |
| 229 | test_cmp expect actual |
| 230 | ) |
| 231 | ' |
| 232 | |
Junio C Hamano | 368f99d | 2005-05-13 22:52:42 -0700 | [diff] [blame] | 233 | test_done |