{"thread":{"id":"28978","subject":"clean bug on ignored subdirectories with no tracked files?","startedAt":"2011-11-19T05:38:24Z","lastAt":"2011-12-01T23:35:52Z","messageCount":7,"participants":["Jay Soffian","Junio C Hamano","Phil Hord"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"179729","messageId":"CAG+J_Dxw00e_cr7i3R9DAbTrqZvJHYk2yeUa=xGKh+Zqqmp-SA@mail.gmail.com","threadId":"28978","inReplyTo":null,"subject":"clean bug on ignored subdirectories with no tracked files?","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2011-11-19T05:38:24Z","receivedAt":"2011-11-19T05:38:24Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"git init test_repo &&\ncd test_repo &&\nmkdir -p foo/bar &&\necho baz > foo/bar/baz &&\necho /foo/bar > .gitignore &&\ngit add .gitignore &&\ngit clean -n -d\n\nInitialized empty Git repository in .../test_repo/.git/\nWould remove foo/\n\nSeems surprising. The work-around is either using '/foo' in the\ntop-level .gitignore or adding a tracked file to the 'foo' directory.\n\nj.\n"},{"id":"179738","messageId":"7vy5vbj4rb.fsf@alter.siamese.dyndns.org","threadId":"28978","inReplyTo":"CAG+J_Dxw00e_cr7i3R9DAbTrqZvJHYk2yeUa=xGKh+Zqqmp-SA@mail.gmail.com","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-19T19:23:20Z","receivedAt":"2011-11-19T19:23:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jay Soffian <jaysoffian@gmail.com> writes:\n\n> git init test_repo &&\n> cd test_repo &&\n> mkdir -p foo/bar &&\n> echo baz > foo/bar/baz &&\n> echo /foo/bar > .gitignore &&\n> git add .gitignore &&\n> git clean -n -d\n>\n> Initialized empty Git repository in .../test_repo/.git/\n> Would remove foo/\n>\n> Seems surprising.\n\nYou said \"everythingthing in foo/bar is uninteresting and can be cleaned\",\nyou have one untracked file in \"foo/bar\" hierarchy, and you have nothing\nelse in \"foo/\" hierarchy.\n\nRemoving the uninteresting cruft as your .gitignore instructs Git makes\nthe entire \"foo/\" hierarchy devoid of any contents. I would *expect* Git\nto clean \"foo\" in this case.\n\nI've seen some \"surprising\" behaviour in \"git clean\" (which I do not use\nmyself, I do not consider part of \"my code\", and I am not surprised if it\nhas many bugs), but I fail to see what is surprising in your transcript.\n\nIt would be a different issue if you had \">foo/other\" before your \"clean\".\nThen \"foo/\" has \"foo/clean\" that is not declared to be uninteresting.\n"},{"id":"179796","messageId":"CAG+J_DwKeWntmi22vHS6CRud6Lo0P_+D5u5ih2Bbc50ekYji5w@mail.gmail.com","threadId":"28978","inReplyTo":"7vy5vbj4rb.fsf@alter.siamese.dyndns.org","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2011-11-21T18:51:50Z","receivedAt":"2011-11-21T18:51:50Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Sat, Nov 19, 2011 at 2:23 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jay Soffian <jaysoffian@gmail.com> writes:\n>\n>> git init test_repo &&\n>> cd test_repo &&\n>> mkdir -p foo/bar &&\n>> echo baz > foo/bar/baz &&\n>> echo /foo/bar > .gitignore &&\n>> git add .gitignore &&\n>> git clean -n -d\n>>\n>> Initialized empty Git repository in .../test_repo/.git/\n>> Would remove foo/\n>>\n>> Seems surprising.\n>\n> You said \"everythingthing in foo/bar is uninteresting and can be cleaned\",\n> you have one untracked file in \"foo/bar\" hierarchy, and you have nothing\n> else in \"foo/\" hierarchy.\n\nJust because it is uninteresting to git does not mean that it isn't\nprecious. In this case the ignored files are from svn and checked out\nvia another tool (gclient).\n\n> Removing the uninteresting cruft as your .gitignore instructs Git makes\n> the entire \"foo/\" hierarchy devoid of any contents. I would *expect* Git\n> to clean \"foo\" in this case.\n\nBut .gitignore is not for indicating \"this is cruft\", it is for\nindicating \"this is not under git's purview.\" You must admit that git\nclean's behavior above, if not surprising to you, is at least\ninconsistent with:\n\n$ git init test_repo && cd test_repo && mkdir foo && touch foo/bar &&\necho /foo > .gitignore && git add .gitignore && git clean -n -d\n\nwhich does protect foo (and its contents) from being cleaned.\n\ngit clean specifically has an option for \"remove only the stuff which\nis ignored\" which implies that it should not be removing ignored stuff\nw/o that option.\n\n> I've seen some \"surprising\" behaviour in \"git clean\" (which I do not use\n> myself, I do not consider part of \"my code\", and I am not surprised if it\n> has many bugs), but I fail to see what is surprising in your transcript.\n>\n> It would be a different issue if you had \">foo/other\" before your \"clean\".\n> Then \"foo/\" has \"foo/clean\" that is not declared to be uninteresting.\n\nHuh? clean is designed to remove untracked unignored files, so I'd\nexpect it to remove foo/other in that case. And what is this foo/clean\nto which you refer?\n\nj.\n"},{"id":"179797","messageId":"7vy5v9fgel.fsf@alter.siamese.dyndns.org","threadId":"28978","inReplyTo":"CAG+J_DwKeWntmi22vHS6CRud6Lo0P_+D5u5ih2Bbc50ekYji5w@mail.gmail.com","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-21T19:02:10Z","receivedAt":"2011-11-21T19:02:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jay Soffian <jaysoffian@gmail.com> writes:\n\n> Just because it is uninteresting to git does not mean that it isn't\n> precious.\n\nThat statement is false with the versions of Git so far. See the other\nthread for the current status and possible future directions.\n"},{"id":"179799","messageId":"7vty5xff6l.fsf@alter.siamese.dyndns.org","threadId":"28978","inReplyTo":"7vy5v9fgel.fsf@alter.siamese.dyndns.org","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-21T19:28:34Z","receivedAt":"2011-11-21T19:28:34Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Jay Soffian <jaysoffian@gmail.com> writes:\n>\n>> Just because it is uninteresting to git does not mean that it isn't\n>> precious.\n>\n> That statement is false with the versions of Git so far. See the other\n> thread for the current status and possible future directions.\n\nOops, sorry, I was really confused. You are right that \"ignored\" for\n\"clean\" does not mean \"they are not tracked and should be removed\". That\nwould result in removal of build artifacts '*.o' and unnecesary\nrecompilation.\n\nWhat \"precious\" means is a bit different, however. With verisons of Git so\nfar, what \"ignored\" means is that they are not tracked, and _can_ be\nremoved when needed to complete normal Git operations. When checking out\nanother branch that has a tracked file at the same path as an untracked\nand ignored file in your current branch, removal of that ignored file is\nnecessary to complete the checkout, and for that purpose, the ignored file\nis considered expendable. And we do not have a concept of \"precious\",\nunexpendable but untracked file, nor a way to specify that to gitignore\nmechanism (which is the topic of the other discussion thread).\n\n\"clean\" without \"-x\" is meant to preserve untracked but expendable paths\n(e.g. build products), so if something is removed that is untracked but\nmatches the ignore pattern, then that is a bug to be fixed.  Care to roll\na patch to fix it?\n\nSorry for the confusion, but as I said, I do not use (hence nor care much\nabout) \"clean\" myself, so...\n"},{"id":"179800","messageId":"CAG+J_DzBgQTdCoj8Y185+=+SpMMYgPXQXkta=o-Rson2xL8ytQ@mail.gmail.com","threadId":"28978","inReplyTo":"7vty5xff6l.fsf@alter.siamese.dyndns.org","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2011-11-21T20:03:43Z","receivedAt":"2011-11-21T20:03:43Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Mon, Nov 21, 2011 at 2:28 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"clean\" without \"-x\" is meant to preserve untracked but expendable paths\n> (e.g. build products), so if something is removed that is untracked but\n> matches the ignore pattern, then that is a bug to be fixed.  Care to roll\n> a patch to fix it?\n\nOkay, just confirming it is a bug. I'll add this e-mail to my todo\nlist, but I don't have time for a patch anytime soon. :-(\n\n> Sorry for the confusion, but as I said, I do not use (hence nor care much\n> about) \"clean\" myself, so...\n\nOkay.\n\nj.\n"},{"id":"180227","messageId":"4ED80F58.20003@cisco.com","threadId":"28978","inReplyTo":"CABURp0qv7MB-ZQvvSZQi43nAy1ZaR75-19T2Sd1JBT14Y_dG7w@mail.gmail.com","subject":"Re: clean bug on ignored subdirectories with no tracked files?","fromName":"Phil Hord","fromEmail":"hordp@cisco.com","sentAt":"2011-12-01T23:35:52Z","receivedAt":"2011-12-01T23:35:52Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"\nOn Mon, Nov 21, 2011 at 3:03 PM, Jay Soffian <jaysoffian@gmail.com> wrote:\n> On Mon, Nov 21, 2011 at 2:28 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> \"clean\" without \"-x\" is meant to preserve untracked but expendable paths\n>> (e.g. build products), so if something is removed that is untracked but\n>> matches the ignore pattern, then that is a bug to be fixed.  Care to roll\n>> a patch to fix it?\n> Okay, just confirming it is a bug. I'll add this e-mail to my todo\n> list, but I don't have time for a patch anytime soon. \n\nI think the fix is in dir.c (treat_directory), but I'm not sure how yet.\n\nHow's this for starters?\n\n-- >8 --\nSubject: [PATCH] clean: Test known breakage of .gitignore and -d\n\ngit-clean -d is used to remove untracked directories.  If the\ndirectory still contains .gitignored files it should not be removed.\nBut git is broken here if neither the ignored files nor the directory\nare explicitly ignored.\n\nDocument this known breakage with a test for both cases.\n\nNoticed-by: Jay Soffian <jaysoffian@gmail.com>\nSigned-off-by: Phil Hord <hordp@cisco.com>\n---\n t/t7300-clean.sh |   15 +++++++++++++++\n 1 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\nindex 800b536..e29e383 100755\n--- a/t/t7300-clean.sh\n+++ b/t/t7300-clean.sh\n@@ -14,6 +14,7 @@ test_expect_success 'setup' '\n \tmkdir -p src &&\n \ttouch src/part1.c Makefile &&\n \techo build >.gitignore &&\n+\techo /foo/bar >>.gitignore &&\n \techo \\*.o >>.gitignore &&\n \tgit add . &&\n \tgit commit -m setup &&\n@@ -264,6 +265,20 @@ test_expect_success 'git clean -d src/ examples/' '\n \n '\n \n+test_expect_failure 'git clean -d leaves .gitignored files alone' '\n+\n+\tmkdir -p objs foo/bar &&\n+\ttouch objs/foo.o &&\n+\ttouch foo/gone &&\n+\ttouch foo/bar/baz &&\n+\tgit clean -nd &&\n+\tgit clean -d &&\n+\ttest ! -f foo/gone &&\n+\ttest -f foo/bar/baz &&\n+\ttest -f objs/foo.o\n+\n+'\n+\n test_expect_success 'git clean -x' '\n \n \tmkdir -p build docs &&\n-- \n1.7.8.rc4\n"}]}