Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions @commitlint/read/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
"dependencies": {
"@commitlint/top-level": "workspace:^",
"@commitlint/types": "workspace:^",
"git-raw-commits": "^5.0.0",
"@conventional-changelog/git-client": "^3.0.0",
"tinyexec": "^1.0.0"
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
},
"devDependencies": {
"@commitlint/test": "workspace:^",
"@commitlint/utils": "workspace:^",
"@types/git-raw-commits": "^5.0.0"
"@commitlint/utils": "workspace:^"
},
"engines": {
"node": ">=22.12.0"
Expand Down
22 changes: 12 additions & 10 deletions @commitlint/read/src/get-history-commits.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { GitOptions } from "git-raw-commits";
import { getRawCommits } from "git-raw-commits";
import { GitClient, type GitLogParams } from "@conventional-changelog/git-client";

export type HistoryCommitsOptions = GitLogParams & Record<string, unknown>;

// Get commit messages from history
export async function getHistoryCommits(
options: GitOptions,
options: HistoryCommitsOptions,
opts: { cwd?: string } = {},
): Promise<string[]> {
// Note: git-raw-commits v5 drops support for arbitrary git log arguments.
// We extract and handle 'skip' manually here to preserve backward compatibility.
// Other arbitrary arguments passed via gitLogArgs may be silently ignored by v5.
const { skip: skipRaw, ...gitOptions } = options as GitOptions & {
skip?: unknown;
};
// Note: @conventional-changelog/git-client doesn't support arbitrary git
// log arguments. We extract and handle 'skip' manually here to preserve
// backward compatibility. Other arbitrary arguments passed via gitLogArgs
// may be silently ignored.
const { skip: skipRaw, ...gitOptions } = options;

let skipNum = 0;
if (skipRaw !== undefined) {
Expand All @@ -21,8 +21,10 @@ export async function getHistoryCommits(
}
}

const client = new GitClient(opts.cwd ?? process.cwd());

const data: string[] = [];
for await (const commit of getRawCommits({ ...gitOptions, cwd: opts.cwd })) {
for await (const commit of client.getRawCommits(gitOptions)) {
if (skipNum > 0) {
skipNum--;
continue;
Expand Down
9 changes: 4 additions & 5 deletions @commitlint/read/src/read.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { parseArgs } from "node:util";
import type { GitOptions } from "git-raw-commits";

import { getHistoryCommits } from "./get-history-commits.js";
import { getHistoryCommits, type HistoryCommitsOptions } from "./get-history-commits.js";
import { getEditCommit } from "./get-edit-commit.js";

import { x } from "tinyexec";
Expand Down Expand Up @@ -60,12 +59,12 @@ export default async function getCommitMessages(
}

// Verify the two refs share a merge-base before handing off the range
// walk to git-raw-commits. In a shallow clone the common ancestor may
// walk to the git client. In a shallow clone the common ancestor may
// be missing, in which case `git log from..to` silently returns only
// the commits that happen to be present, hiding invalid commits in the
// unfetched portion of history.
if (from) {
// `to` is left undefined here when no --to was given; git-raw-commits
// `to` is left undefined here when no --to was given; the git client
// defaults it to HEAD, so we mirror that for the merge-base check.
const effectiveTo = to ?? "HEAD";
const mergeBase = await x("git", ["merge-base", from, effectiveTo], {
Expand All @@ -80,7 +79,7 @@ export default async function getCommitMessages(
}
}

let gitOptions: GitOptions = { from, to };
let gitOptions: HistoryCommitsOptions = { from, to };
if (gitLogArgs) {
const { values, positionals } = parseArgs({
args: gitLogArgs.split(" "),
Expand Down
Loading