fix(git): respect core.commentChar when stripping commit message comments#308432
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(git): respect core.commentChar when stripping commit message comments#308432yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…ents The `stripCommitMessageComments` helper always stripped lines starting with `#`, ignoring any `core.commentChar` setting the user may have configured in their Git config. Git allows changing the comment character via `core.commentChar` (e.g. `git config core.commentChar ";"`) so that lines beginning with the configured character are treated as comments in commit messages and templates. VS Code's Git extension was not aware of this setting and always assumed `#`, causing commit template and SQUASH/MERGE message prefilling to incorrectly include comment lines when a non-default comment character was configured. Fix: read `core.commentChar` from Git config and pass it through to the stripping regex. When the setting is `auto` (let Git pick automatically) or is not configured, fall back to the default `#`. The comment character is escaped before use in the regex to handle any special characters a user might configure.
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Git extension strips comment lines from commit message templates and in-progress merge/squash messages before displaying them as the initial commit message. This is done by
stripCommitMessageComments(), which always assumes the comment character is#.However, Git supports configuring an alternative comment character via
core.commentChar(e.g.git config core.commentChar ";"). When a user has set this, lines beginning with;(or whatever they chose) are comments in Git's eyes, but VS Code's extension was not stripping them — they would leak into the commit message input box.This also means that if a user has
core.commentCharset to something other than#, and their commit template or message content contains#, lines with#would be stripped even though they are not comments.Fix
getCommentChar()which readscore.commentCharfromgit config. Handles theautovalue (falls back to#) and missing/empty config (defaults to#).stripCommitMessageComments()to accept an optionalcommentCharparameter (defaults to#for backward compatibility) and build the regex dynamically with proper escaping.getSquashMessage,getMergeMessage,getCommitTemplate) to fetch the comment char in parallel with the file read and pass it through.Testing
git config core.commentChar ";"in a local repo;-prefixed comment lines#lines (not comments with this config) are preserved