Save a computation of the git root

This commit is contained in:
Henry Mercer
2026-03-30 13:37:14 +01:00
parent 0592832ed8
commit be0a156326
12 changed files with 88 additions and 87 deletions
+8 -8
View File
@@ -162174,17 +162174,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs2.existsSync(path3.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -107769,17 +107769,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path4.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -104228,17 +104228,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs2.existsSync(path3.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -165686,17 +165686,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path4.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+11 -10
View File
@@ -105312,17 +105312,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path5.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
@@ -107048,13 +107048,14 @@ async function validateOverlayDatabaseMode(overlayDatabaseMode, useOverlayDataba
);
return new Failure("incompatible-codeql" /* IncompatibleCodeQl */);
}
if (await getGitRoot(sourceRoot) === void 0) {
const gitRoot = await getGitRoot(sourceRoot);
if (gitRoot === void 0) {
logger.warning(
`Cannot build an ${overlayDatabaseMode} database because the source root "${sourceRoot}" is not inside a git repository. Falling back to creating a normal full database instead.`
);
return new Failure("no-git-root" /* NoGitRoot */);
}
if (await hasSubmodules(sourceRoot)) {
if (hasSubmodules(gitRoot)) {
if (gitVersion === void 0) {
logger.warning(
`Cannot build an ${overlayDatabaseMode} database because the repository has submodules and the Git version could not be determined. Falling back to creating a normal full database instead.`
+8 -8
View File
@@ -104221,17 +104221,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs2.existsSync(path3.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -104087,17 +104087,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path3.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -107377,17 +107377,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path4.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+8 -8
View File
@@ -107062,17 +107062,17 @@ var getGitRoot = async function(sourceRoot) {
return void 0;
}
};
async function hasSubmodules(basePath) {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`
);
}
function hasSubmodules(gitRoot) {
return fs3.existsSync(path3.join(gitRoot, ".gitmodules"));
}
var getFileOidsUnderPath = async function(basePath) {
const args = await hasSubmodules(basePath) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const gitRoot = await getGitRoot(basePath);
if (gitRoot === void 0) {
throw new Error(
`Cannot determine the Git root from ${basePath}.`
);
}
const args = hasSubmodules(gitRoot) ? ["ls-files", "--recurse-submodules", "--stage"] : ["ls-files", "--stage"];
const stdout = await runGitCommand(
basePath,
args,
+1 -1
View File
@@ -1099,7 +1099,7 @@ const checkOverlayEnablementMacro = test.macro({
}
// Mock submodule detection
sinon.stub(gitUtils, "hasSubmodules").resolves(setup.hasSubmodules);
sinon.stub(gitUtils, "hasSubmodules").returns(setup.hasSubmodules);
// Mock default branch detection
sinon
+3 -2
View File
@@ -970,7 +970,8 @@ async function validateOverlayDatabaseMode(
);
return new Failure(OverlayDisabledReason.IncompatibleCodeQl);
}
if ((await getGitRoot(sourceRoot)) === undefined) {
const gitRoot = await getGitRoot(sourceRoot);
if (gitRoot === undefined) {
logger.warning(
`Cannot build an ${overlayDatabaseMode} database because ` +
`the source root "${sourceRoot}" is not inside a git repository. ` +
@@ -978,7 +979,7 @@ async function validateOverlayDatabaseMode(
);
return new Failure(OverlayDisabledReason.NoGitRoot);
}
if (await hasSubmodules(sourceRoot)) {
if (hasSubmodules(gitRoot)) {
if (gitVersion === undefined) {
logger.warning(
`Cannot build an ${overlayDatabaseMode} database because ` +
+9 -10
View File
@@ -248,16 +248,12 @@ export const getGitRoot = async function (
};
/**
* Returns true if the Git repository containing `basePath` has submodules
* registered (i.e. a `.gitmodules` file exists at the repository root).
* Returns true if the Git repository has submodules registered (i.e. a
* `.gitmodules` file exists at the repository root).
*
* @param gitRoot The root of the Git repository.
*/
export async function hasSubmodules(basePath: string): Promise<boolean> {
const gitRoot = await getGitRoot(basePath);
if (gitRoot === undefined) {
throw new Error(
`Cannot determine whether the repository has submodules because the Git root could not be found from ${basePath}.`,
);
}
export function hasSubmodules(gitRoot: string): boolean {
return fs.existsSync(path.join(gitRoot, ".gitmodules"));
}
@@ -283,7 +279,10 @@ export const getFileOidsUnderPath = async function (
// We only pass --recurse-submodules when the repository actually has
// submodules, because the combination of --recurse-submodules and --stage is
// only supported since Git 2.36.0.
const args = (await hasSubmodules(basePath))
const gitRoot = await getGitRoot(basePath);
const mayHaveSubmodules =
gitRoot === undefined ? true : hasSubmodules(gitRoot);
const args = mayHaveSubmodules
? ["ls-files", "--recurse-submodules", "--stage"]
: ["ls-files", "--stage"];
const stdout = await runGitCommand(