Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for executable files
  • Loading branch information
s0 committed May 7, 2025
commit e151efe7818bc9d24b36dd4c1ced50b21549d122
57 changes: 57 additions & 0 deletions src/test/integration/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const makeFileChanges = async (
repoDirectory: string,
changegroup:
| "standard"
| "with-executable-file"
| "with-ignored-symlink"
| "with-included-valid-symlink"
| "with-included-invalid-symlink",
Expand Down Expand Up @@ -120,6 +121,17 @@ const makeFileChanges = async (
path.join(repoDirectory, "coverage", "foo", "bar"),
"This file should be ignored",
);
if (changegroup === "with-executable-file") {
// Add an executable file
await fs.promises.writeFile(
path.join(repoDirectory, "executable-file.sh"),
"#!/bin/bash\necho hello",
);
await fs.promises.chmod(
path.join(repoDirectory, "executable-file.sh"),
0o755,
);
}
if (changegroup === "with-ignored-symlink") {
// node_modules is ignored in this repo
await fs.promises.mkdir(path.join(repoDirectory, "node_modules"), {
Expand Down Expand Up @@ -341,6 +353,51 @@ describe("git", () => {
});
});

it(`should throw appropriate error when executable file is present`, async () => {
const branch = `${TEST_BRANCH_PREFIX}-executable-file`;
branches.push(branch);

await fs.promises.mkdir(testDir, { recursive: true });
const repoDirectory = path.join(testDir, `repo-executable-file`);

// Clone the git repo locally using the git cli and child-process
await new Promise<void>((resolve, reject) => {
const p = execFile(
"git",
["clone", process.cwd(), `repo-executable-file`],
{ cwd: testDir },
(error) => {
if (error) {
reject(error);
} else {
resolve();
}
},
);
p.stdout?.pipe(process.stdout);
p.stderr?.pipe(process.stderr);
});

await makeFileChanges(repoDirectory, "with-executable-file");

// Push the changes
await expect(() =>
commitChangesFromRepo({
octokit,
...REPO,
branch,
message: {
headline: "Test commit",
body: "This is a test commit",
},
repoDirectory,
log,
}),
).rejects.toThrow(
"Unexpected executable file at executable-file.sh, GitHub API only supports non-executable files and directories. You may need to add this file to .gitignore",
);
});

it("should correctly be able to base changes off specific commit", async () => {
const branch = `${TEST_BRANCH_PREFIX}-specific-base`;
branches.push(branch);
Expand Down