Move git version logging to config utils

This commit is contained in:
Henry Mercer
2025-12-17 12:06:41 +00:00
parent e052dbd57d
commit 3765106c90
17 changed files with 321 additions and 445 deletions
+1 -69
View File
@@ -7,12 +7,7 @@ import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import * as gitUtils from "./git-utils";
import {
getRecordingLogger,
LoggedMessage,
setupActionsVars,
setupTests,
} from "./testing-utils";
import { setupActionsVars, setupTests } from "./testing-utils";
import { withTmpDir } from "./util";
setupTests(test);
@@ -464,66 +459,3 @@ test("getGitVersionOrThrow throws when git command fails", async (t) => {
runGitCommandStub.restore();
}
});
test("gitVersionAtLeast returns true for version meeting requirement", async (t) => {
const runGitCommandStub = sinon
.stub(gitUtils as any, "runGitCommand")
.resolves("git version 2.40.0\n");
const messages: LoggedMessage[] = [];
const logger = getRecordingLogger(messages);
try {
const result = await gitUtils.gitVersionAtLeast("2.38.0", logger);
t.true(result);
t.true(
messages.some(
(m) =>
m.type === "debug" &&
m.message === "Installed Git version is 2.40.0.",
),
);
} finally {
runGitCommandStub.restore();
}
});
test("gitVersionAtLeast returns false for version not meeting requirement", async (t) => {
const runGitCommandStub = sinon
.stub(gitUtils as any, "runGitCommand")
.resolves("git version 2.30.0\n");
const messages: LoggedMessage[] = [];
const logger = getRecordingLogger(messages);
try {
const result = await gitUtils.gitVersionAtLeast("2.38.0", logger);
t.false(result);
} finally {
runGitCommandStub.restore();
}
});
test("gitVersionAtLeast returns false when version cannot be determined", async (t) => {
const runGitCommandStub = sinon
.stub(gitUtils as any, "runGitCommand")
.rejects(new Error("git not found"));
const messages: LoggedMessage[] = [];
const logger = getRecordingLogger(messages);
try {
const result = await gitUtils.gitVersionAtLeast("2.38.0", logger);
t.false(result);
t.true(
messages.some(
(m) =>
m.type === "debug" &&
typeof m.message === "string" &&
m.message.includes("Could not determine Git version"),
),
);
} finally {
runGitCommandStub.restore();
}
});