diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index b501469f5..75be56ced 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -162158,11 +162158,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 7f7f4fbe8..268cfad57 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -107778,11 +107778,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 42d955963..7720f03cb 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -104212,11 +104212,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 27cb1e9b4..341449f7e 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -165672,11 +165672,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/init-action.js b/lib/init-action.js index 625562ed9..cf2669305 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -105306,11 +105306,11 @@ var getGitRoot = async function(sourceRoot) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index df13d019d..cefba2d56 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -104205,11 +104205,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index e710db491..8fcb62498 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -104072,11 +104072,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 485021d43..3527c5364 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -107363,11 +107363,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 484025f82..da345bf9a 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -107047,11 +107047,11 @@ var decodeGitFilePath = function(filePath) { var getFileOidsUnderPath = async function(basePath) { const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files." ); const fileOidMap = {}; - const regex = /^([0-9a-f]{40})_(.+)$/; + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex); diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index 4c51bc1d9..21327b549 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -347,9 +347,9 @@ test.serial("getFileOidsUnderPath returns correct file mapping", async (t) => { const runGitCommandStub = sinon .stub(gitUtils as any, "runGitCommand") .resolves( - "30d998ded095371488be3a729eb61d86ed721a18_lib/git-utils.js\n" + - "d89514599a9a99f22b4085766d40af7b99974827_lib/git-utils.js.map\n" + - "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_src/git-utils.ts", + "100644 30d998ded095371488be3a729eb61d86ed721a18 0\tlib/git-utils.js\n" + + "100644 d89514599a9a99f22b4085766d40af7b99974827 0\tlib/git-utils.js.map\n" + + "100644 a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96 0\tsrc/git-utils.ts", ); const result = await gitUtils.getFileOidsUnderPath("/fake/path"); @@ -362,7 +362,7 @@ test.serial("getFileOidsUnderPath returns correct file mapping", async (t) => { t.deepEqual(runGitCommandStub.firstCall.args, [ "/fake/path", - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files.", ]); }); @@ -371,9 +371,9 @@ test.serial("getFileOidsUnderPath handles quoted paths", async (t) => { sinon .stub(gitUtils as any, "runGitCommand") .resolves( - "30d998ded095371488be3a729eb61d86ed721a18_lib/normal-file.js\n" + - 'd89514599a9a99f22b4085766d40af7b99974827_"lib/file with spaces.js"\n' + - 'a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_"lib/file\\twith\\ttabs.js"', + "100644 30d998ded095371488be3a729eb61d86ed721a18 0\tlib/normal-file.js\n" + + '100644 d89514599a9a99f22b4085766d40af7b99974827 0\t"lib/file with spaces.js"\n' + + '100644 a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96 0\t"lib/file\\twith\\ttabs.js"', ); const result = await gitUtils.getFileOidsUnderPath("/fake/path"); @@ -398,9 +398,9 @@ test.serial( sinon .stub(gitUtils as any, "runGitCommand") .resolves( - "30d998ded095371488be3a729eb61d86ed721a18_lib/git-utils.js\n" + + "100644 30d998ded095371488be3a729eb61d86ed721a18 0\tlib/git-utils.js\n" + "invalid-line-format\n" + - "a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96_src/git-utils.ts", + "100644 a47c11f5bfdca7661942d2c8f1b7209fb0dfdf96 0\tsrc/git-utils.ts", ); await t.throwsAsync( diff --git a/src/git-utils.ts b/src/git-utils.ts index 6b792ea54..16bf01f59 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -252,24 +252,28 @@ export const getGitRoot = async function ( * * @param basePath A path into the Git repository. * @returns a map from file paths (relative to `basePath`) to Git OIDs. - * @throws {Error} if "git ls-tree" produces unexpected output. + * @throws {Error} if "git ls-files" produces unexpected output. */ export const getFileOidsUnderPath = async function ( basePath: string, ): Promise<{ [key: string]: string }> { // Without the --full-name flag, the path is relative to the current working // directory of the git command, which is basePath. + // + // We use --stage rather than --format here because --stage has been available since Git 2.11.0, + // while --format was only introduced in Git 2.38.0, which would limit overlay rollout. const stdout = await runGitCommand( basePath, - ["ls-files", "--recurse-submodules", "--format=%(objectname)_%(path)"], + ["ls-files", "--recurse-submodules", "--stage"], "Cannot list Git OIDs of tracked files.", ); const fileOidMap: { [key: string]: string } = {}; - // With --format=%(objectname)_%(path), the output is a list of lines like: - // 30d998ded095371488be3a729eb61d86ed721a18_lib/git-utils.js - // d89514599a9a99f22b4085766d40af7b99974827_lib/git-utils.js.map - const regex = /^([0-9a-f]{40})_(.+)$/; + // With --stage, the output is a list of lines like: + // 100644 4c51bc1d9e86cd86e01b0f340cb8ce095c33b283 0\tsrc/git-utils.test.ts + // 100644 6b792ea543ce75d7a8a03df591e3c85311ecb64f 0\tsrc/git-utils.ts + // The fields are: \t + const regex = /^[0-9]+ ([0-9a-f]{40}) [0-9]+\t(.+)$/; for (const line of stdout.split("\n")) { if (line) { const match = line.match(regex);