All of lore.kernel.org
 help / color / mirror / Atom feed
* git clean -X deletes ignored directory
@ 2020-10-07 19:32 Yves Fischer
  0 siblings, 0 replies; only message in thread
From: Yves Fischer @ 2020-10-07 19:32 UTC (permalink / raw)
  To: git

Hello everyone,

I found a behavior with git-clean that appears to be unexpected.

It is related to the change in 95c11ec which, if I read the history correctly, got later corrected in cada730.

Example (in git repo after build):
======
./git init test
cd test
mkdir ignored-subdir
touch test.c test.o ignored-subdir/some-file
echo \*.o > .gitignore
echo ignored-subdir >> .gitignore 
../git add .
../git commit -m test
../git clean -X -d -n '*.o'
# Would remove ignored-subdir/  <--- why?
# Would remove test.o
======

In the example I would have expected that the "ignored-subdir" is not deleted because it's not matched by the path argument. The manpage of git-clean says:
> If any optional <path>... arguments are given, only those paths are affected.

I believe the issue is fixed in cada730 only for files. It seems to persist for directories.

The attached diff has a test that tries to cover this.

Kind regards,
Yves

----

diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index cb5e34d94c..77d834d34a 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -746,4 +746,49 @@ test_expect_success 'clean untracked paths by pathspec' '
        test_must_be_empty actual
 '
 
+# fixed by cada730
+test_expect_success 'git clean x1' '
+
+       git init clean-x1 &&
+       touch clean-x1/test.c clean-x1/test.o clean-x1/other-untracked-file &&
+       echo \*.o >> clean-x1/.gitignore &&
+       echo other-untracked-file >> clean-x1/.gitignore &&
+       git -C clean-x1 add . &&
+       git -C clean-x1 commit -m setup &&
+       git -C clean-x1 clean -X -d -f "*.o" &&
+       ! test -f clean-x1/test.o &&
+       test -f clean-x1/other-untracked-file
+
+'
+
+# fixed by cada730
+test_expect_success 'git clean x2' '
+
+       git init clean-x2 &&
+       touch clean-x2/test.c clean-x2/test.o clean-x2/other-untracked-file &&
+       echo \*.o >> clean-x2/.gitignore &&
+       echo other-untracked-file >> clean-x2/.gitignore &&
+       git -C clean-x2 add . &&
+       git -C clean-x2 commit -m setup &&
+       git -C clean-x2 clean -X -f "*.o" &&
+       ! test -f clean-x2/test.o &&
+       test -f clean-x2/other-untracked-file
+
+'
+
+test_expect_success 'git clean x3' '
+
+       git init clean-x3 &&
+       mkdir other-untracked-dir &&
+       touch clean-x3/test.c clean-x3/test.o clean-x3/other-untracked-dir/foo &&
+       echo \*.o >> clean-x3/.gitignore &&
+       echo other-untracked-dir >> clean-x3/.gitignore &&
+       git -C clean-x3 add . &&
+       git -C clean-x3 commit -m setup &&
+       git -C clean-x3 clean -X -f "*.o" &&
+       ! test -f clean-x3/test.o &&
+       test -f clean-x3/other-untracked-dir/foo
+
+'
+
 test_done

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-07 19:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 19:32 git clean -X deletes ignored directory Yves Fischer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.