{"thread":{"id":"61438","subject":"bug: git config --global --unset doesn't unset configs in corner case","startedAt":"2024-05-09T02:14:09Z","lastAt":"2024-05-10T16:39:08Z","messageCount":4,"participants":["Mike Hommey","Junio C Hamano","Patrick Steinhardt","rsbecker@nexbridge.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"494341","messageId":"20240509021352.se4u7ajaolveyyjf@glandium.org","threadId":"61438","inReplyTo":null,"subject":"bug: git config --global --unset doesn't unset configs in corner case","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2024-05-09T02:13:52Z","receivedAt":"2024-05-09T02:14:09Z","isPatch":false,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Hi,\n\nWhen both ~/.gitconfig and ~/.config/git/config exist, git will read\nboth. But when using `git config --global --unset`, it will only touch\nthe first one. So unsetting config items from ~/.config/git/config is\nnot possible from the command line when ~/.gitconfig exists.\n\nMike\n"},{"id":"494358","messageId":"xmqqmsozuf7y.fsf@gitster.g","threadId":"61438","inReplyTo":"20240509021352.se4u7ajaolveyyjf@glandium.org","subject":"Re: bug: git config --global --unset doesn't unset configs in corner case","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-05-09T16:23:13Z","receivedAt":"2024-05-09T16:23:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> When both ~/.gitconfig and ~/.config/git/config exist, git will read\n> both. But when using `git config --global --unset`, it will only touch\n> the first one. So unsetting config items from ~/.config/git/config is\n> not possible from the command line when ~/.gitconfig exists.\n\nInteresting observation of an understandable behaviour.\n\nI think the original intent of limiting the writing to just one was\nto avoid having both files in the first place.  When both do exist\nalready, I am not sure what the right behaviour on the write side\nshould be.  We could special case \"--unset-all\" and remove from\nboth, but \"--unset\" is to remove just one, so when the reading side\nreads from both, it becomes \"which one to remove\"?\n\nComments from those who are more familiar with the \"git config\" are\ncertainly appreciated.\n\nThanks.\n\n"},{"id":"494416","messageId":"Zj3vajAeJKuRaCvn@tanuki","threadId":"61438","inReplyTo":"xmqqmsozuf7y.fsf@gitster.g","subject":"Re: bug: git config --global --unset doesn't unset configs in corner case","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-05-10T09:56:58Z","receivedAt":"2024-05-10T09:57:05Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, May 09, 2024 at 09:23:13AM -0700, Junio C Hamano wrote:\n> Mike Hommey <mh@glandium.org> writes:\n> \n> > When both ~/.gitconfig and ~/.config/git/config exist, git will read\n> > both. But when using `git config --global --unset`, it will only touch\n> > the first one. So unsetting config items from ~/.config/git/config is\n> > not possible from the command line when ~/.gitconfig exists.\n\nThis actually works as documented:\n\n  --global\n\n    For writing options: write to global ~/.gitconfig file rather than\n    the repository .git/config, write to $XDG_CONFIG_HOME/git/config\n    file if this file exists and the ~/.gitconfig file doesn’t.\n\n    For reading options: read only from global ~/.gitconfig and from\n    $XDG_CONFIG_HOME/git/config rather than from all available files.\n\n    See also the section called “FILES”.\n\nWhether that behaviour is sane is a different question though.\n\n> Interesting observation of an understandable behaviour.\n> \n> I think the original intent of limiting the writing to just one was\n> to avoid having both files in the first place.  When both do exist\n> already, I am not sure what the right behaviour on the write side\n> should be.  We could special case \"--unset-all\" and remove from\n> both, but \"--unset\" is to remove just one, so when the reading side\n> reads from both, it becomes \"which one to remove\"?\n> \n> Comments from those who are more familiar with the \"git config\" are\n> certainly appreciated.\n\nHonestly, I even think that the reading behaviour is weird. For almost\nall the other tools that I know of that did the XDG migration, they only\never read either the XDG config or the one located in the users' home\ndirectory. I think this behaviour is quite sensible and leads to less\nsurprises overall, also to avoid asymmetric behaviour like the reported\none.\n\nIn any case, I find the expectation that `--unset-all` unsets all config\nreasonable. But what about `--remove-section` and `--rename-section`? If\na section exists in both files, should it be renamed in both? And\nremoved in both? What if you set a value with a value pattern (`git\nconfig foo.bar baz pattern`)? I think the answers are less clear in\nthose cases, and that to me hints that the design of how this feature\nworks is off.\n\nAs said, the most reasonable behaviour would be if we started to only\never use _either_ the XDG _or_ the home config, but never both. This not\nonly solves the reported issue, where it's unclear which of the files\nshould be modified. It also solves other problems -- would you for\nexample know the precedence order of those two files?\n\nI have no idea though whether this is something that we can reasonably\nchange now. I doubt that many users rely on having both configs, and\nI cannot think of any reason why they knowingly would. But it would be a\npotentially breaking change regardless of that.\n\nPatrick\n"},{"id":"494475","messageId":"001b01daa2f8$8cf49800$a6ddc800$@nexbridge.com","threadId":"61438","inReplyTo":"xmqqmsozuf7y.fsf@gitster.g","subject":"RE: bug: git config --global --unset doesn't unset configs in corner case","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2024-05-10T16:38:49Z","receivedAt":"2024-05-10T16:39:08Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On Thursday, May 9, 2024 12:23 PM, Junio C Hamano wrote:\n>Mike Hommey <mh@glandium.org> writes:\n>\n>> When both ~/.gitconfig and ~/.config/git/config exist, git will read\n>> both. But when using `git config --global --unset`, it will only touch\n>> the first one. So unsetting config items from ~/.config/git/config is\n>> not possible from the command line when ~/.gitconfig exists.\n>\n>Interesting observation of an understandable behaviour.\n>\n>I think the original intent of limiting the writing to just one was to\navoid having both\n>files in the first place.  When both do exist already, I am not sure what\nthe right\n>behaviour on the write side should be.  We could special case \"--unset-all\"\nand\n>remove from both, but \"--unset\" is to remove just one, so when the reading\nside\n>reads from both, it becomes \"which one to remove\"?\n>\n>Comments from those who are more familiar with the \"git config\" are\ncertainly\n>appreciated.\n\nIf both ~/.gitconfig and ~/.config/git/config both exist, a scope of\n--global becomes ambiguous. The --file <file> option should disambiguate the\noperation if just --unset is used. Otherwise, perhaps we should fail the\noperation.\n\n--Randall\n\n"}]}