aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-03-15 12:43:58 -0700
committerJunio C Hamano <gitster@pobox.com>2024-03-15 16:07:37 -0700
commitfbad334db9cff30cdf1fe3d498dec737bfae38df (patch)
treeaf08f0a5f5c0a7397344084df6a9a1d7106ee66d /t
parent42d5c033945e4fc41d7268bfe4284d37651986b8 (diff)
downloadgit-fbad334db9cff30cdf1fe3d498dec737bfae38df.tar.gz
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>
Diffstat (limited to 't')
-rwxr-xr-xt/t1300-config.sh9
1 files changed, 5 insertions, 4 deletions
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index ac7b02e6b0..d5dfb45877 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -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
'