mirror of
https://github.com/git/git.git
synced 2026-03-20 21:50:07 +01:00
config: fix --comment formatting
When git adds comments itself (like "rebase -i" todo list and "commit -e" log message editor), it always gives a comment introducer "#" followed by a Space before the message, except for the recently introduced "git config --comment", where the users are forced to say " this is my comment" if they want to add their comment in this usual format; otherwise their comment string will end up without a space after the "#". Make it more ergonomic, while keeping it possible to also use this unusual style, by massaging the comment string at the UI layer with a set of simple rules: * If the given comment string begins with '#', it is passed intact. * Otherwise, "# " is prefixed. * A string with LF in it cannot be used as a comment string. Right now there is only one "front-end" that accepts end-user comment string and calls the underlying machinery to add or modify configuration file with comments, but to make sure that the future callers perform similar massaging as they see fit, add a sanity check logic in git_config_set_multivar_in_file_gently(), which is the single choke point in the codepaths that consumes the comment string. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@@ -71,16 +71,17 @@ cat > expect << EOF
|
||||
[section]
|
||||
Movie = BadPhysics
|
||||
UPPERCASE = true
|
||||
penguin = gentoo #Pygoscelis papua
|
||||
disposition = peckish #find fish
|
||||
foo = bar ## abc
|
||||
penguin = gentoo # Pygoscelis papua
|
||||
disposition = peckish # find fish
|
||||
foo = bar #abc
|
||||
[Sections]
|
||||
WhatEver = Second
|
||||
EOF
|
||||
|
||||
test_expect_success 'append comments' '
|
||||
git config --replace-all --comment="Pygoscelis papua" section.penguin gentoo &&
|
||||
git config --comment="find fish" section.disposition peckish &&
|
||||
git config --comment="# abc" section.foo bar &&
|
||||
git config --comment="#abc" section.foo bar &&
|
||||
test_cmp expect .git/config
|
||||
'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user