From fbad334db9cff30cdf1fe3d498dec737bfae38df Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 15 Mar 2024 12:43:58 -0700 Subject: 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 --- Documentation/git-config.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Documentation') diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index e608d5ffef..af374ee2e0 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,9 +9,9 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git config' [] [--type=] [--comment=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] -'git config' [] [--type=] [--comment=] --add -'git config' [] [--type=] [--comment=] [--fixed-value] --replace-all [] +'git config' [] [--type=] [--comment=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] +'git config' [] [--type=] [--comment=] --add +'git config' [] [--type=] [--comment=] [--fixed-value] --replace-all [] 'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get [] 'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all [] 'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp [] @@ -87,10 +87,11 @@ OPTIONS values. This is the same as providing '^$' as the `value-pattern` in `--replace-all`. ---comment :: - Append a comment to new or modified lines. A '#' character will be - unconditionally prepended to the value. The value must not contain - linefeed characters (no multi-line comments are permitted). +--comment :: + Append a comment at the end of new or modified lines. + Unless __ begins with "#", a string "# " (hash + followed by a space) is prepended to it. The __ must not + contain linefeed characters (no multi-line comments are permitted). --get:: Get the value for a given key (optionally filtered by a regex -- cgit v1.3