Skip to content

Commit d2fa395

Browse files
chore(read): replace deprecated git-raw-commits with git-client (#4860)
`git-raw-commits` is deprecated in favor of `@conventional-changelog/git-client`, which is now used directly via `GitClient.getRawCommits`.
1 parent 1b4e5bc commit d2fa395

4 files changed

Lines changed: 59 additions & 81 deletions

File tree

@commitlint/read/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@
3636
"dependencies": {
3737
"@commitlint/top-level": "workspace:^",
3838
"@commitlint/types": "workspace:^",
39-
"git-raw-commits": "^5.0.0",
39+
"@conventional-changelog/git-client": "^3.0.0",
4040
"tinyexec": "^1.0.0"
4141
},
4242
"devDependencies": {
4343
"@commitlint/test": "workspace:^",
44-
"@commitlint/utils": "workspace:^",
45-
"@types/git-raw-commits": "^5.0.0"
44+
"@commitlint/utils": "workspace:^"
4645
},
4746
"engines": {
4847
"node": ">=22.12.0"

@commitlint/read/src/get-history-commits.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { GitOptions } from "git-raw-commits";
2-
import { getRawCommits } from "git-raw-commits";
1+
import { GitClient, type GitLogParams } from "@conventional-changelog/git-client";
2+
3+
export type HistoryCommitsOptions = GitLogParams & Record<string, unknown>;
34

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

1616
let skipNum = 0;
1717
if (skipRaw !== undefined) {
@@ -21,8 +21,10 @@ export async function getHistoryCommits(
2121
}
2222
}
2323

24+
const client = new GitClient(opts.cwd ?? process.cwd());
25+
2426
const data: string[] = [];
25-
for await (const commit of getRawCommits({ ...gitOptions, cwd: opts.cwd })) {
27+
for await (const commit of client.getRawCommits(gitOptions)) {
2628
if (skipNum > 0) {
2729
skipNum--;
2830
continue;

@commitlint/read/src/read.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { parseArgs } from "node:util";
2-
import type { GitOptions } from "git-raw-commits";
32

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

76
import { x } from "tinyexec";
@@ -60,12 +59,12 @@ export default async function getCommitMessages(
6059
}
6160

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

83-
let gitOptions: GitOptions = { from, to };
82+
let gitOptions: HistoryCommitsOptions = { from, to };
8483
if (gitLogArgs) {
8584
const { values, positionals } = parseArgs({
8685
args: gitLogArgs.split(" "),

0 commit comments

Comments
 (0)