On Mon, Nov 21, 2011 at 3:03 PM, Jay Soffian [off-list ref] wrote:
On Mon, Nov 21, 2011 at 2:28 PM, Junio C Hamano [off-list ref] wrote:
quoted
"clean" without "-x" is meant to preserve untracked but expendable paths
(e.g. build products), so if something is removed that is untracked but
matches the ignore pattern, then that is a bug to be fixed. Care to roll
a patch to fix it?
Okay, just confirming it is a bug. I'll add this e-mail to my todo
list, but I don't have time for a patch anytime soon.
I think the fix is in dir.c (treat_directory), but I'm not sure how yet.
How's this for starters?
-- >8 --
Subject: [PATCH] clean: Test known breakage of .gitignore and -d
git-clean -d is used to remove untracked directories. If the
directory still contains .gitignored files it should not be removed.
But git is broken here if neither the ignored files nor the directory
are explicitly ignored.
Document this known breakage with a test for both cases.
Noticed-by: Jay Soffian [off-list ref]
Signed-off-by: Phil Hord <redacted>
---
t/t7300-clean.sh | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 800b536..e29e383 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -14,6 +14,7 @@ test_expect_success 'setup' '
mkdir -p src &&
touch src/part1.c Makefile &&
echo build >.gitignore &&
+ echo /foo/bar >>.gitignore &&
echo \*.o >>.gitignore &&
git add . &&
git commit -m setup &&
@@ -264,6 +265,20 @@ test_expect_success 'git clean -d src/ examples/' '
'
+test_expect_failure 'git clean -d leaves .gitignored files alone' '
+
+ mkdir -p objs foo/bar &&
+ touch objs/foo.o &&
+ touch foo/gone &&
+ touch foo/bar/baz &&
+ git clean -nd &&
+ git clean -d &&
+ test ! -f foo/gone &&
+ test -f foo/bar/baz &&
+ test -f objs/foo.o
+
+'
+
test_expect_success 'git clean -x' '
mkdir -p build docs &&
--
1.7.8.rc4