git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] git config --rename-section and variable replacement can lose config data

From
ASA. Christine Spang <spang@mit.edu>
Date
Jun 6, 2009, 08:52 UTC
Message-ID
<20090606085212.GA17461@how-about-a-nice-game-of-chess.mit.edu>
Hi,

While working on a Perl module that parses git-style config files I noticed the following bug while replicating the --rename-section functionality:

spang@loki:~/tmp> cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
        [valid] foo = bar
    hello = world
spang@loki:~/tmp> git config --get valid.foo
bar
spang@loki:~/tmp> git config --rename-section valid lost-data
spang@loki:~/tmp> cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[lost-data]
    hello = world

As you can see, --rename-section just replaces the entire line containing the section header that is being renamed, and if there is a config variable (or a comment, for that matter) following the section header on the same line (which is valid according to the config format documentation and the test suite), it is lost.

On further investigation, git config also blows away comments at the end of the line when replacing variable values, e.g.:

spang@loki:~/tmp> cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[test]
    foo = bar ; a comment
spang@loki:~/tmp> git config test.foo baz
spang@loki:~/tmp> cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[test]
    foo = baz

IMHO, it would be saner to, when a section header or variable value is to be replaced, just replace the substring of the line in question that needs replacing, rather than writing whole new lines and having to check if there is a variable and/or a comment following the data that is being replaced and then writing those to new lines as well. (Where would the comment be moved to?)

I'm using git v1.6.3.1, but I've looked at the code and the bug is still present in HEAD.

cheers, Christine

Message 1 of 1 in “[BUG] git config --rename-section and variable replacement can lose config data”
  1. A. Christine SpangJun 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.