Throw in test mode if can't compute git version

This commit is contained in:
Henry Mercer
2025-12-18 12:52:13 +00:00
parent 003ddaeef5
commit 358a55e232
3 changed files with 10 additions and 2 deletions
+4 -1
View File
@@ -91565,7 +91565,7 @@ async function getGitVersionOrThrow() {
"Failed to get git version."
);
const match = stdout.match(/^git version ((\d+\.\d+\.\d+).*)$/);
if (match?.[1]) {
if (match?.[1] && match?.[2]) {
return new GitVersionInfo(match[2], match[1]);
}
throw new Error(`Could not parse Git version from output: ${stdout.trim()}`);
@@ -92985,6 +92985,9 @@ async function initConfig(features, inputs) {
await logGitVersionTelemetry(config, gitVersion);
} catch (e) {
logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`);
if (isInTestMode()) {
throw e;
}
}
const { overlayDatabaseMode, useOverlayDatabaseCaching } = await getOverlayDatabaseMode(
inputs.codeql,
+5
View File
@@ -53,6 +53,7 @@ import {
checkDiskUsage,
getCodeQLMemoryLimit,
getErrorMessage,
isInTestMode,
} from "./util";
export * from "./config/db-config";
@@ -935,6 +936,10 @@ export async function initConfig(
await logGitVersionTelemetry(config, gitVersion);
} catch (e) {
logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`);
// Throw the error in test mode so it's more visible.
if (isInTestMode()) {
throw e;
}
}
// The choice of overlay database mode depends on the selection of languages
+1 -1
View File
@@ -53,7 +53,7 @@ export async function getGitVersionOrThrow(): Promise<GitVersionInfo> {
// 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]) {
if (match?.[1] && match?.[2]) {
return new GitVersionInfo(match[2], match[1]);
}
throw new Error(`Could not parse Git version from output: ${stdout.trim()}`);