{"thread":{"id":"49930","subject":"[RFC] git clean --local","startedAt":"2018-12-01T22:51:26Z","lastAt":"2018-12-04T02:46:00Z","messageCount":8,"participants":["Cameron Boehmer","Junio C Hamano","Ævar Arnfjörð Bjarmason","Randall S. Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"364425","messageId":"CAM+q9MeVS1e11vzu+-RP-i5NhSsnRz=x21q3gcGy8L62yceiMw@mail.gmail.com","threadId":"49930","inReplyTo":null,"subject":"[RFC] git clean --local","fromName":"Cameron Boehmer","fromEmail":"cameron.boehmer@gmail.com","sentAt":"2018-12-01T22:51:10Z","receivedAt":"2018-12-01T22:51:26Z","isPatch":false,"sender":{"key":"cameron.boehmer@gmail.com","avatar":null},"body":"-x and -X are great, but they remove files that are ignored via my\n~/.gitignore that I'd rather keep (personal toolchain dotfiles). If\nothers also would like to see this addressed and we settle on a\nspecific solution, I'd be happy to submit a patch. Some ideas:\n\n1) add a new flag\n-l, --local\n    Do not consult git config --global core.excludesFile in\ndetermining what files git ignores. This is useful in conjunction with\n-x/-X to preserve user files while removing build artifacts.\n\n2) change the behavior of -x/-X\nWhile it would be inconsistent with git's behavior elsewhere to NOT\nconsult the global excludesFile, the intent behind -x/-X seems to have\neverything to do with the contents of current project's .gitignores,\nand nothing to do with the global excludes. However, even if this is\npalatable, it's not backwards compatible, and I'm not sure this meets\nthe threshold of significance for breaking changes.\n\nOf course, I'm open to suggestions.\n\nThanks to all for their contributions,\nCameron\n"},{"id":"364426","messageId":"xmqqsgzgiyk2.fsf@gitster-ct.c.googlers.com","threadId":"49930","inReplyTo":"CAM+q9MeVS1e11vzu+-RP-i5NhSsnRz=x21q3gcGy8L62yceiMw@mail.gmail.com","subject":"Re: [RFC] git clean --local","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-02T00:04:29Z","receivedAt":"2018-12-02T00:04:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Cameron Boehmer <cameron.boehmer@gmail.com> writes:\n\n> 1) add a new flag\n> -l, --local\n>     Do not consult git config --global core.excludesFile in\n> determining what files git ignores. This is useful in conjunction with\n> -x/-X to preserve user files while removing build artifacts.\n\nThis does not belong to the \"clean\" command (who says the need to\nignore the global configuration is limited to \"clean\" and why?), so\n\"git clean --local\" is simply not acceptable.\n\nBut it might be useful as an option that affects any \"git\" command,\ne.g. \"git --local-config-only clean\".  I dunno.\n\n> 2) change the behavior of -x/-X\n\nThis won't happen without a long deprecation period.\n\nIf you haven't seen and read them, check the recent list archive for\nthe past few weeks, with keywords \"trashable\", \"precious\", etc.\n"},{"id":"364434","messageId":"xmqqo9a4ilm8.fsf@gitster-ct.c.googlers.com","threadId":"49930","inReplyTo":"xmqqsgzgiyk2.fsf@gitster-ct.c.googlers.com","subject":"Re: [RFC] git clean --local","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-02T04:43:59Z","receivedAt":"2018-12-02T04:44:06Z","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> Cameron Boehmer <cameron.boehmer@gmail.com> writes:\n>\n>> 1) add a new flag\n>> -l, --local\n>>     Do not consult git config --global core.excludesFile in\n>> determining what files git ignores. This is useful in conjunction with\n>> -x/-X to preserve user files while removing build artifacts.\n> ...\n> But it might be useful as an option that affects any \"git\" command,\n> e.g. \"git --local-config-only clean\".  I dunno.\n\nIf you only want to say \"there is no global excludes file\", perhaps\n\n    $ git -c core.excludesFile=/dev/null clean -x\n\nmay be sufficient, so for that particular use case, there is no need\nto introduce a new command, I'd think.\n\nIn the longer term, however, I think we would want to introduce a\ndistinction among ignored files---we only support \"ignored and\nexpendable\" class, but not \"ignored but precious\" class.  With the\nlatter class introduced, it would make sense for \"git clean -x/-X\"\nto notice that a path is ignored but precious and keep it.  If a\ndir/foo is ignored, dir/bar is tracked in commit A that is currently\nchecked out, and there is no dir/ directory in commit B, checking\nout commit B would remove dir/foo (because the last tracked file in\nthe directory goes away and all remaining files in the directory\nwould be ignored but expendable).  But if we introduced a new\n\"ignored but precious\" class and made dir/foo a member of such a\nclass, then you will be prevented from checkout out B until you do\nsomething about dir/foo that is now \"precious\".\n\n\n\n\n"},{"id":"364440","messageId":"87woosukkm.fsf@evledraar.gmail.com","threadId":"49930","inReplyTo":"CAM+q9MeVS1e11vzu+-RP-i5NhSsnRz=x21q3gcGy8L62yceiMw@mail.gmail.com","subject":"Re: [RFC] git clean --local","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-12-02T13:25:45Z","receivedAt":"2018-12-02T13:25:51Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Dec 01 2018, Cameron Boehmer wrote:\n\n> 1) add a new flag\n> -l, --local\n>     Do not consult git config --global core.excludesFile in\n> determining what files git ignores. This is useful in conjunction with\n> -x/-X to preserve user files while removing build artifacts.\n\nOr perhaps a general flag to ignore configuration would be useful for\nsuch cases, see\nhttps://public-inbox.org/git/87zhtqvm66.fsf@evledraar.gmail.com/\n"},{"id":"364451","messageId":"004101d48a65$afb0da40$0f128ec0$@nexbridge.com","threadId":"49930","inReplyTo":"87woosukkm.fsf@evledraar.gmail.com","subject":"RE: [RFC] git clean --local","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2018-12-02T17:37:18Z","receivedAt":"2018-12-02T17:37:30Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On December 2, 2018 8:26, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Sat, Dec 01 2018, Cameron Boehmer wrote:\n> \n> > 1) add a new flag\n> > -l, --local\n> >     Do not consult git config --global core.excludesFile in\n> > determining what files git ignores. This is useful in conjunction with\n> > -x/-X to preserve user files while removing build artifacts.\n> \n> Or perhaps a general flag to ignore configuration would be useful for such\n> cases, see https://public-\n> inbox.org/git/87zhtqvm66.fsf@evledraar.gmail.com/\n\nWould something like git clean --exclude=file-pattern work as a compromise notion? Files matching the pattern would not be cleaned regardless of .gitignore or their potential preciousness status long-term. Multiple repetitions of the --exclude option might be supportable. I could see that being somewhat useful in scripting.\n\nCheers,\nRandall\n\n\n"},{"id":"364454","messageId":"xmqqk1kriuu8.fsf@gitster-ct.c.googlers.com","threadId":"49930","inReplyTo":"004101d48a65$afb0da40$0f128ec0$@nexbridge.com","subject":"Re: [RFC] git clean --local","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-02T19:37:03Z","receivedAt":"2018-12-02T19:37:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Randall S. Becker\" <rsbecker@nexbridge.com> writes:\n\n\n> Would something like git clean --exclude=file-pattern work as a\n> compromise notion? Files matching the pattern would not be cleaned\n> regardless of .gitignore or their potential preciousness status\n> long-term. Multiple repetitions of the --exclude option might be\n> supportable. I could see that being somewhat useful in scripting.\n\nI think \"git clean\" already takes \"-e\", but I am not sure if it is\nmeant to do what you wrote above.\n\nIf \"git clean\" takes a pathspec, perhaps you can give a negative\npathspec to exclude whatever you do not want to get cleaned,\nsomething like\n\n\tgit clean '*.o' ':!precious.o'\n\nto say \"presious.o is ignored (hence normally expendable), but I do\nnot want to clean it with this invocation of 'git clean'\"?\n"},{"id":"364464","messageId":"CAM+q9MfiycW6kXRLHsseKp+n1k9goALjRY-ePke2vYDhqcpD=g@mail.gmail.com","threadId":"49930","inReplyTo":"xmqqk1kriuu8.fsf@gitster-ct.c.googlers.com","subject":"Re: [RFC] git clean --local","fromName":"Cameron Boehmer","fromEmail":"cameron.boehmer@gmail.com","sentAt":"2018-12-03T07:40:56Z","receivedAt":"2018-12-03T07:41:11Z","isPatch":false,"sender":{"key":"cameron.boehmer@gmail.com","avatar":null},"body":"> > Would something like git clean --exclude=file-pattern work as a\n> > compromise notion? Files matching the pattern would not be cleaned\n> > regardless of .gitignore or their potential preciousness status\n> > long-term. Multiple repetitions of the --exclude option might be\n> > supportable. I could see that being somewhat useful in scripting.\n>\n> I think \"git clean\" already takes \"-e\", but I am not sure if it is\n> meant to do what you wrote above.\n\nIt does already take --exclude=file-pattern, which is like adding\nlines to .gitignore. (W/o -x/-X, that would mean DON'T clean them, but\nwith -x/-X, it means DO clean them.)\n\n>\n> If \"git clean\" takes a pathspec, perhaps you can give a negative\n> pathspec to exclude whatever you do not want to get cleaned,\n> something like\n>\n>         git clean '*.o' ':!precious.o'\n>\n\nI like this, but I'm also 100% satisfied with Junio's previous suggestion:\n    git -c core.excludesFile=/dev/null clean ...\n"},{"id":"364522","messageId":"xmqqk1kqf1r4.fsf@gitster-ct.c.googlers.com","threadId":"49930","inReplyTo":"xmqqk1kriuu8.fsf@gitster-ct.c.googlers.com","subject":"Re: [RFC] git clean --local","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-04T02:45:51Z","receivedAt":"2018-12-04T02:46:00Z","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> If \"git clean\" takes a pathspec, perhaps you can give a negative\n> pathspec to exclude whatever you do not want to get cleaned,\n> something like\n>\n> \tgit clean '*.o' ':!precious.o'\n>\n> to say \"presious.o is ignored (hence normally expendable), but I do\n> not want to clean it with this invocation of 'git clean'\"?\n\nHmph, this leads me to an interesting thought.  With today's code,\nthese two commands behave in meaningfully different ways when I mark\nsome paths that match .gitignore patterns with the precious\nattribute.\n\n\techo \"*.ignored\" >>.git/info/exclude\n\techo \"precious.* precious\" >>.git/info/attributes\n\n\t: >expendable.ignored 2>precious.ignored\n\n\tgit clean -n -x\n\tgit clean -n -x ':(exclude,attr:precious)'\n\nI am not suggesting that giving \"git clean\" a configuration knob\nthat always append pathspec elements, which would allow users to use\nthe mechanism to set the above magic pathspec, would be a good\napproach.  If we were to follow through this line of thought, an\nobvious thing to do is to always unconditonally append the above\nmagic pathspec internally when running \"git clean\", which would mean\n\n * Existing projects and users' repositories will see no behaviour\n   change, because they are unaware of the \"precious\" attribute.\n\n * People who learn the new feature can start using the \"ignored but\n   precious\" class, without any need for transition period.\n\n\n"}]}