Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Michael Spang |
| 4 | # |
| 5 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 6 | test_description='git clean basic tests' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 10 | git config clean.requireForce no |
| 11 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 12 | test_expect_success 'setup' ' |
| 13 | |
| 14 | mkdir -p src && |
| 15 | touch src/part1.c Makefile && |
| 16 | echo build >.gitignore && |
| 17 | echo \*.o >>.gitignore && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 18 | git add . && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 19 | git commit -m setup && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 20 | touch src/part2.c README && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 21 | git add . |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 22 | |
| 23 | ' |
| 24 | |
Nguyễn Thái Ngọc Duy | c28b3d6 | 2009-08-20 20:47:01 +0700 | [diff] [blame] | 25 | test_expect_success 'git clean with skip-worktree .gitignore' ' |
| 26 | git update-index --skip-worktree .gitignore && |
| 27 | rm .gitignore && |
| 28 | mkdir -p build docs && |
| 29 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 30 | git clean && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 31 | test_path_is_file Makefile && |
| 32 | test_path_is_file README && |
| 33 | test_path_is_file src/part1.c && |
| 34 | test_path_is_file src/part2.c && |
| 35 | test_path_is_missing a.out && |
| 36 | test_path_is_missing src/part3.c && |
| 37 | test_path_is_file docs/manual.txt && |
| 38 | test_path_is_file obj.o && |
| 39 | test_path_is_file build/lib.so && |
Nguyễn Thái Ngọc Duy | c28b3d6 | 2009-08-20 20:47:01 +0700 | [diff] [blame] | 40 | git update-index --no-skip-worktree .gitignore && |
| 41 | git checkout .gitignore |
| 42 | ' |
| 43 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 44 | test_expect_success 'git clean' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 45 | |
| 46 | mkdir -p build docs && |
| 47 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 48 | git clean && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 49 | test_path_is_file Makefile && |
| 50 | test_path_is_file README && |
| 51 | test_path_is_file src/part1.c && |
| 52 | test_path_is_file src/part2.c && |
| 53 | test_path_is_missing a.out && |
| 54 | test_path_is_missing src/part3.c && |
| 55 | test_path_is_file docs/manual.txt && |
| 56 | test_path_is_file obj.o && |
| 57 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 58 | |
| 59 | ' |
| 60 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 61 | test_expect_success 'git clean src/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 62 | |
| 63 | mkdir -p build docs && |
| 64 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 65 | git clean src/ && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 66 | test_path_is_file Makefile && |
| 67 | test_path_is_file README && |
| 68 | test_path_is_file src/part1.c && |
| 69 | test_path_is_file src/part2.c && |
| 70 | test_path_is_file a.out && |
| 71 | test_path_is_missing src/part3.c && |
| 72 | test_path_is_file docs/manual.txt && |
| 73 | test_path_is_file obj.o && |
| 74 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 75 | |
| 76 | ' |
| 77 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 78 | test_expect_success 'git clean src/ src/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 79 | |
| 80 | mkdir -p build docs && |
| 81 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 82 | git clean src/ src/ && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 83 | test_path_is_file Makefile && |
| 84 | test_path_is_file README && |
| 85 | test_path_is_file src/part1.c && |
| 86 | test_path_is_file src/part2.c && |
| 87 | test_path_is_file a.out && |
| 88 | test_path_is_missing src/part3.c && |
| 89 | test_path_is_file docs/manual.txt && |
| 90 | test_path_is_file obj.o && |
| 91 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 92 | |
| 93 | ' |
| 94 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 95 | test_expect_success 'git clean with prefix' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 96 | |
Shawn Bohrer | 2b6f0b0 | 2008-04-13 18:49:38 -0500 | [diff] [blame] | 97 | mkdir -p build docs src/test && |
| 98 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 99 | (cd src/ && git clean) && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 100 | test_path_is_file Makefile && |
| 101 | test_path_is_file README && |
| 102 | test_path_is_file src/part1.c && |
| 103 | test_path_is_file src/part2.c && |
| 104 | test_path_is_file a.out && |
| 105 | test_path_is_missing src/part3.c && |
| 106 | test_path_is_file src/test/1.c && |
| 107 | test_path_is_file docs/manual.txt && |
| 108 | test_path_is_file obj.o && |
| 109 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 110 | |
| 111 | ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 112 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 113 | test_expect_success 'git clean with relative prefix' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 114 | |
| 115 | mkdir -p build docs && |
| 116 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 117 | would_clean=$( |
| 118 | cd docs && |
| 119 | git clean -n ../src | |
Elijah Newren | e86bbcf | 2019-09-17 09:35:01 -0700 | [diff] [blame] | 120 | grep part3 | |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 121 | sed -n -e "s|^Would remove ||p" |
| 122 | ) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 123 | test "$would_clean" = ../src/part3.c |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 124 | ' |
| 125 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 126 | test_expect_success 'git clean with absolute path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 127 | |
| 128 | mkdir -p build docs && |
| 129 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 130 | would_clean=$( |
| 131 | cd docs && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 132 | git clean -n "$(pwd)/../src" | |
Elijah Newren | e86bbcf | 2019-09-17 09:35:01 -0700 | [diff] [blame] | 133 | grep part3 | |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 134 | sed -n -e "s|^Would remove ||p" |
| 135 | ) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 136 | test "$would_clean" = ../src/part3.c |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 137 | ' |
| 138 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 139 | test_expect_success 'git clean with out of work tree relative path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 140 | |
| 141 | mkdir -p build docs && |
| 142 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 143 | ( |
| 144 | cd docs && |
| 145 | test_must_fail git clean -n ../.. |
| 146 | ) |
| 147 | ' |
| 148 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 149 | test_expect_success 'git clean with out of work tree absolute path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 150 | |
| 151 | mkdir -p build docs && |
| 152 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 153 | dd=$(cd .. && pwd) && |
| 154 | ( |
| 155 | cd docs && |
| 156 | test_must_fail git clean -n $dd |
| 157 | ) |
| 158 | ' |
| 159 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 160 | test_expect_success 'git clean -d with prefix and path' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 161 | |
| 162 | mkdir -p build docs src/feature && |
| 163 | touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 164 | (cd src/ && git clean -d feature/) && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 165 | test_path_is_file Makefile && |
| 166 | test_path_is_file README && |
| 167 | test_path_is_file src/part1.c && |
| 168 | test_path_is_file src/part2.c && |
| 169 | test_path_is_file a.out && |
| 170 | test_path_is_file src/part3.c && |
| 171 | test_path_is_missing src/feature/file.c && |
| 172 | test_path_is_file docs/manual.txt && |
| 173 | test_path_is_file obj.o && |
| 174 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 175 | |
| 176 | ' |
| 177 | |
Johannes Sixt | 7569c1f | 2010-11-25 09:03:39 +0100 | [diff] [blame] | 178 | test_expect_success SYMLINKS 'git clean symbolic link' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 179 | |
| 180 | mkdir -p build docs && |
| 181 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 182 | ln -s docs/manual.txt src/part4.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 183 | git clean && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 184 | test_path_is_file Makefile && |
| 185 | test_path_is_file README && |
| 186 | test_path_is_file src/part1.c && |
| 187 | test_path_is_file src/part2.c && |
| 188 | test_path_is_missing a.out && |
| 189 | test_path_is_missing src/part3.c && |
| 190 | test_path_is_missing src/part4.c && |
| 191 | test_path_is_file docs/manual.txt && |
| 192 | test_path_is_file obj.o && |
| 193 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 194 | |
| 195 | ' |
| 196 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 197 | test_expect_success 'git clean with wildcard' ' |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 198 | |
| 199 | touch a.clean b.clean other.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 200 | git clean "*.clean" && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 201 | test_path_is_file Makefile && |
| 202 | test_path_is_file README && |
| 203 | test_path_is_file src/part1.c && |
| 204 | test_path_is_file src/part2.c && |
| 205 | test_path_is_missing a.clean && |
| 206 | test_path_is_missing b.clean && |
| 207 | test_path_is_file other.c |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 208 | |
| 209 | ' |
| 210 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 211 | test_expect_success 'git clean -n' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 212 | |
| 213 | mkdir -p build docs && |
| 214 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 215 | git clean -n && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 216 | test_path_is_file Makefile && |
| 217 | test_path_is_file README && |
| 218 | test_path_is_file src/part1.c && |
| 219 | test_path_is_file src/part2.c && |
| 220 | test_path_is_file a.out && |
| 221 | test_path_is_file src/part3.c && |
| 222 | test_path_is_file docs/manual.txt && |
| 223 | test_path_is_file obj.o && |
| 224 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 225 | |
| 226 | ' |
| 227 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 228 | test_expect_success 'git clean -d' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 229 | |
| 230 | mkdir -p build docs && |
| 231 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 232 | git clean -d && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 233 | test_path_is_file Makefile && |
| 234 | test_path_is_file README && |
| 235 | test_path_is_file src/part1.c && |
| 236 | test_path_is_file src/part2.c && |
| 237 | test_path_is_missing a.out && |
| 238 | test_path_is_missing src/part3.c && |
| 239 | test_path_is_missing docs && |
| 240 | test_path_is_file obj.o && |
| 241 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 242 | |
| 243 | ' |
| 244 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 245 | test_expect_success 'git clean -d src/ examples/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 246 | |
| 247 | mkdir -p build docs examples && |
| 248 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 249 | git clean -d src/ examples/ && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 250 | test_path_is_file Makefile && |
| 251 | test_path_is_file README && |
| 252 | test_path_is_file src/part1.c && |
| 253 | test_path_is_file src/part2.c && |
| 254 | test_path_is_file a.out && |
| 255 | test_path_is_missing src/part3.c && |
| 256 | test_path_is_missing examples/1.c && |
| 257 | test_path_is_file docs/manual.txt && |
| 258 | test_path_is_file obj.o && |
| 259 | test_path_is_file build/lib.so |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 260 | |
| 261 | ' |
| 262 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 263 | test_expect_success 'git clean -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 264 | |
| 265 | mkdir -p build docs && |
| 266 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 267 | git clean -x && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 268 | test_path_is_file Makefile && |
| 269 | test_path_is_file README && |
| 270 | test_path_is_file src/part1.c && |
| 271 | test_path_is_file src/part2.c && |
| 272 | test_path_is_missing a.out && |
| 273 | test_path_is_missing src/part3.c && |
| 274 | test_path_is_file docs/manual.txt && |
| 275 | test_path_is_missing obj.o && |
| 276 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 277 | |
| 278 | ' |
| 279 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 280 | test_expect_success 'git clean -d -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 281 | |
| 282 | mkdir -p build docs && |
| 283 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 284 | git clean -d -x && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 285 | test_path_is_file Makefile && |
| 286 | test_path_is_file README && |
| 287 | test_path_is_file src/part1.c && |
| 288 | test_path_is_file src/part2.c && |
| 289 | test_path_is_missing a.out && |
| 290 | test_path_is_missing src/part3.c && |
| 291 | test_path_is_missing docs && |
| 292 | test_path_is_missing obj.o && |
| 293 | test_path_is_missing build |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 294 | |
| 295 | ' |
| 296 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 297 | test_expect_success 'git clean -d -x with ignored tracked directory' ' |
| 298 | |
| 299 | mkdir -p build docs && |
| 300 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 301 | git clean -d -x -e src && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 302 | test_path_is_file Makefile && |
| 303 | test_path_is_file README && |
| 304 | test_path_is_file src/part1.c && |
| 305 | test_path_is_file src/part2.c && |
| 306 | test_path_is_missing a.out && |
| 307 | test_path_is_file src/part3.c && |
| 308 | test_path_is_missing docs && |
| 309 | test_path_is_missing obj.o && |
| 310 | test_path_is_missing build |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 311 | |
| 312 | ' |
| 313 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 314 | test_expect_success 'git clean -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 315 | |
| 316 | mkdir -p build docs && |
| 317 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 318 | git clean -X && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 319 | test_path_is_file Makefile && |
| 320 | test_path_is_file README && |
| 321 | test_path_is_file src/part1.c && |
| 322 | test_path_is_file src/part2.c && |
| 323 | test_path_is_file a.out && |
| 324 | test_path_is_file src/part3.c && |
| 325 | test_path_is_file docs/manual.txt && |
| 326 | test_path_is_missing obj.o && |
| 327 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 328 | |
| 329 | ' |
| 330 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 331 | test_expect_success 'git clean -d -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 332 | |
| 333 | mkdir -p build docs && |
| 334 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 335 | git clean -d -X && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 336 | test_path_is_file Makefile && |
| 337 | test_path_is_file README && |
| 338 | test_path_is_file src/part1.c && |
| 339 | test_path_is_file src/part2.c && |
| 340 | test_path_is_file a.out && |
| 341 | test_path_is_file src/part3.c && |
| 342 | test_path_is_file docs/manual.txt && |
| 343 | test_path_is_missing obj.o && |
| 344 | test_path_is_missing build |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 345 | |
| 346 | ' |
| 347 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 348 | test_expect_success 'git clean -d -X with ignored tracked directory' ' |
| 349 | |
| 350 | mkdir -p build docs && |
| 351 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 352 | git clean -d -X -e src && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 353 | test_path_is_file Makefile && |
| 354 | test_path_is_file README && |
| 355 | test_path_is_file src/part1.c && |
| 356 | test_path_is_file src/part2.c && |
| 357 | test_path_is_file a.out && |
| 358 | test_path_is_missing src/part3.c && |
| 359 | test_path_is_file docs/manual.txt && |
| 360 | test_path_is_missing obj.o && |
| 361 | test_path_is_missing build |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 362 | |
| 363 | ' |
| 364 | |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 365 | test_expect_success 'clean.requireForce defaults to true' ' |
| 366 | |
| 367 | git config --unset clean.requireForce && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 368 | test_must_fail git clean |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 369 | |
| 370 | ' |
| 371 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 372 | test_expect_success 'clean.requireForce' ' |
| 373 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 374 | git config clean.requireForce true && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 375 | test_must_fail git clean |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 376 | |
| 377 | ' |
| 378 | |
| 379 | test_expect_success 'clean.requireForce and -n' ' |
| 380 | |
| 381 | mkdir -p build docs && |
| 382 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 383 | git clean -n && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 384 | test_path_is_file Makefile && |
| 385 | test_path_is_file README && |
| 386 | test_path_is_file src/part1.c && |
| 387 | test_path_is_file src/part2.c && |
| 388 | test_path_is_file a.out && |
| 389 | test_path_is_file src/part3.c && |
| 390 | test_path_is_file docs/manual.txt && |
| 391 | test_path_is_file obj.o && |
| 392 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 393 | |
| 394 | ' |
| 395 | |
| 396 | test_expect_success 'clean.requireForce and -f' ' |
| 397 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 398 | git clean -f && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 399 | test_path_is_file README && |
| 400 | test_path_is_file src/part1.c && |
| 401 | test_path_is_file src/part2.c && |
| 402 | test_path_is_missing a.out && |
| 403 | test_path_is_missing src/part3.c && |
| 404 | test_path_is_file docs/manual.txt && |
| 405 | test_path_is_file obj.o && |
| 406 | test_path_is_file build/lib.so |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 407 | |
| 408 | ' |
| 409 | |
Junio C Hamano | 105ec9a | 2024-03-03 14:06:00 -0800 | [diff] [blame] | 410 | test_expect_success 'clean.requireForce and --interactive' ' |
| 411 | git clean --interactive </dev/null >output 2>error && |
| 412 | test_grep ! "requireForce is true and" error && |
| 413 | test_grep "\*\*\* Commands \*\*\*" output |
| 414 | ' |
| 415 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 416 | test_expect_success 'core.excludesfile' ' |
Junio C Hamano | b57321f | 2007-11-14 01:54:43 -0800 | [diff] [blame] | 417 | |
| 418 | echo excludes >excludes && |
| 419 | echo included >included && |
| 420 | git config core.excludesfile excludes && |
| 421 | output=$(git clean -n excludes included 2>&1) && |
| 422 | expr "$output" : ".*included" >/dev/null && |
| 423 | ! expr "$output" : ".*excludes" >/dev/null |
| 424 | |
| 425 | ' |
| 426 | |
Ævar Arnfjörð Bjarmason | c91cfd1 | 2010-08-06 22:09:09 +0000 | [diff] [blame] | 427 | test_expect_success SANITY 'removal failure' ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 428 | |
| 429 | mkdir foo && |
| 430 | touch foo/bar && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 431 | test_when_finished "chmod 755 foo" && |
Johannes Schindelin | e2c2407 | 2009-03-11 17:58:32 +0100 | [diff] [blame] | 432 | (exec <foo/bar && |
| 433 | chmod 0 foo && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 434 | test_must_fail git clean -f -d) |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 435 | ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 436 | |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 437 | test_expect_success 'nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 438 | rm -fr foo bar baz && |
| 439 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 440 | ( |
| 441 | cd foo && |
| 442 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 443 | test_commit nested hello.world |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 444 | ) && |
| 445 | ( |
| 446 | cd bar && |
| 447 | >goodbye.people |
| 448 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 449 | ( |
| 450 | cd baz/boo && |
| 451 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 452 | test_commit deeply.nested deeper.world |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 453 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 454 | git clean -f -d && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 455 | test_path_is_file foo/.git/index && |
| 456 | test_path_is_file foo/hello.world && |
| 457 | test_path_is_file baz/boo/.git/index && |
| 458 | test_path_is_file baz/boo/deeper.world && |
| 459 | test_path_is_missing bar |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 460 | ' |
| 461 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 462 | test_expect_success 'should clean things that almost look like git but are not' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 463 | rm -fr almost_git almost_bare_git almost_submodule && |
| 464 | mkdir -p almost_git/.git/objects && |
| 465 | mkdir -p almost_git/.git/refs && |
| 466 | cat >almost_git/.git/HEAD <<-\EOF && |
| 467 | garbage |
| 468 | EOF |
| 469 | cp -r almost_git/.git/ almost_bare_git && |
| 470 | mkdir almost_submodule/ && |
| 471 | cat >almost_submodule/.git <<-\EOF && |
| 472 | garbage |
| 473 | EOF |
| 474 | test_when_finished "rm -rf almost_*" && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 475 | git clean -f -d && |
| 476 | test_path_is_missing almost_git && |
| 477 | test_path_is_missing almost_bare_git && |
| 478 | test_path_is_missing almost_submodule |
| 479 | ' |
| 480 | |
| 481 | test_expect_success 'should not clean submodules' ' |
| 482 | rm -fr repo to_clean sub1 sub2 && |
| 483 | mkdir repo to_clean && |
| 484 | ( |
| 485 | cd repo && |
| 486 | git init && |
| 487 | test_commit msg hello.world |
| 488 | ) && |
Taylor Blau | 0d3beb7 | 2022-07-29 15:21:40 -0400 | [diff] [blame] | 489 | test_config_global protocol.file.allow always && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 490 | git submodule add ./repo/.git sub1 && |
| 491 | git commit -m "sub1" && |
| 492 | git branch before_sub2 && |
| 493 | git submodule add ./repo/.git sub2 && |
| 494 | git commit -m "sub2" && |
| 495 | git checkout before_sub2 && |
| 496 | >to_clean/should_clean.this && |
| 497 | git clean -f -d && |
| 498 | test_path_is_file repo/.git/index && |
| 499 | test_path_is_file repo/hello.world && |
| 500 | test_path_is_file sub1/.git && |
| 501 | test_path_is_file sub1/hello.world && |
| 502 | test_path_is_file sub2/.git && |
| 503 | test_path_is_file sub2/hello.world && |
| 504 | test_path_is_missing to_clean |
| 505 | ' |
| 506 | |
Stefan Beller | cadfbef | 2016-05-03 11:54:32 -0700 | [diff] [blame] | 507 | test_expect_success POSIXPERM,SANITY 'should avoid cleaning possible submodules' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 508 | rm -fr to_clean possible_sub1 && |
| 509 | mkdir to_clean possible_sub1 && |
| 510 | test_when_finished "rm -rf possible_sub*" && |
| 511 | echo "gitdir: foo" >possible_sub1/.git && |
| 512 | >possible_sub1/hello.world && |
| 513 | chmod 0 possible_sub1/.git && |
| 514 | >to_clean/should_clean.this && |
| 515 | git clean -f -d && |
| 516 | test_path_is_file possible_sub1/.git && |
| 517 | test_path_is_file possible_sub1/hello.world && |
| 518 | test_path_is_missing to_clean |
| 519 | ' |
| 520 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 521 | test_expect_success 'nested (empty) git should be kept' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 522 | rm -fr empty_repo to_clean && |
| 523 | git init empty_repo && |
| 524 | mkdir to_clean && |
| 525 | >to_clean/should_clean.this && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 526 | # Note that we put the expect file in the .git directory so that it |
| 527 | # does not get cleaned. |
| 528 | find empty_repo | sort >.git/expect && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 529 | git clean -f -d && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 530 | find empty_repo | sort >actual && |
| 531 | test_cmp .git/expect actual && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 532 | test_path_is_missing to_clean |
| 533 | ' |
| 534 | |
| 535 | test_expect_success 'nested bare repositories should be cleaned' ' |
| 536 | rm -fr bare1 bare2 subdir && |
| 537 | git init --bare bare1 && |
| 538 | git clone --local --bare . bare2 && |
| 539 | mkdir subdir && |
| 540 | cp -r bare2 subdir/bare3 && |
| 541 | git clean -f -d && |
| 542 | test_path_is_missing bare1 && |
| 543 | test_path_is_missing bare2 && |
| 544 | test_path_is_missing subdir |
| 545 | ' |
| 546 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 547 | test_expect_failure 'nested (empty) bare repositories should be cleaned even when in .git' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 548 | rm -fr strange_bare && |
| 549 | mkdir strange_bare && |
| 550 | git init --bare strange_bare/.git && |
| 551 | git clean -f -d && |
| 552 | test_path_is_missing strange_bare |
| 553 | ' |
| 554 | |
| 555 | test_expect_failure 'nested (non-empty) bare repositories should be cleaned even when in .git' ' |
| 556 | rm -fr strange_bare && |
| 557 | mkdir strange_bare && |
| 558 | git clone --local --bare . strange_bare/.git && |
| 559 | git clean -f -d && |
| 560 | test_path_is_missing strange_bare |
| 561 | ' |
| 562 | |
Elijah Newren | 09487f2 | 2019-09-17 09:35:02 -0700 | [diff] [blame] | 563 | test_expect_success 'giving path in nested git work tree will NOT remove it' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 564 | rm -fr repo && |
| 565 | mkdir repo && |
| 566 | ( |
| 567 | cd repo && |
| 568 | git init && |
| 569 | mkdir -p bar/baz && |
| 570 | test_commit msg bar/baz/hello.world |
| 571 | ) && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 572 | find repo | sort >expect && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 573 | git clean -f -d repo/bar/baz && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 574 | find repo | sort >actual && |
| 575 | test_cmp expect actual |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 576 | ' |
| 577 | |
| 578 | test_expect_success 'giving path to nested .git will not remove it' ' |
| 579 | rm -fr repo && |
| 580 | mkdir repo untracked && |
| 581 | ( |
| 582 | cd repo && |
| 583 | git init && |
| 584 | test_commit msg hello.world |
| 585 | ) && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 586 | find repo | sort >expect && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 587 | git clean -f -d repo/.git && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 588 | find repo | sort >actual && |
| 589 | test_cmp expect actual && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 590 | test_path_is_dir untracked/ |
| 591 | ' |
| 592 | |
Elijah Newren | 09487f2 | 2019-09-17 09:35:02 -0700 | [diff] [blame] | 593 | test_expect_success 'giving path to nested .git/ will NOT remove contents' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 594 | rm -fr repo untracked && |
| 595 | mkdir repo untracked && |
| 596 | ( |
| 597 | cd repo && |
| 598 | git init && |
| 599 | test_commit msg hello.world |
| 600 | ) && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 601 | find repo | sort >expect && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 602 | git clean -f -d repo/.git/ && |
Patrick Steinhardt | 390c5b0 | 2023-11-02 09:47:06 +0100 | [diff] [blame] | 603 | find repo | sort >actual && |
| 604 | test_cmp expect actual && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 605 | test_path_is_dir untracked/ |
| 606 | ' |
| 607 | |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 608 | test_expect_success 'force removal of nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 609 | rm -fr foo bar baz && |
| 610 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 611 | ( |
| 612 | cd foo && |
| 613 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 614 | test_commit nested hello.world |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 615 | ) && |
| 616 | ( |
| 617 | cd bar && |
| 618 | >goodbye.people |
| 619 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 620 | ( |
| 621 | cd baz/boo && |
| 622 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 623 | test_commit deeply.nested deeper.world |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 624 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 625 | git clean -f -f -d && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 626 | test_path_is_missing foo && |
| 627 | test_path_is_missing bar && |
| 628 | test_path_is_missing baz |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 629 | ' |
| 630 | |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 631 | test_expect_success 'git clean -e' ' |
| 632 | rm -fr repo && |
| 633 | mkdir repo && |
| 634 | ( |
| 635 | cd repo && |
| 636 | git init && |
Brandon Casey | 84d6940 | 2010-09-15 15:58:22 -0500 | [diff] [blame] | 637 | touch known 1 2 3 && |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 638 | git add known && |
| 639 | git clean -f -e 1 -e 2 && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 640 | test_path_exists 1 && |
| 641 | test_path_exists 2 && |
| 642 | test_path_is_missing 3 && |
| 643 | test_path_exists known |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 644 | ) |
| 645 | ' |
| 646 | |
Alex Riesen | 0235017 | 2011-04-01 10:29:16 +0200 | [diff] [blame] | 647 | test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' |
| 648 | mkdir foo && |
| 649 | chmod a= foo && |
| 650 | git clean -dfx foo && |
Abraham Samuel Adekunle | 77af53f | 2024-10-09 18:22:02 +0000 | [diff] [blame] | 651 | test_path_is_missing foo |
Alex Riesen | 0235017 | 2011-04-01 10:29:16 +0200 | [diff] [blame] | 652 | ' |
| 653 | |
Jeff King | cf424f5 | 2014-03-10 16:37:30 -0400 | [diff] [blame] | 654 | test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' |
| 655 | mkdir -p foo && |
| 656 | mkdir -p foobar && |
| 657 | git clean -df foobar && |
| 658 | test_path_is_dir foo && |
| 659 | test_path_is_missing foobar |
| 660 | ' |
| 661 | |
| 662 | test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' ' |
| 663 | mkdir -p foo && |
| 664 | mkdir -p foobar && |
| 665 | git clean -df foo && |
| 666 | test_path_is_missing foo && |
| 667 | test_path_is_dir foobar |
| 668 | ' |
| 669 | |
Samuel Lijin | 6b1db43 | 2017-05-23 06:09:37 -0400 | [diff] [blame] | 670 | test_expect_success 'git clean -d skips untracked dirs containing ignored files' ' |
Samuel Lijin | b3487cc | 2017-05-18 04:21:49 -0400 | [diff] [blame] | 671 | echo /foo/bar >.gitignore && |
| 672 | echo ignoreme >>.gitignore && |
| 673 | rm -rf foo && |
| 674 | mkdir -p foo/a/aa/aaa foo/b/bb/bbb && |
| 675 | touch foo/bar foo/baz foo/a/aa/ignoreme foo/b/ignoreme foo/b/bb/1 foo/b/bb/2 && |
| 676 | git clean -df && |
| 677 | test_path_is_dir foo && |
| 678 | test_path_is_file foo/bar && |
| 679 | test_path_is_missing foo/baz && |
| 680 | test_path_is_file foo/a/aa/ignoreme && |
| 681 | test_path_is_missing foo/a/aa/aaa && |
| 682 | test_path_is_file foo/b/ignoreme && |
| 683 | test_path_is_missing foo/b/bb |
| 684 | ' |
| 685 | |
Elijah Newren | 09487f2 | 2019-09-17 09:35:02 -0700 | [diff] [blame] | 686 | test_expect_success 'git clean -d skips nested repo containing ignored files' ' |
SZEDER Gábor | 502c386 | 2019-08-25 20:59:18 +0200 | [diff] [blame] | 687 | test_when_finished "rm -rf nested-repo-with-ignored-file" && |
| 688 | |
| 689 | git init nested-repo-with-ignored-file && |
| 690 | ( |
| 691 | cd nested-repo-with-ignored-file && |
| 692 | >file && |
| 693 | git add file && |
| 694 | git commit -m Initial && |
| 695 | |
| 696 | # This file is ignored by a .gitignore rule in the outer repo |
| 697 | # added in the previous test. |
| 698 | >ignoreme |
| 699 | ) && |
| 700 | |
| 701 | git clean -fd && |
| 702 | |
| 703 | test_path_is_file nested-repo-with-ignored-file/.git/index && |
| 704 | test_path_is_file nested-repo-with-ignored-file/ignoreme && |
| 705 | test_path_is_file nested-repo-with-ignored-file/file |
| 706 | ' |
| 707 | |
Elijah Newren | 89a1f4a | 2019-09-17 09:34:58 -0700 | [diff] [blame] | 708 | test_expect_success 'git clean handles being told what to clean' ' |
Elijah Newren | 7541cc5 | 2019-09-17 09:34:53 -0700 | [diff] [blame] | 709 | mkdir -p d1 d2 && |
| 710 | touch d1/ut d2/ut && |
| 711 | git clean -f */ut && |
| 712 | test_path_is_missing d1/ut && |
| 713 | test_path_is_missing d2/ut |
| 714 | ' |
| 715 | |
Elijah Newren | 404ebce | 2019-09-17 09:34:56 -0700 | [diff] [blame] | 716 | test_expect_success 'git clean handles being told what to clean, with -d' ' |
Elijah Newren | 7541cc5 | 2019-09-17 09:34:53 -0700 | [diff] [blame] | 717 | mkdir -p d1 d2 && |
| 718 | touch d1/ut d2/ut && |
| 719 | git clean -ffd */ut && |
| 720 | test_path_is_missing d1/ut && |
| 721 | test_path_is_missing d2/ut |
| 722 | ' |
| 723 | |
Elijah Newren | 89a1f4a | 2019-09-17 09:34:58 -0700 | [diff] [blame] | 724 | test_expect_success 'git clean works if a glob is passed without -d' ' |
Elijah Newren | 7541cc5 | 2019-09-17 09:34:53 -0700 | [diff] [blame] | 725 | mkdir -p d1 d2 && |
| 726 | touch d1/ut d2/ut && |
| 727 | git clean -f "*ut" && |
| 728 | test_path_is_missing d1/ut && |
| 729 | test_path_is_missing d2/ut |
| 730 | ' |
| 731 | |
Elijah Newren | 404ebce | 2019-09-17 09:34:56 -0700 | [diff] [blame] | 732 | test_expect_success 'git clean works if a glob is passed with -d' ' |
Elijah Newren | 7541cc5 | 2019-09-17 09:34:53 -0700 | [diff] [blame] | 733 | mkdir -p d1 d2 && |
| 734 | touch d1/ut d2/ut && |
| 735 | git clean -ffd "*ut" && |
| 736 | test_path_is_missing d1/ut && |
| 737 | test_path_is_missing d2/ut |
| 738 | ' |
| 739 | |
Johannes Schindelin | b09364c | 2019-07-18 02:30:33 -0700 | [diff] [blame] | 740 | test_expect_success MINGW 'handle clean & core.longpaths = false nicely' ' |
| 741 | test_config core.longpaths false && |
| 742 | a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && |
| 743 | mkdir -p $a50$a50/$a50$a50/$a50$a50 && |
| 744 | : >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" && |
| 745 | # create a temporary outside the working tree to hide from "git clean" |
| 746 | test_must_fail git clean -xdf 2>.git/err && |
| 747 | # grepping for a strerror string is unportable but it is OK here with |
| 748 | # MINGW prereq |
Patrick Steinhardt | 106834e | 2024-10-09 15:25:18 +0200 | [diff] [blame] | 749 | test_grep -e "too long" -e "No such file or directory" .git/err |
Johannes Schindelin | b09364c | 2019-07-18 02:30:33 -0700 | [diff] [blame] | 750 | ' |
| 751 | |
Elijah Newren | 2270533 | 2020-01-16 20:21:54 +0000 | [diff] [blame] | 752 | test_expect_success 'clean untracked paths by pathspec' ' |
Derrick Stolee | f365bf4 | 2020-01-16 20:21:53 +0000 | [diff] [blame] | 753 | git init untracked && |
| 754 | mkdir untracked/dir && |
| 755 | echo >untracked/dir/file.txt && |
| 756 | git -C untracked clean -f dir/file.txt && |
| 757 | ls untracked/dir >actual && |
| 758 | test_must_be_empty actual |
| 759 | ' |
| 760 | |
Elijah Newren | aa6e1b2 | 2021-05-12 17:28:19 +0000 | [diff] [blame] | 761 | test_expect_success 'avoid traversing into ignored directories' ' |
Elijah Newren | 2e4e43a | 2021-05-12 17:28:17 +0000 | [diff] [blame] | 762 | test_when_finished rm -f output error trace.* && |
| 763 | test_create_repo avoid-traversing-deep-hierarchy && |
| 764 | ( |
| 765 | cd avoid-traversing-deep-hierarchy && |
| 766 | |
| 767 | mkdir -p untracked/subdir/with/a && |
| 768 | >untracked/subdir/with/a/random-file.txt && |
| 769 | |
| 770 | GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ |
| 771 | git clean -ffdxn -e untracked |
| 772 | ) && |
| 773 | |
| 774 | # Make sure we only visited into the top-level directory, and did |
| 775 | # not traverse into the "untracked" subdirectory since it was excluded |
| 776 | grep data.*read_directo.*directories-visited trace.output | |
| 777 | cut -d "|" -f 9 >trace.relevant && |
| 778 | cat >trace.expect <<-EOF && |
| 779 | ..directories-visited:1 |
| 780 | EOF |
| 781 | test_cmp trace.expect trace.relevant |
| 782 | ' |
| 783 | |
Elijah Newren | dd55fc0 | 2021-05-12 17:28:20 +0000 | [diff] [blame] | 784 | test_expect_success 'traverse into directories that may have ignored entries' ' |
Elijah Newren | a97c7a8 | 2021-05-12 17:28:18 +0000 | [diff] [blame] | 785 | test_when_finished rm -f output && |
| 786 | test_create_repo need-to-traverse-into-hierarchy && |
| 787 | ( |
| 788 | cd need-to-traverse-into-hierarchy && |
| 789 | mkdir -p modules/foobar/src/generated && |
| 790 | > modules/foobar/src/generated/code.c && |
| 791 | > modules/foobar/Makefile && |
| 792 | echo "/modules/**/src/generated/" >.gitignore && |
| 793 | |
| 794 | git clean -fX modules/foobar >../output && |
| 795 | |
| 796 | grep Removing ../output && |
| 797 | |
| 798 | test_path_is_missing modules/foobar/src/generated/code.c && |
| 799 | test_path_is_file modules/foobar/Makefile |
| 800 | ) |
| 801 | ' |
| 802 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 803 | test_done |