* [BUG] git clean -X skips a directory containing only ignored files
@ 2012-01-30 23:36 Paul Berry
2012-01-31 14:47 ` Michael Schubert
2012-01-31 16:20 ` Andrew Wong
0 siblings, 2 replies; 5+ messages in thread
From: Paul Berry @ 2012-01-30 23:36 UTC (permalink / raw)
To: git
I am trying to use "git clean -X" to remove object files (which
are gitignored) from my source tree, but it appears to miss
object files that are in a subdirectory without any git-tracked
files:
$ git init test
Initialized empty Git repository in /home/pberry/tmp/test/.git/
$ cd test
$ mkdir foo
$ touch foo/bar.o
$ echo '*.o' > .gitignore
$ git add .gitignore
$ git commit -mgitignore
[master (root-commit) 6b5ffcb] gitignore
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
$ git status
# On branch master
nothing to commit (working directory clean)
$ git clean -d -X -f
$ ls foo
bar.o
It seems to me that bar.o should have been removed, because
according to the git-clean docs, -X means "Remove only files
ignored by git", and bar.o is definitely being ignored by git.
It looks like a very similar bug was reported back in 2010, but
not fixed:
http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.
I've confirmed that the workaround mentioned by Jonathan Nieder
in that thread fixes my problem too (removing "dir.flags |=
DIR_SHOW_OTHER_DIRECTORIES;" from builtin/clean.c). However I'm
guessing from Jonathan's comments that it would be better to fix
this bug elsewhere (somewhere in dir.c perhaps).
Is anyone interested in following up on this old bug?
Alternatively, if someone could give me some guidance as to the
best way to go about fixing this bug, I would be glad to submit a
patch.
Thanks,
Paul
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] git clean -X skips a directory containing only ignored files
2012-01-30 23:36 [BUG] git clean -X skips a directory containing only ignored files Paul Berry
@ 2012-01-31 14:47 ` Michael Schubert
2012-01-31 17:39 ` Paul Berry
2012-01-31 16:20 ` Andrew Wong
1 sibling, 1 reply; 5+ messages in thread
From: Michael Schubert @ 2012-01-31 14:47 UTC (permalink / raw)
To: Paul Berry; +Cc: git
On 01/31/2012 12:36 AM, Paul Berry wrote:
> I am trying to use "git clean -X" to remove object files (which
> are gitignored) from my source tree, but it appears to miss
> object files that are in a subdirectory without any git-tracked
> files:
>
> $ git init test
> Initialized empty Git repository in /home/pberry/tmp/test/.git/
> $ cd test
> $ mkdir foo
> $ touch foo/bar.o
> $ echo '*.o' > .gitignore
> $ git add .gitignore
> $ git commit -mgitignore
> [master (root-commit) 6b5ffcb] gitignore
> 1 files changed, 1 insertions(+), 0 deletions(-)
> create mode 100644 .gitignore
> $ git status
> # On branch master
> nothing to commit (working directory clean)
> $ git clean -d -X -f
> $ ls foo
> bar.o
>
> It seems to me that bar.o should have been removed, because
> according to the git-clean docs, -X means "Remove only files
> ignored by git", and bar.o is definitely being ignored by git.
>
>
> It looks like a very similar bug was reported back in 2010, but
> not fixed:
> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.
> I've confirmed that the workaround mentioned by Jonathan Nieder
> in that thread fixes my problem too (removing "dir.flags |=
> DIR_SHOW_OTHER_DIRECTORIES;" from builtin/clean.c). However I'm
> guessing from Jonathan's comments that it would be better to fix
> this bug elsewhere (somewhere in dir.c perhaps).
Removing DIR_SHOW_OTHER_DIRECTORIES just happens to not trigger
this particular "bug" but breaks pretty much everything else.
As a workaround, you could explicitly add the directory to your
gitignore file.
Here's a test:
-- >8 --
Subject: [PATCH] t7300-clean: show known breakage with "git clean -d -X"
"git clean -d -X" fails for directories containing only untracked files.
Example:
$ ls -R .
.:
foo
./foo:
bar.o
$ cat .gitignore
*.o
$ git clean -d -X -f
$ ! test -d foo || echo fail
Reported-by: Paul Berry <stereotype441@gmail.com>
Signed-off-by: Michael Schubert <mschub@elegosoft.com>
---
t/t7300-clean.sh | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 800b536..0b6d545 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -332,6 +332,13 @@ test_expect_success 'git clean -d -X' '
'
+test_expect_failure 'git clean -d -X' '
+ mkdir -p a/b &&
+ touch a/b/c.o &&
+ git clean -d -X &&
+ ! test -d a
+'
+
test_expect_success 'clean.requireForce defaults to true' '
git config --unset clean.requireForce &&
--
1.7.9.174.g356eff6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [BUG] git clean -X skips a directory containing only ignored files
2012-01-30 23:36 [BUG] git clean -X skips a directory containing only ignored files Paul Berry
2012-01-31 14:47 ` Michael Schubert
@ 2012-01-31 16:20 ` Andrew Wong
2012-02-01 12:18 ` Michael Schubert
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Wong @ 2012-01-31 16:20 UTC (permalink / raw)
To: Paul Berry; +Cc: git
I think there were a bit of discussions on this issues just while ago too:
http://thread.gmane.org/gmane.comp.version-control.git/188605
On 01/30/2012 06:36 PM, Paul Berry wrote:
> I am trying to use "git clean -X" to remove object files (which
> are gitignored) from my source tree, but it appears to miss
> object files that are in a subdirectory without any git-tracked
> files:
>
> $ git init test
> Initialized empty Git repository in /home/pberry/tmp/test/.git/
> $ cd test
> $ mkdir foo
> $ touch foo/bar.o
> $ echo '*.o' > .gitignore
> $ git add .gitignore
> $ git commit -mgitignore
> [master (root-commit) 6b5ffcb] gitignore
> 1 files changed, 1 insertions(+), 0 deletions(-)
> create mode 100644 .gitignore
> $ git status
> # On branch master
> nothing to commit (working directory clean)
> $ git clean -d -X -f
> $ ls foo
> bar.o
>
> It seems to me that bar.o should have been removed, because
> according to the git-clean docs, -X means "Remove only files
> ignored by git", and bar.o is definitely being ignored by git.
>
>
> It looks like a very similar bug was reported back in 2010, but
> not fixed:
> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.
> I've confirmed that the workaround mentioned by Jonathan Nieder
> in that thread fixes my problem too (removing "dir.flags |=
> DIR_SHOW_OTHER_DIRECTORIES;" from builtin/clean.c). However I'm
> guessing from Jonathan's comments that it would be better to fix
> this bug elsewhere (somewhere in dir.c perhaps).
>
> Is anyone interested in following up on this old bug?
> Alternatively, if someone could give me some guidance as to the
> best way to go about fixing this bug, I would be glad to submit a
> patch.
>
> Thanks,
>
> Paul
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] git clean -X skips a directory containing only ignored files
2012-01-31 14:47 ` Michael Schubert
@ 2012-01-31 17:39 ` Paul Berry
0 siblings, 0 replies; 5+ messages in thread
From: Paul Berry @ 2012-01-31 17:39 UTC (permalink / raw)
To: Michael Schubert; +Cc: git
On 31 January 2012 06:47, Michael Schubert <mschub@elegosoft.com> wrote:
> On 01/31/2012 12:36 AM, Paul Berry wrote:
>> I am trying to use "git clean -X" to remove object files (which
>> are gitignored) from my source tree, but it appears to miss
>> object files that are in a subdirectory without any git-tracked
>> files:
>>
>> $ git init test
>> Initialized empty Git repository in /home/pberry/tmp/test/.git/
>> $ cd test
>> $ mkdir foo
>> $ touch foo/bar.o
>> $ echo '*.o' > .gitignore
>> $ git add .gitignore
>> $ git commit -mgitignore
>> [master (root-commit) 6b5ffcb] gitignore
>> 1 files changed, 1 insertions(+), 0 deletions(-)
>> create mode 100644 .gitignore
>> $ git status
>> # On branch master
>> nothing to commit (working directory clean)
>> $ git clean -d -X -f
>> $ ls foo
>> bar.o
>>
>> It seems to me that bar.o should have been removed, because
>> according to the git-clean docs, -X means "Remove only files
>> ignored by git", and bar.o is definitely being ignored by git.
>>
>>
>> It looks like a very similar bug was reported back in 2010, but
>> not fixed:
>> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.
>> I've confirmed that the workaround mentioned by Jonathan Nieder
>> in that thread fixes my problem too (removing "dir.flags |=
>> DIR_SHOW_OTHER_DIRECTORIES;" from builtin/clean.c). However I'm
>> guessing from Jonathan's comments that it would be better to fix
>> this bug elsewhere (somewhere in dir.c perhaps).
>
> Removing DIR_SHOW_OTHER_DIRECTORIES just happens to not trigger
> this particular "bug" but breaks pretty much everything else.
Yeah, I had a feeling that might be the case.
>
> As a workaround, you could explicitly add the directory to your
> gitignore file.
>
> Here's a test:
>
> -- >8 --
>
> Subject: [PATCH] t7300-clean: show known breakage with "git clean -d -X"
>
> "git clean -d -X" fails for directories containing only untracked files.
> Example:
>
> $ ls -R .
> .:
> foo
> ./foo:
> bar.o
> $ cat .gitignore
> *.o
> $ git clean -d -X -f
> $ ! test -d foo || echo fail
>
> Reported-by: Paul Berry <stereotype441@gmail.com>
> Signed-off-by: Michael Schubert <mschub@elegosoft.com>
> ---
> t/t7300-clean.sh | 7 +++++++
> 1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
> index 800b536..0b6d545 100755
> --- a/t/t7300-clean.sh
> +++ b/t/t7300-clean.sh
> @@ -332,6 +332,13 @@ test_expect_success 'git clean -d -X' '
>
> '
>
> +test_expect_failure 'git clean -d -X' '
> + mkdir -p a/b &&
> + touch a/b/c.o &&
> + git clean -d -X &&
> + ! test -d a
Thanks for the test case. BTW, you might consider changing this last
line to "! test -f a/b/c.o". Reasoning: it is clear from the docs
that c.o should be removed by "git clean -X" (since c.o is an ignored
file). It is less clear whether the directories a and a/b should be
removed by "git clean -X", since those directories are not in
themselves ignored, only their contents.
> +'
> +
> test_expect_success 'clean.requireForce defaults to true' '
>
> git config --unset clean.requireForce &&
> --
> 1.7.9.174.g356eff6
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] git clean -X skips a directory containing only ignored files
2012-01-31 16:20 ` Andrew Wong
@ 2012-02-01 12:18 ` Michael Schubert
0 siblings, 0 replies; 5+ messages in thread
From: Michael Schubert @ 2012-02-01 12:18 UTC (permalink / raw)
To: Andrew Wong; +Cc: Paul Berry, git
On 01/31/2012 05:20 PM, Andrew Wong wrote:
> I think there were a bit of discussions on this issues just while ago too:
> http://thread.gmane.org/gmane.comp.version-control.git/188605
Thanks, missed that.
Below a patch with an update for Documentation/git-clean.txt - I'm not sure
if the issue should be described more accurate.?
-- >8 --
Subject: [PATCH] Documentation: tell about "git clean -Xd" bug
"git clean -Xd" doesn't work as expected (delete all ignored files and
untracked directories), because Git's dir subsystem is skipping
directories which both aren't explicitly ignored and don't hold any
tracked files.
Tell about this limitation in BUGS.
Signed-off-by: Michael Schubert <mschub@elegosoft.com>
---
Documentation/git-clean.txt | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index 79fb984..888c07d 100644
--- a/Documentation/git-clean.txt
+++ b/Documentation/git-clean.txt
@@ -29,7 +29,8 @@ OPTIONS
Remove untracked directories in addition to untracked files.
If an untracked directory is managed by a different git
repository, it is not removed by default. Use -f option twice
- if you really want to remove such a directory.
+ if you really want to remove such a directory. Also see BUGS
+ below.
-f::
--force::
@@ -63,6 +64,11 @@ OPTIONS
Remove only files ignored by git. This may be useful to rebuild
everything from scratch, but keep manually created files.
+BUGS
+----
+'git-clean -Xd' doesn't work as expected for directories which don't hold
+any tracked files and aren't explicitly ignored either.
+
GIT
---
Part of the linkgit:git[1] suite
--
1.7.9.174.g356eff6
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-02-01 12:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30 23:36 [BUG] git clean -X skips a directory containing only ignored files Paul Berry
2012-01-31 14:47 ` Michael Schubert
2012-01-31 17:39 ` Paul Berry
2012-01-31 16:20 ` Andrew Wong
2012-02-01 12:18 ` Michael Schubert
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).