Skip to content

Commit 92b7c7c

Browse files
ayu-chgitster
authored andcommitted
config: set comment_line_str to "#" when core.commentChar=auto
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. The patch text is based on Phillip Wood's message: https://lore.kernel.org/git/[email protected]/ and the commit log message is wriiten by me. Signed-off-by: Phillip Wood <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Ghanshyam Thakkar <[email protected]> Signed-off-by: Ayush Chandekar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e69bbfa commit 92b7c7c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,11 @@ static int git_default_core_config(const char *var, const char *value,
15371537
!strcmp(var, "core.commentstring")) {
15381538
if (!value)
15391539
return config_error_nonbool(var);
1540-
else if (!strcasecmp(value, "auto"))
1540+
else if (!strcasecmp(value, "auto")) {
15411541
auto_comment_line_char = 1;
1542-
else if (value[0]) {
1542+
FREE_AND_NULL(comment_line_str_to_free);
1543+
comment_line_str = "#";
1544+
} else if (value[0]) {
15431545
if (strchr(value, '\n'))
15441546
return error(_("%s cannot contain newline"), var);
15451547
comment_line_str = value;

0 commit comments

Comments
 (0)