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

Re: [GSOC PATCH 2/2] config: set comment_line_str to "#" when core.commentChar=auto

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 15, 2025, 21:23 UTC
Message-ID
<xmqq1pqhgnby.fsf@gitster.g>
In-Reply-To
<2a3c2d323bdb520a37a099b361be9ec5f2d5d46f.1752602474.git.ayu.chandekar@gmail.com>
Ayush Chandekar <ayu.chandekar@gmail.com> writes:
Show 56 quoted lines
> If conflict comments already use a comment character that isn't "#", and
> core.commentChar is set "auto", Git will ignore these lines during the
> scan using ignored_log_message_bytes() and pick a new comment character
> based on the rest of the message. The newly chosen character may be
> different from the one used in the conflict comments and therefore,
> these are no longer treated as comments and end up in the final commit
> message.
>
> For example, during a rebase if the user previously set
> core.commentChar=% and then encounters a conflict, conflict comments
> like "% Conflicts:" are generated. If the user subsequently sets
> core.commentChar=auto before running `rebase --continue`, Git parses the
> "auto" setting and begins scanning. It first uses the existing
> 'comment_line_str' (which is '%') to detect and ignore conflict comments
> via ignored_log_message_bytes().
>
> Then, Git scans the rest of the message (excluding conflict comments),
> sees that none of the remaining lines start with '#' and decides to set
> comment_line_str to '#'. Since the final commit character differs from
> the one used in the conflict comments, those lines are no longer
> considered comments and get included in the final commit message.
>
> Set 'comment_line_str' to '#' when core.commentChar is set to 'auto' to
> reset any previously set value.
>
> While this does not solve the issue of conflict comment inclusion and
> the user visible behaviour stays tha same, it standardizes the behaviour
> of the code by always resetting 'comment_line_str' to '#' when
> core.commentChar=auto is parsed.
>
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
> Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
> ---
>  config.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
>
> diff --git a/config.c b/config.c
> index eb60c293ab..bb75bdc65d 100644
> --- a/config.c
> +++ b/config.c
> @@ -1537,9 +1537,11 @@ static int git_default_core_config(const char *var, const char *value,
>  	    !strcmp(var, "core.commentstring")) {
>  		if (!value)
>  			return config_error_nonbool(var);
> -		else if (!strcasecmp(value, "auto"))
> +		else if (!strcasecmp(value, "auto")) {
>  			auto_comment_line_char = 1;
> -		else if (value[0]) {
> +			FREE_AND_NULL(comment_line_str_to_free);
> +			comment_line_str = "#";
> +		} else if (value[0]) {
>  			if (strchr(value, '\n'))
>  				return error(_("%s cannot contain newline"), var);
>  			comment_line_str = value;
This patch is exactly what Phillip suggested in
https://lore.kernel.org/git/9e96aaab-79a2-4632-94cd-d016d4a63b30@gmail.com/
isn't it?  Makes sense to me.
Previous: Ayush ChandekarNext: Ayush Chandekar
Message 29 of 41 in “commit: avoid scanning trailing comments when 'core.commentChar' is "auto"”
  1. commit: avoid scanning trailing comments when 'core.commentChar' is "auto"Ayush Chandekar, Jun 26, 2025
  2. Junio C HamanoJun 26, 2025
  3. Ayush ChandekarJun 26, 2025
  4. Kristoffer HaugsbakkJun 26, 2025
  5. Ayush ChandekarJun 26, 2025
  6. commit: avoid scanning trailing comments when 'core.commentChar' is "auto"Ayush Chandekar, Jun 26, 2025
  7. Phillip WoodJun 27, 2025
  8. Junio C HamanoJun 27, 2025
  9. Ayush ChandekarJun 28, 2025
  10. Phillip WoodJun 28, 2025
  11. Ayush ChandekarJun 28, 2025
  12. Phillip WoodJun 30, 2025
  13. Ayush ChandekarJun 30, 2025
  14. Phillip WoodJun 28, 2025
  15. Junio C HamanoJun 30, 2025
  16. Ayush ChandekarJun 28, 2025
  17. Christian CouderJun 27, 2025
  18. commit: avoid scanning trailing comments when 'core.commentChar' is "auto"Ayush Chandekar, Jun 30, 2025
  19. Phillip WoodJul 1, 2025
  20. Ayush ChandekarJul 1, 2025
  21. Phillip WoodJul 1, 2025
  22. Ayush ChandekarJul 2, 2025
  23. Phillip WoodJul 4, 2025
  24. Ayush ChandekarJul 8, 2025
  25. Phillip WoodJul 9, 2025
  26. 0/2 commit: improve behaviour of core.commentChar=auto for comments in commit messagesAyush Chandekar, Jul 15, 2025
  27. 1/2 commit: avoid scanning trailing comments when 'core.commentChar' is "auto"Ayush Chandekar, Jul 15, 2025
  28. 2/2 config: set comment_line_str to "#" when core.commentChar=autoAyush Chandekar, Jul 15, 2025
  29. Junio C HamanoJul 15, 2025
  30. Ayush ChandekarJul 15, 2025
  31. Junio C HamanoJul 15, 2025
  32. Ayush ChandekarJul 16, 2025
  33. Junio C HamanoJul 16, 2025
  34. Phillip WoodJul 16, 2025
  35. Junio C HamanoJul 16, 2025
  36. 0/2 commit: improve behaviour of core.commentChar=auto for comments in commit messagesAyush Chandekar, Jul 16, 2025
  37. 1/2 commit: avoid scanning trailing comments when 'core.commentChar' is "auto"Ayush Chandekar, Jul 16, 2025
  38. 2/2 config: set comment_line_str to "#" when core.commentChar=autoAyush Chandekar, Jul 16, 2025
  39. Junio C HamanoJul 16, 2025
  40. Phillip WoodJul 16, 2025
  41. Junio C HamanoJul 16, 2025

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.