Make git add work consistently with subdirectories (#473)

* Make git add work consistently with subdirectories

Currently, depending on your `commitMode`,
when running the action with `cwd` set to a subdirectory of a repo,
the action will either:

- `git-cli`: add the files changed in the subdirectory only
- `github-api`: add files changed anywhere in the repository

This commit brings github-api in line with git-cli,
so that it only adds files in the current working directory.

* Explicitly set `cwd` for all exec calls

* Avoid using `ExecOptions` from `@actions/exec`

* Rename type

* remove redundant `filter`

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
Sam Lanning
2025-05-10 12:34:27 +02:00
committed by GitHub
co-authored by Mateusz Burzyński
parent 7f0270e8f4
commit 3c24abeab2
4 changed files with 74 additions and 38 deletions
+7 -2
View File
@@ -15,11 +15,12 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
return;
}
const inputCwd = core.getInput("cwd");
const inputCwd = getOptionalInput("cwd");
if (inputCwd) {
core.info("changing directory to the one given as the input");
process.chdir(inputCwd);
}
const cwd = inputCwd || process.cwd();
const octokit = setupOctokit(githubToken);
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
@@ -27,7 +28,10 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
core.setFailed(`Invalid commit mode: ${commitMode}`);
return;
}
const git = new Git(commitMode === "github-api" ? octokit : undefined);
const git = new Git({
octokit: commitMode === "github-api" ? octokit : undefined,
cwd
});
let setupGitUser = core.getBooleanInput("setupGitUser");
@@ -100,6 +104,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
git,
octokit,
createGithubReleases: core.getBooleanInput("createGithubReleases"),
cwd,
});
if (result.published) {