{"thread":{"id":"19711","subject":"[BUG] git config --rename-section and variable replacement can lose config data","startedAt":"2009-06-06T08:52:12Z","lastAt":"2009-06-06T08:52:12Z","messageCount":1,"participants":["A. Christine Spang"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"115637","messageId":"20090606085212.GA17461@how-about-a-nice-game-of-chess.mit.edu","threadId":"19711","inReplyTo":null,"subject":"[BUG] git config --rename-section and variable replacement can lose config data","fromName":"A. Christine Spang","fromEmail":"spang@mit.edu","sentAt":"2009-06-06T08:52:12Z","receivedAt":"2009-06-06T08:52:12Z","isPatch":false,"sender":{"key":"spang@mit.edu","avatar":null},"body":"Hi,\n\nWhile working on a Perl module that parses git-style config files I noticed\nthe following bug while replicating the --rename-section functionality:\n\nspang@loki:~/tmp> cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n        [valid] foo = bar\n    hello = world\nspang@loki:~/tmp> git config --get valid.foo\nbar\nspang@loki:~/tmp> git config --rename-section valid lost-data\nspang@loki:~/tmp> cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n[lost-data]\n    hello = world\n\nAs you can see, --rename-section just replaces the entire line\ncontaining the section header that is being renamed, and if there is a\nconfig variable (or a comment, for that matter) following the section\nheader on the same line (which is valid according to the config format\ndocumentation and the test suite), it is lost.\n\nOn further investigation, git config also blows away comments at the end\nof the line when replacing variable values, e.g.:\n\nspang@loki:~/tmp> cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n[test]\n    foo = bar ; a comment\nspang@loki:~/tmp> git config test.foo baz\nspang@loki:~/tmp> cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n[test]\n    foo = baz\n\nIMHO, it would be saner to, when a section header or variable value is to be\nreplaced, just replace the substring of the line in question that needs\nreplacing, rather than writing whole new lines and having to check if there is\na variable and/or a comment following the data that is being replaced and then\nwriting those to new lines as well. (Where would the comment be moved to?)\n\nI'm using git v1.6.3.1, but I've looked at the code and the bug is still\npresent in HEAD.\n\ncheers,\nChristine\n"}]}