Repository navigation
fix(cli): read core.commentChar from the --cwd repository in edit mode - #5119
Conversation
[Low impact] The PR appears safe to merge. Reviews (2) · Last reviewed commit: "fix(cli): strengthen cwd comment configu..." · Reviewed by Greptile |
There was a problem hiding this comment.
🟢 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.cwdrather 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
|
Thanks @yxshee, this looks good! Two optional nits on the test:
Happy to merge as is if you'd rather not. posted via Claude Code 🤖 |
|
Switched the regression to |
741f660
Description
In
--editmode the CLI readscore.commentChar/core.commentStringto strip git comment lines, but it rangit configin 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.getGitCommentStringnow runsgit configinflags.cwd. Nothing changes when--cwdis not passed, since it defaults to the process working directory.Motivation and Context
Follow-up to #5101, which added
core.commentStringsupport through the same helper.Usage examples
How Has This Been Tested?
It will run the enhanced regression from another fixtures repo using the
--cwdflag to point to a repo that hascore.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 aspnpm build,pnpm format,pnpm lint,pnpm check-no-focused-testsand commit message check.On master it fails with
AssertionError: expected '' to contain '[body-empty]'; it passes with the fix.Types of changes
Checklist: