Skip to content

Commit 358a55e

Browse files
committed
Throw in test mode if can't compute git version
1 parent 003ddae commit 358a55e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/init-action.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
checkDiskUsage,
5454
getCodeQLMemoryLimit,
5555
getErrorMessage,
56+
isInTestMode,
5657
} from "./util";
5758

5859
export * from "./config/db-config";
@@ -935,6 +936,10 @@ export async function initConfig(
935936
await logGitVersionTelemetry(config, gitVersion);
936937
} catch (e) {
937938
logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`);
939+
// Throw the error in test mode so it's more visible.
940+
if (isInTestMode()) {
941+
throw e;
942+
}
938943
}
939944

940945
// The choice of overlay database mode depends on the selection of languages

src/git-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function getGitVersionOrThrow(): Promise<GitVersionInfo> {
5353
// Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1"
5454
// We capture just the major.minor.patch portion to ensure semver compatibility.
5555
const match = stdout.match(/^git version ((\d+\.\d+\.\d+).*)$/);
56-
if (match?.[1]) {
56+
if (match?.[1] && match?.[2]) {
5757
return new GitVersionInfo(match[2], match[1]);
5858
}
5959
throw new Error(`Could not parse Git version from output: ${stdout.trim()}`);

0 commit comments

Comments
 (0)