{"thread":{"id":"63745","subject":"[GSOC RFC] commit: commentChar=auto bug-fix suggestion","startedAt":"2025-07-05T07:16:11Z","lastAt":"2025-07-05T07:16:11Z","messageCount":1,"participants":["Ayush Chandekar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"521342","messageId":"CAE7as+YXwesgk2tna4kEC34EbQ=-eA+thQBqU3qnveDh9rbt8g@mail.gmail.com","threadId":"63745","inReplyTo":null,"subject":"[GSOC RFC] commit: commentChar=auto bug-fix suggestion","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-05T07:15:59Z","receivedAt":"2025-07-05T07:16:11Z","isPatch":false,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Hey everyone,\n\nThis rfc is related to the patch for bug-fix [1] I sent recently.\nIn few words: When core.commentChar is set to \"auto\", Git scans the\ncommit message to pick a comment character that isn't present. If old\nconflict comments remain, Git mistakenly reads the comment character\nin conflict comments as a part of the commit message and chooses\nanother, causing the conflict lines to be included in the commit\nmessage. Skipping the trailing comment block during the scan allows\nGit to reuse the original character, keeping the final commit message\nclean.\n\nSo after doing this, Phillip and Junio informed me about another bug\nwhich comes across [2]: If conflict comments already use a character\nthat isn't \"#\" (e.g., \"% Conflicts:\") and core.commentChar=auto is\nset, Git will ignore these lines during the scan using\nignored_log_message_bytes()(which uses the comment character used in\nthe conflict message) and then pick a new comment character based on\nthe rest of the message. The newly chosen character is different from\nthe one used in the conflict comments, those lines get no longer\ntreated as comments and end up in the final commit message.\n\nTo make this behavior consistent, as Phillip suggested, we can set\ncomment_line_str to \"#\" when core.commentChar=auto. So that even if it\nbreaks, it breaks consistently.\n\nAn alternative approach I thought of is to return early from the\n'adjust_comment_line_char()' when ignored_log_message_bytes() finds\nconflict markers. This would skip the comment charater detection which\nends up keeping the same comment character as the one in conflict\ncomments. This fixes the issue, but we end up ignoring the\ncore.commentchar=auto when we detect conflict comments.\n\nYou can check the attempts on my branches [3] & [4].\nI'd appreciate thoughts on which approach makes more sense.\nThanks!\n\n\n[1]: https://lore.kernel.org/git/20250626132233.414789-1-ayu.chandekar@gmail.com/\n[2]: https://lore.kernel.org/git/f39a3285-574a-45c6-9646-04eb175f4770@gmail.com/\n[3]: https://github.com/ayu-ch/git/commits/fix-rebase-commit-9\n[4]: https://github.com/ayu-ch/git/commits/fix-rebase-commit-8\n"}]}