git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yves Fischer" <yvesf@xapek.org>
To: git@vger.kernel.org
Subject: git clean -X deletes ignored directory
Date: Wed, 07 Oct 2020 19:32:22 +0000	[thread overview]
Message-ID: <995c4c10c68d39e84aa48ae967f81da6@xapek.org> (raw)

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

                 reply	other threads:[~2020-10-07 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=995c4c10c68d39e84aa48ae967f81da6@xapek.org \
    --to=yvesf@xapek.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).