diff --git a/src/config-utils.test.ts b/src/config-utils.test.ts index 01f0a21d2..a9cb1802a 100644 --- a/src/config-utils.test.ts +++ b/src/config-utils.test.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as github from "@actions/github"; import test, { ExecutionContext } from "ava"; import * as yaml from "js-yaml"; +import * as semver from "semver"; import * as sinon from "sinon"; import * as actionsUtil from "./actions-util"; @@ -1065,7 +1066,6 @@ const getOverlayDatabaseModeMacro = test.macro({ sinon .stub(gitUtils, "gitVersionAtLeast") .callsFake(async (requiredVersion: string) => { - const semver = await import("semver"); return semver.gte(setup.gitVersion!, requiredVersion); }); } else { diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index ed1d01c15..dbea5cac3 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -424,6 +424,20 @@ test("getGitVersion returns undefined for invalid git output", async (t) => { } }); +test("getGitVersion handles Windows-style git output", async (t) => { + const runGitCommandStub = sinon + .stub(gitUtils as any, "runGitCommand") + .resolves("git version 2.40.0.windows.1\n"); + + try { + const version = await gitUtils.getGitVersion(); + // Should extract just the major.minor.patch portion + t.is(version, "2.40.0"); + } finally { + runGitCommandStub.restore(); + } +}); + test("getGitVersion returns undefined when git command fails", async (t) => { const runGitCommandStub = sinon .stub(gitUtils as any, "runGitCommand") diff --git a/src/git-utils.ts b/src/git-utils.ts index 38b17099a..6fa1369ce 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -30,7 +30,8 @@ export async function getGitVersion(): Promise { ["--version"], "Failed to get git version.", ); - // Expected output format: "git version 2.40.0" + // Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1" + // We capture just the major.minor.patch portion to ensure semver compatibility. const match = stdout.match(/git version (\d+\.\d+\.\d+)/); if (match?.[1]) { return match[1];