Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion @commitlint/read/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export default async function getCommitMessages(

let gitOptions: GitOptions = { from, to };
if (gitLogArgs) {
const { _, ...parsedArgs } = minimist(gitLogArgs.split(" "));

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

const { _, ...parsedArgs } = … introduces an unused local (_). With noUnusedLocals: true in the repo TS config, this will fail type-check/build unless _ is used or removed. Consider deleting ._ from the minimist result instead of destructuring it, or explicitly marking the binding as used (e.g. void _) so the compiler doesn’t flag it.

Suggested change
const { _, ...parsedArgs } = minimist(gitLogArgs.split(" "));
const parsedArgs = minimist(gitLogArgs.split(" "));
delete parsedArgs._;

Copilot uses AI. Check for mistakes.
gitOptions = {
...minimist(gitLogArgs.split(" ")),
...parsedArgs,
firstParent: parsedArgs["first-parent"],
Comment on lines 75 to +77

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

After mapping "first-parent" to firstParent, parsedArgs still contains the original "first-parent" key and it will be spread into gitOptions. Since git-raw-commits/git-client v5 dropped support for arbitrary git log args, it’s better to remove the kebab-case key after mapping to avoid passing unknown options downstream.

Copilot uses AI. Check for mistakes.
from,
Comment on lines +74 to 78

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Firstparent overwritten to undefined 🐞 Bug ≡ Correctness

In getCommitMessages(), firstParent is always assigned from parsedArgs["first-parent"] after
spreading parsedArgs, which overwrites any parsedArgs.firstParent value (e.g., from
--firstParent) with undefined. This makes --git-log-args parsing silently drop a valid
firstParent setting and always injects a firstParent property when gitLogArgs is set.
Agent Prompt
### Issue description
`firstParent` is always overwritten with `parsedArgs["first-parent"]`, which clobbers an existing `parsedArgs.firstParent` value and also adds `firstParent: undefined` whenever `gitLogArgs` is provided.

### Issue Context
`--git-log-args` is an arbitrary space-separated string. The code should map kebab-case `first-parent` to camelCase `firstParent` **only when present**, and should not overwrite an existing `firstParent` value.

### Fix Focus Areas
- @commitlint/read/src/read.ts[72-81]

### Suggested approach
- Extract `first-parent` via object rest (`const { ['first-parent']: firstParentKebab, ...rest } = parsedArgs`) so the kebab key is removed from the spread.
- Build `gitOptions` with:
  - `...rest`
  - `firstParent` set **only if** `firstParentKebab !== undefined`, otherwise preserve any existing `rest.firstParent`.
  - `from`/`to` last as today.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

to,
};
Comment on lines +77 to 80

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

firstParent is always set from parsedArgs["first-parent"]. If the user passes the already-camel-cased --firstParent, minimist will set parsedArgs.firstParent = true but parsedArgs["first-parent"] will be undefined, and this code will overwrite firstParent to undefined in gitOptions. Update the mapping so firstParent is only derived from the kebab-case key when it’s actually present, and avoid clobbering an existing firstParent value.

Suggested change
firstParent: parsedArgs["first-parent"],
from,
to,
};
from,
to,
};
if (Object.prototype.hasOwnProperty.call(parsedArgs, "first-parent")) {
gitOptions.firstParent = parsedArgs["first-parent"];
}

Copilot uses AI. Check for mistakes.
Comment on lines 73 to 80

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

This change adds new behavior for gitLogArgs parsing (dropping minimist’s _ and mapping --first-parent to firstParent), but @commitlint/read/src/read.test.ts currently only covers --skip. Add a test case that verifies --git-log-args='--first-parent' results in first-parent history only (or at least that the correct option is passed through), to prevent regressions like #4704.

Copilot uses AI. Check for mistakes.
Expand Down