]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7300-clean.sh
Sync with 2.31.5
[thirdparty/git.git] / t / t7300-clean.sh
index ff0a0f1dbb9aee4bd72ffc0836198192506b7c72..c975eb54d234d77b2f13df2a96acd4cbefb93865 100755 (executable)
@@ -747,4 +747,46 @@ test_expect_success 'clean untracked paths by pathspec' '
        test_must_be_empty actual
 '
 
+test_expect_success 'avoid traversing into ignored directories' '
+       test_when_finished rm -f output error trace.* &&
+       test_create_repo avoid-traversing-deep-hierarchy &&
+       (
+               cd avoid-traversing-deep-hierarchy &&
+
+               mkdir -p untracked/subdir/with/a &&
+               >untracked/subdir/with/a/random-file.txt &&
+
+               GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
+               git clean -ffdxn -e untracked
+       ) &&
+
+       # Make sure we only visited into the top-level directory, and did
+       # not traverse into the "untracked" subdirectory since it was excluded
+       grep data.*read_directo.*directories-visited trace.output |
+               cut -d "|" -f 9 >trace.relevant &&
+       cat >trace.expect <<-EOF &&
+        ..directories-visited:1
+       EOF
+       test_cmp trace.expect trace.relevant
+'
+
+test_expect_success 'traverse into directories that may have ignored entries' '
+       test_when_finished rm -f output &&
+       test_create_repo need-to-traverse-into-hierarchy &&
+       (
+               cd need-to-traverse-into-hierarchy &&
+               mkdir -p modules/foobar/src/generated &&
+               > modules/foobar/src/generated/code.c &&
+               > modules/foobar/Makefile &&
+               echo "/modules/**/src/generated/" >.gitignore &&
+
+               git clean -fX modules/foobar >../output &&
+
+               grep Removing ../output &&
+
+               test_path_is_missing modules/foobar/src/generated/code.c &&
+               test_path_is_file modules/foobar/Makefile
+       )
+'
+
 test_done