Skip to content

fix(cli): read core.commentChar from the --cwd repository in edit mode - #5119

Merged
escapedcat merged 3 commits into
conventional-changelog:masterfrom
yxshee:fix/edit-comment-char-cwd
Nov 10, 2026
Merged

escapedcat merged 3 commits into
conventional-changelog:masterfrom
yxshee:fix/edit-comment-char-cwd

Conversation

@yxshee

@yxshee yxshee commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

In --edit mode the CLI reads core.commentChar / core.commentString to strip git comment lines, but it ran git config in the process working directory instead of --cwd. The config, the git root and the message file already come from --cwd, so a repository-local comment character was missed whenever commitlint ran from another directory, and its comment lines were linted as the body. getGitCommentString now runs git config in flags.cwd. Nothing changes when --cwd is not passed, since it defaults to the process working directory.

Motivation and Context

Follow-up to #5101, which added core.commentString support through the same helper.

Usage examples

git -C repo config core.commentChar ';'
# repo/.git/COMMIT_EDITMSG:
#   feat: add thing
#   ; Please enter the commit message. THIS LINE IS LONG .....(over 100 chars)
commitlint --cwd repo --edit
# master: ✖ body's lines must not be longer than 100 characters [body-max-line-length]
# now: passes, the same result as running it inside repo

How Has This Been Tested?

It will run the enhanced regression from another fixtures repo using the --cwd flag to point to a repo that has core.commentChar=;. Since this will not match the fixture's $ parser option we need git config to be pulled from the target repo. All 1332 tests pass as well as pnpm build, pnpm format, pnpm lint, pnpm check-no-focused-tests and commit message check.

On master it fails with AssertionError: expected '' to contain '[body-empty]'; it passes with the fix.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have verified that any documentation examples I added/changed actually work.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • For a feature/bug fix, my commits follow the test-driven flow: a failing-test commit, then the implementation.

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Reviews (2) · Last reviewed commit: "fix(cli): strengthen cwd comment configu..." · Reviewed by Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change to read Git comment settings from the repository specified by --cwd.

No open issues 🎉

What changed in this PR

Fixes edit-mode comment stripping when commitlint runs outside the repository specified by --cwd. This extends the comment-prefix handling introduced in #5101 while preserving behavior when --cwd is omitted.

Changes:

  • Reads Git comment settings from flags.cwd rather than the process working directory.
  • Adds a regression test that runs from a separate repository and verifies the target repository’s comment character is used.
File Description
@commitlint/​cli/​src/​cli.ts Passes flags.cwd to the Git config subprocess.
@commitlint/​cli/​src/​cli.test.ts Tests repository-local comment handling with an explicit --cwd.

Review effort: Balanced

@escapedcat

Copy link
Copy Markdown
Member

Thanks @yxshee, this looks good! Two optional nits on the test:

  • fixtures/comment-char/commitlint.config.js already sets commentChar: '$', so the test can still pass without the git config being read from --cwd. Using a char the config doesn't set makes it strict, like the commentString test does:

    await x("git", ["config", "--local", "core.commentChar", ";"], { nodeOptions: { cwd: targetCwd } });

    You'd need to change the comment line in the message file to start with ; too.

  • Please rename cwd → targetCwd to match the earlier test that sets up two repos, and add a one-line comment on why fixtures/default is the process dir (it's just a repo without the custom comment char).

Happy to merge as is if you'd rather not.


posted via Claude Code 🤖

@yxshee

yxshee commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Switched the regression to ;, renamed targetCwd, and explained the separate process repository. The stronger test fails on master; all 1332 tests pass.

@escapedcat
escapedcat added this pull request to the merge queue Nov 10, 2026
Merged via the queue into conventional-changelog:master with commit 741f660 Nov 10, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants