Add function to query git for all generated files

This commit is contained in:
Michael B. Gale
2025-11-19 15:35:46 +00:00
parent 0b4317954f
commit 1512f400b3
2 changed files with 72 additions and 0 deletions
+39
View File
@@ -1,4 +1,5 @@
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as core from "@actions/core";
@@ -392,3 +393,41 @@ test("getFileOidsUnderPath throws on unexpected output format", async (t) => {
runGitCommandStub.restore();
}
});
test("listFiles returns array of file paths", async (t) => {
sinon
.stub(gitUtils, "runGitCommand")
.resolves(["dir/file.txt", "README.txt"].join(os.EOL));
await t.notThrowsAsync(async () => {
const result = await gitUtils.listFiles("/some/path");
t.is(result.length, 2);
t.is(result[0], "dir/file.txt");
});
});
test("getGeneratedFiles returns generated files only", async (t) => {
const runGitCommandStub = sinon.stub(gitUtils, "runGitCommand");
runGitCommandStub
.onFirstCall()
.resolves(["dir/file.txt", "test.json", "README.txt"].join(os.EOL));
runGitCommandStub
.onSecondCall()
.resolves(
[
"dir/file.txt: linguist-generated: unspecified",
"test.json: linguist-generated: true",
"README.txt: linguist-generated: false",
].join(os.EOL),
);
await t.notThrowsAsync(async () => {
const result = await gitUtils.getGeneratedFiles("/some/path");
t.assert(runGitCommandStub.calledTwice);
t.is(result.length, 1);
t.is(result[0], "test.json");
});
});