Skip to content

Commit fc2bbb0

Browse files
Copilothenrymercer
andcommitted
Address code review feedback
- Add test for Windows-style git version format - Add comment clarifying regex extracts major.minor.patch - Replace dynamic import with static import for semver Co-authored-by: henrymercer <[email protected]>
1 parent 89753aa commit fc2bbb0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/config-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as github from "@actions/github";
55
import test, { ExecutionContext } from "ava";
66
import * as yaml from "js-yaml";
7+
import * as semver from "semver";
78
import * as sinon from "sinon";
89

910
import * as actionsUtil from "./actions-util";
@@ -1065,7 +1066,6 @@ const getOverlayDatabaseModeMacro = test.macro({
10651066
sinon
10661067
.stub(gitUtils, "gitVersionAtLeast")
10671068
.callsFake(async (requiredVersion: string) => {
1068-
const semver = await import("semver");
10691069
return semver.gte(setup.gitVersion!, requiredVersion);
10701070
});
10711071
} else {

src/git-utils.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,20 @@ test("getGitVersion returns undefined for invalid git output", async (t) => {
424424
}
425425
});
426426

427+
test("getGitVersion handles Windows-style git output", async (t) => {
428+
const runGitCommandStub = sinon
429+
.stub(gitUtils as any, "runGitCommand")
430+
.resolves("git version 2.40.0.windows.1\n");
431+
432+
try {
433+
const version = await gitUtils.getGitVersion();
434+
// Should extract just the major.minor.patch portion
435+
t.is(version, "2.40.0");
436+
} finally {
437+
runGitCommandStub.restore();
438+
}
439+
});
440+
427441
test("getGitVersion returns undefined when git command fails", async (t) => {
428442
const runGitCommandStub = sinon
429443
.stub(gitUtils as any, "runGitCommand")

src/git-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export async function getGitVersion(): Promise<string | undefined> {
3030
["--version"],
3131
"Failed to get git version.",
3232
);
33-
// Expected output format: "git version 2.40.0"
33+
// Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1"
34+
// We capture just the major.minor.patch portion to ensure semver compatibility.
3435
const match = stdout.match(/git version (\d+\.\d+\.\d+)/);
3536
if (match?.[1]) {
3637
return match[1];

0 commit comments

Comments
 (0)