{"thread":{"id":"29485","subject":"[BUG] git clean -X skips a directory containing only ignored files","startedAt":"2012-01-30T23:36:13Z","lastAt":"2012-02-01T12:18:50Z","messageCount":5,"participants":["Paul Berry","Michael Schubert","Andrew Wong"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"183397","messageId":"CA+yLL67J-7U9z7HVvq5wTc1g4_UCtqYfEyqdt7XR5zDqvQN5NA@mail.gmail.com","threadId":"29485","inReplyTo":null,"subject":"[BUG] git clean -X skips a directory containing only ignored files","fromName":"Paul Berry","fromEmail":"stereotype441@gmail.com","sentAt":"2012-01-30T23:36:13Z","receivedAt":"2012-01-30T23:36:13Z","isPatch":false,"sender":{"key":"stereotype441@gmail.com","avatar":null},"body":"I am trying to use \"git clean -X\" to remove object files (which\nare gitignored) from my source tree, but it appears to miss\nobject files that are in a subdirectory without any git-tracked\nfiles:\n\n$ git init test\nInitialized empty Git repository in /home/pberry/tmp/test/.git/\n$ cd test\n$ mkdir foo\n$ touch foo/bar.o\n$ echo '*.o' > .gitignore\n$ git add .gitignore\n$ git commit -mgitignore\n[master (root-commit) 6b5ffcb] gitignore\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 .gitignore\n$ git status\n# On branch master\nnothing to commit (working directory clean)\n$ git clean -d -X -f\n$ ls foo\nbar.o\n\nIt seems to me that bar.o should have been removed, because\naccording to the git-clean docs, -X means \"Remove only files\nignored by git\", and bar.o is definitely being ignored by git.\n\n\nIt looks like a very similar bug was reported back in 2010, but\nnot fixed:\nhttp://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.\nI've confirmed that the workaround mentioned by Jonathan Nieder\nin that thread fixes my problem too (removing \"dir.flags |=\nDIR_SHOW_OTHER_DIRECTORIES;\" from builtin/clean.c).  However I'm\nguessing from Jonathan's comments that it would be better to fix\nthis bug elsewhere (somewhere in dir.c perhaps).\n\nIs anyone interested in following up on this old bug?\nAlternatively, if someone could give me some guidance as to the\nbest way to go about fixing this bug, I would be glad to submit a\npatch.\n\nThanks,\n\nPaul\n"},{"id":"183416","messageId":"4F27FF01.6040706@elegosoft.com","threadId":"29485","inReplyTo":"CA+yLL67J-7U9z7HVvq5wTc1g4_UCtqYfEyqdt7XR5zDqvQN5NA@mail.gmail.com","subject":"Re: [BUG] git clean -X skips a directory containing only ignored files","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-01-31T14:47:29Z","receivedAt":"2012-01-31T14:47:29Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 01/31/2012 12:36 AM, Paul Berry wrote:\n> I am trying to use \"git clean -X\" to remove object files (which\n> are gitignored) from my source tree, but it appears to miss\n> object files that are in a subdirectory without any git-tracked\n> files:\n> \n> $ git init test\n> Initialized empty Git repository in /home/pberry/tmp/test/.git/\n> $ cd test\n> $ mkdir foo\n> $ touch foo/bar.o\n> $ echo '*.o' > .gitignore\n> $ git add .gitignore\n> $ git commit -mgitignore\n> [master (root-commit) 6b5ffcb] gitignore\n>  1 files changed, 1 insertions(+), 0 deletions(-)\n>  create mode 100644 .gitignore\n> $ git status\n> # On branch master\n> nothing to commit (working directory clean)\n> $ git clean -d -X -f\n> $ ls foo\n> bar.o\n> \n> It seems to me that bar.o should have been removed, because\n> according to the git-clean docs, -X means \"Remove only files\n> ignored by git\", and bar.o is definitely being ignored by git.\n> \n> \n> It looks like a very similar bug was reported back in 2010, but\n> not fixed:\n> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.\n> I've confirmed that the workaround mentioned by Jonathan Nieder\n> in that thread fixes my problem too (removing \"dir.flags |=\n> DIR_SHOW_OTHER_DIRECTORIES;\" from builtin/clean.c).  However I'm\n> guessing from Jonathan's comments that it would be better to fix\n> this bug elsewhere (somewhere in dir.c perhaps).\n\nRemoving DIR_SHOW_OTHER_DIRECTORIES just happens to not trigger\nthis particular \"bug\" but breaks pretty much everything else.\n\nAs a workaround, you could explicitly add the directory to your\ngitignore file.\n\nHere's a test:\n\n-- >8 --\n\nSubject: [PATCH] t7300-clean: show known breakage with \"git clean -d -X\"\n\n\"git clean -d -X\" fails for directories containing only untracked files.\nExample:\n\n\t$ ls -R .\n\t.:\n\tfoo\n\t./foo:\n\tbar.o\n\t$ cat .gitignore\n\t*.o\n\t$ git clean -d -X -f\n\t$ ! test -d foo || echo fail\n\nReported-by: Paul Berry <stereotype441@gmail.com>\nSigned-off-by: Michael Schubert <mschub@elegosoft.com>\n---\n t/t7300-clean.sh |    7 +++++++\n 1 files changed, 7 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\nindex 800b536..0b6d545 100755\n--- a/t/t7300-clean.sh\n+++ b/t/t7300-clean.sh\n@@ -332,6 +332,13 @@ test_expect_success 'git clean -d -X' '\n \n '\n \n+test_expect_failure 'git clean -d -X' '\n+  mkdir -p a/b &&\n+  touch a/b/c.o &&\n+  git clean -d -X &&\n+  ! test -d a\n+'\n+\n test_expect_success 'clean.requireForce defaults to true' '\n \n \tgit config --unset clean.requireForce &&\n-- \n1.7.9.174.g356eff6\n"},{"id":"183419","messageId":"4F2814D7.8030504@sohovfx.com","threadId":"29485","inReplyTo":"CA+yLL67J-7U9z7HVvq5wTc1g4_UCtqYfEyqdt7XR5zDqvQN5NA@mail.gmail.com","subject":"Re: [BUG] git clean -X skips a directory containing only ignored files","fromName":"Andrew Wong","fromEmail":"andrew.w@sohovfx.com","sentAt":"2012-01-31T16:20:39Z","receivedAt":"2012-01-31T16:20:39Z","isPatch":false,"sender":{"key":"andrew.w@sohovfx.com","avatar":null},"body":"I think there were a bit of discussions on this issues just while ago too:\nhttp://thread.gmane.org/gmane.comp.version-control.git/188605\n\n\nOn 01/30/2012 06:36 PM, Paul Berry wrote:\n> I am trying to use \"git clean -X\" to remove object files (which\n> are gitignored) from my source tree, but it appears to miss\n> object files that are in a subdirectory without any git-tracked\n> files:\n>\n> $ git init test\n> Initialized empty Git repository in /home/pberry/tmp/test/.git/\n> $ cd test\n> $ mkdir foo\n> $ touch foo/bar.o\n> $ echo '*.o' > .gitignore\n> $ git add .gitignore\n> $ git commit -mgitignore\n> [master (root-commit) 6b5ffcb] gitignore\n>  1 files changed, 1 insertions(+), 0 deletions(-)\n>  create mode 100644 .gitignore\n> $ git status\n> # On branch master\n> nothing to commit (working directory clean)\n> $ git clean -d -X -f\n> $ ls foo\n> bar.o\n>\n> It seems to me that bar.o should have been removed, because\n> according to the git-clean docs, -X means \"Remove only files\n> ignored by git\", and bar.o is definitely being ignored by git.\n>\n>\n> It looks like a very similar bug was reported back in 2010, but\n> not fixed:\n> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.\n> I've confirmed that the workaround mentioned by Jonathan Nieder\n> in that thread fixes my problem too (removing \"dir.flags |=\n> DIR_SHOW_OTHER_DIRECTORIES;\" from builtin/clean.c).  However I'm\n> guessing from Jonathan's comments that it would be better to fix\n> this bug elsewhere (somewhere in dir.c perhaps).\n>\n> Is anyone interested in following up on this old bug?\n> Alternatively, if someone could give me some guidance as to the\n> best way to go about fixing this bug, I would be glad to submit a\n> patch.\n>\n> Thanks,\n>\n> Paul\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>   \n"},{"id":"183420","messageId":"CA+yLL65OWXMGnftKzpLLnESd_-Ogyj_UXg2m7h0FSyriuh91pw@mail.gmail.com","threadId":"29485","inReplyTo":"4F27FF01.6040706@elegosoft.com","subject":"Re: [BUG] git clean -X skips a directory containing only ignored files","fromName":"Paul Berry","fromEmail":"stereotype441@gmail.com","sentAt":"2012-01-31T17:39:02Z","receivedAt":"2012-01-31T17:39:02Z","isPatch":false,"sender":{"key":"stereotype441@gmail.com","avatar":null},"body":"On 31 January 2012 06:47, Michael Schubert <mschub@elegosoft.com> wrote:\n> On 01/31/2012 12:36 AM, Paul Berry wrote:\n>> I am trying to use \"git clean -X\" to remove object files (which\n>> are gitignored) from my source tree, but it appears to miss\n>> object files that are in a subdirectory without any git-tracked\n>> files:\n>>\n>> $ git init test\n>> Initialized empty Git repository in /home/pberry/tmp/test/.git/\n>> $ cd test\n>> $ mkdir foo\n>> $ touch foo/bar.o\n>> $ echo '*.o' > .gitignore\n>> $ git add .gitignore\n>> $ git commit -mgitignore\n>> [master (root-commit) 6b5ffcb] gitignore\n>>  1 files changed, 1 insertions(+), 0 deletions(-)\n>>  create mode 100644 .gitignore\n>> $ git status\n>> # On branch master\n>> nothing to commit (working directory clean)\n>> $ git clean -d -X -f\n>> $ ls foo\n>> bar.o\n>>\n>> It seems to me that bar.o should have been removed, because\n>> according to the git-clean docs, -X means \"Remove only files\n>> ignored by git\", and bar.o is definitely being ignored by git.\n>>\n>>\n>> It looks like a very similar bug was reported back in 2010, but\n>> not fixed:\n>> http://git.661346.n2.nabble.com/BUG-git-clean-X-behaviour-when-gitignore-has-sub-directory-entries-td5575307.html.\n>> I've confirmed that the workaround mentioned by Jonathan Nieder\n>> in that thread fixes my problem too (removing \"dir.flags |=\n>> DIR_SHOW_OTHER_DIRECTORIES;\" from builtin/clean.c).  However I'm\n>> guessing from Jonathan's comments that it would be better to fix\n>> this bug elsewhere (somewhere in dir.c perhaps).\n>\n> Removing DIR_SHOW_OTHER_DIRECTORIES just happens to not trigger\n> this particular \"bug\" but breaks pretty much everything else.\n\nYeah, I had a feeling that might be the case.\n\n>\n> As a workaround, you could explicitly add the directory to your\n> gitignore file.\n>\n> Here's a test:\n>\n> -- >8 --\n>\n> Subject: [PATCH] t7300-clean: show known breakage with \"git clean -d -X\"\n>\n> \"git clean -d -X\" fails for directories containing only untracked files.\n> Example:\n>\n>        $ ls -R .\n>        .:\n>        foo\n>        ./foo:\n>        bar.o\n>        $ cat .gitignore\n>        *.o\n>        $ git clean -d -X -f\n>        $ ! test -d foo || echo fail\n>\n> Reported-by: Paul Berry <stereotype441@gmail.com>\n> Signed-off-by: Michael Schubert <mschub@elegosoft.com>\n> ---\n>  t/t7300-clean.sh |    7 +++++++\n>  1 files changed, 7 insertions(+), 0 deletions(-)\n>\n> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\n> index 800b536..0b6d545 100755\n> --- a/t/t7300-clean.sh\n> +++ b/t/t7300-clean.sh\n> @@ -332,6 +332,13 @@ test_expect_success 'git clean -d -X' '\n>\n>  '\n>\n> +test_expect_failure 'git clean -d -X' '\n> +  mkdir -p a/b &&\n> +  touch a/b/c.o &&\n> +  git clean -d -X &&\n> +  ! test -d a\n\nThanks for the test case.  BTW, you might consider changing this last\nline to \"! test -f a/b/c.o\".  Reasoning: it is clear from the docs\nthat c.o should be removed by \"git clean -X\" (since c.o is an ignored\nfile).  It is less clear whether the directories a and a/b should be\nremoved by \"git clean -X\", since those directories are not in\nthemselves ignored, only their contents.\n\n> +'\n> +\n>  test_expect_success 'clean.requireForce defaults to true' '\n>\n>        git config --unset clean.requireForce &&\n> --\n> 1.7.9.174.g356eff6\n"},{"id":"183468","messageId":"4F292DAA.1000107@elegosoft.com","threadId":"29485","inReplyTo":"4F2814D7.8030504@sohovfx.com","subject":"Re: [BUG] git clean -X skips a directory containing only ignored files","fromName":"Michael Schubert","fromEmail":"mschub@elegosoft.com","sentAt":"2012-02-01T12:18:50Z","receivedAt":"2012-02-01T12:18:50Z","isPatch":false,"sender":{"key":"mschub@elegosoft.com","avatar":null},"body":"On 01/31/2012 05:20 PM, Andrew Wong wrote:\n> I think there were a bit of discussions on this issues just while ago too:\n> http://thread.gmane.org/gmane.comp.version-control.git/188605\n\nThanks, missed that.\n\nBelow a patch with an update for Documentation/git-clean.txt - I'm not sure\nif the issue should be described more accurate.?\n\n-- >8 --\n\nSubject: [PATCH] Documentation: tell about \"git clean -Xd\" bug\n\n\"git clean -Xd\" doesn't work as expected (delete all ignored files and\nuntracked directories), because Git's dir subsystem is skipping\ndirectories which both aren't explicitly ignored and don't hold any\ntracked files.\n\nTell about this limitation in BUGS.\n\nSigned-off-by: Michael Schubert <mschub@elegosoft.com>\n---\n Documentation/git-clean.txt |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt\nindex 79fb984..888c07d 100644\n--- a/Documentation/git-clean.txt\n+++ b/Documentation/git-clean.txt\n@@ -29,7 +29,8 @@ OPTIONS\n \tRemove untracked directories in addition to untracked files.\n \tIf an untracked directory is managed by a different git\n \trepository, it is not removed by default.  Use -f option twice\n-\tif you really want to remove such a directory.\n+\tif you really want to remove such a directory.  Also see BUGS\n+\tbelow.\n \n -f::\n --force::\n@@ -63,6 +64,11 @@ OPTIONS\n \tRemove only files ignored by git.  This may be useful to rebuild\n \teverything from scratch, but keep manually created files.\n \n+BUGS\n+----\n+'git-clean -Xd' doesn't work as expected for directories which don't hold\n+any tracked files and aren't explicitly ignored either.\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\n-- \n1.7.9.174.g356eff6\n"}]}