git clean -X deletes ignored directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux