{"thread":{"id":"29373","subject":"Unexpected \"clean -Xd\" behavior","startedAt":"2012-01-16T02:00:14Z","lastAt":"2012-01-19T22:12:18Z","messageCount":5,"participants":["Pete Harlan","Jonathan Nieder","Nguyen Thai Ngoc Duy","pgit@pcharlan.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"182589","messageId":"4F1384AE.1050209@pcharlan.com","threadId":"29373","inReplyTo":null,"subject":"Unexpected \"clean -Xd\" behavior","fromName":"Pete Harlan","fromEmail":"pgit@pcharlan.com","sentAt":"2012-01-16T02:00:14Z","receivedAt":"2012-01-16T02:00:14Z","isPatch":false,"sender":{"key":"pgit@pcharlan.com","avatar":null},"body":"Hi,\n\nWhen a directory contains nothing but an ignored subdirectory, that\nsubdirectory does not get removed by \"git clean -Xdf\".\n\nFor example, in a new directory:\n\n# git init\nInitialized empty Git repository in /tmp/foo/.git/\n# echo a/ >.gitignore\n# git add .gitignore\n# git commit -m \"Initial commit\"\n[master (root-commit) c3af24c] Initial commit\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 .gitignore\n# mkdir -p foo/a\n# touch foo/a/junk.o\n# git status\n# On branch master\nnothing to commit (working directory clean)\n# git clean -Xdn  # <--- DOES NOT MENTION foo/a\n# touch foo/x.c\n# git clean -Xdn  # <--- DITTO WITH UNTRACKED IN foo\n# git add foo/x.c\n# git clean -Xdn  # <--- WITH TRACKED IN foo, WILL REMOVE a/\nWould remove foo/a/\n#\n\nIs this intentional?  It's interfering with my using \"git clean\" to\nremove built objects, which happen to be in a dedicated temporary\nsubdirectory.\n\nThanks,\n\n--Pete Harlan\n  pgit@pcharlan.com\n"},{"id":"182758","messageId":"20120119002904.GA14107@burratino","threadId":"29373","inReplyTo":"4F1384AE.1050209@pcharlan.com","subject":"Re: Unexpected \"clean -Xd\" behavior","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-01-19T00:29:04Z","receivedAt":"2012-01-19T00:29:04Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"(+cc: Duy, Shawn)\nHi,\n\nPete Harlan wrote:\n\n> When a directory contains nothing but an ignored subdirectory, that\n> subdirectory does not get removed by \"git clean -Xdf\".\n>\n> For example, in a new directory:\n>\n> # git init\n> Initialized empty Git repository in /tmp/foo/.git/\n> # echo a/ >.gitignore\n> # git add .gitignore\n> # git commit -m \"Initial commit\"\n> [master (root-commit) c3af24c] Initial commit\n>  1 files changed, 1 insertions(+), 0 deletions(-)\n>  create mode 100644 .gitignore\n> # mkdir -p foo/a\n> # touch foo/a/junk.o\n> # git status\n> # On branch master\n> nothing to commit (working directory clean)\n> # git clean -Xdn  # <--- DOES NOT MENTION foo/a\n> # touch foo/x.c\n> # git clean -Xdn  # <--- DITTO WITH UNTRACKED IN foo\n> # git add foo/x.c\n> # git clean -Xdn  # <--- WITH TRACKED IN foo, WILL REMOVE a/\n> Would remove foo/a/\n> #\n>\n> Is this intentional?  It's interfering with my using \"git clean\" to\n> remove built objects, which happen to be in a dedicated temporary\n> subdirectory.\n\nSounds like a bug.  Duy, Shawn, any hints?\n\nThanks,\nJonathan\n"},{"id":"182767","messageId":"CACsJy8AE+rwmOVUZez5GRXRHJsTy+W8ekzr59NTd7_C+gB0Byw@mail.gmail.com","threadId":"29373","inReplyTo":"20120119002904.GA14107@burratino","subject":"Re: Unexpected \"clean -Xd\" behavior","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-19T07:31:32Z","receivedAt":"2012-01-19T07:31:32Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2012/1/19 Jonathan Nieder <jrnieder@gmail.com>:\n> Pete Harlan wrote:\n>\n>> When a directory contains nothing but an ignored subdirectory, that\n>> subdirectory does not get removed by \"git clean -Xdf\".\n>>\n>> For example, in a new directory:\n>>\n>> # git init\n>> Initialized empty Git repository in /tmp/foo/.git/\n>> # echo a/ >.gitignore\n>> # git add .gitignore\n>> # git commit -m \"Initial commit\"\n>> [master (root-commit) c3af24c] Initial commit\n>>  1 files changed, 1 insertions(+), 0 deletions(-)\n>>  create mode 100644 .gitignore\n>> # mkdir -p foo/a\n>> # touch foo/a/junk.o\n>> # git status\n>> # On branch master\n>> nothing to commit (working directory clean)\n>> # git clean -Xdn  # <--- DOES NOT MENTION foo/a\n\n-X is to remove ignored files _only_ (DIR_SHOW_IGNORED flag). And\n\"foo\" is not ignored according to .gitignore, so it cuts short there\nand never gets to \"foo/a\". -x works. May be intentional, may be not\n(we hit a corner case). I don't know. Commit message b991625 might\nhelp:\n\n    dir.c: Omit non-excluded directories with dir->show_ignored\n\n    This makes \"git-ls-files --others --directory --ignored\" behave\n    as documented and consequently also fixes \"git-clean -d -X\".\n    Previously, git-clean would remove non-excluded directories\n    even when using the -X option.\n-- \nDuy\n"},{"id":"182780","messageId":"20120119100317.GA15386@burratino","threadId":"29373","inReplyTo":"CACsJy8AE+rwmOVUZez5GRXRHJsTy+W8ekzr59NTd7_C+gB0Byw@mail.gmail.com","subject":"Re: Unexpected \"clean -Xd\" behavior","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-01-19T10:03:42Z","receivedAt":"2012-01-19T10:03:42Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Nguyen Thai Ngoc Duy wrote:\n\n> -X is to remove ignored files _only_ (DIR_SHOW_IGNORED flag). And\n> \"foo\" is not ignored according to .gitignore, so it cuts short there\n> and never gets to \"foo/a\". -x works.\n\nMakes sense.\n\nI guess the internal logic is that \"git clean -fdX\" cleans up files\nthat \"git clean -fd\" would miss, and this is not such a file (\"git\nclean -fd\" removes it).  But as Pete mentioned, in this edge case the\nbehavior renders \"git clean -fdX\" less effective than expected at its\nprimary task as poor man's \"make clean\".\n\nI'd be happy to see a patch that moves to a different set of semantics\nor an addition to t/t7300-clean.sh and BUGS section in\nDocumentation/git-clean.txt explaining the current limitations, if\nsomeone wants to work on that.\n\nThanks, both.\nJonathan\n"},{"id":"182817","messageId":"3cb3bb5dbcc4ae803dbdb4a3ff052433.squirrel@webmail.pcharlan.com","threadId":"29373","inReplyTo":"CACsJy8AE+rwmOVUZez5GRXRHJsTy+W8ekzr59NTd7_C+gB0Byw@mail.gmail.com","subject":"Re: Unexpected \"clean -Xd\" behavior","fromName":"","fromEmail":"pgit@pcharlan.com","sentAt":"2012-01-19T22:12:18Z","receivedAt":"2012-01-19T22:12:18Z","isPatch":false,"sender":{"key":"pgit@pcharlan.com","avatar":null},"body":"Thank you very much for looking at this.\n\n2012/1/19 \"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com>:\n> 2012/1/19 Jonathan Nieder <jrnieder@gmail.com>:\n>> Pete Harlan wrote:\n>>\n>>> When a directory contains nothing but an ignored subdirectory, that\n>>> subdirectory does not get removed by \"git clean -Xdf\".\n>>>\n>>> For example, in a new directory:\n>>>\n>>> # git init\n>>> Initialized empty Git repository in /tmp/foo/.git/\n>>> # echo a/ >.gitignore\n>>> # git add .gitignore\n>>> # git commit -m \"Initial commit\"\n>>> [master (root-commit) c3af24c] Initial commit\n>>> Â 1 files changed, 1 insertions(+), 0 deletions(-)\n>>> Â create mode 100644 .gitignore\n>>> # mkdir -p foo/a\n>>> # touch foo/a/junk.o\n>>> # git status\n>>> # On branch master\n>>> nothing to commit (working directory clean)\n>>> # git clean -Xdn Â # <--- DOES NOT MENTION foo/a\n>\n> -X is to remove ignored files _only_ (DIR_SHOW_IGNORED flag). And\n> \"foo\" is not ignored according to .gitignore, so it cuts short there\n> and never gets to \"foo/a\". -x works.\n\nBut the presence of a tracked file in foo makes it not cut short there, so\nthe logic seems a bit off.  (If we're interested in removing ignored files\nonly, then the ignored files (not a tracked file) should trigger us\nlooking into foo.  I don't know Git internals but I'm guessing it's not\nquite that simple.)\n\n> May be intentional, may be not\n> (we hit a corner case). I don't know. Commit message b991625 might\n> help:\n>\n>     dir.c: Omit non-excluded directories with dir->show_ignored\n>\n>     This makes \"git-ls-files --others --directory --ignored\" behave\n>     as documented and consequently also fixes \"git-clean -d -X\".\n>     Previously, git-clean would remove non-excluded directories\n>     even when using the -X option.\n\nIt can (and does) leave foo behind (because it's not ignored), but it\nwould conform better to the -X documentation if the ignored files were\nremoved.\n\nBTW the above commit doesn't affect the behavior in this example.\n\nIf a fix isn't desirable then as Jonathan said updating the documentation\nmakes sense.  (And those of us using it as a poor man's \"make clean\" can\njust fix our Makefiles instead...)\n\nThanks,\n\n--Pete\n"}]}