diff options
author | Junio C Hamano <gitster@pobox.com> | 2025-07-28 12:02:34 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2025-07-28 12:02:34 -0700 |
commit | d345ceda32412d8575234ad8b959d9f598b00a6e (patch) | |
tree | 3fab6580d77ba77fd75de4d360d36d2db06be60d /builtin/commit.c | |
parent | 0f6e5037d40db4768e8b61aea22c68c9711ce544 (diff) | |
parent | 92b7c7c9f5fde4972a653ddb90eca52c592de07e (diff) |
Merge branch 'ac/auto-comment-char-fix'
"git commit" that concludes a conflicted merge failed to notice and remove
existing comment added automatically (like "# Conflicts:") when the
core.commentstring is set to 'auto'.
* ac/auto-comment-char-fix:
config: set comment_line_str to "#" when core.commentChar=auto
commit: avoid scanning trailing comments when 'core.commentChar' is "auto"
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index fba0dded64..63e7158e98 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -688,6 +688,10 @@ static void adjust_comment_line_char(const struct strbuf *sb) char candidates[] = "#;@!$%^&|:"; char *candidate; const char *p; + size_t cutoff; + + /* Ignore comment chars in trailing comments (e.g., Conflicts:) */ + cutoff = sb->len - ignored_log_message_bytes(sb->buf, sb->len); if (!memchr(sb->buf, candidates[0], sb->len)) { free(comment_line_str_to_free); @@ -700,7 +704,7 @@ static void adjust_comment_line_char(const struct strbuf *sb) candidate = strchr(candidates, *p); if (candidate) *candidate = ' '; - for (p = sb->buf; *p; p++) { + for (p = sb->buf; p + 1 < sb->buf + cutoff; p++) { if ((p[0] == '\n' || p[0] == '\r') && p[1]) { candidate = strchr(candidates, p[1]); if (candidate) |