mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
fix(tooling): add fast mode to committer helper
This commit is contained in:
@@ -37,10 +37,24 @@ function writeRepoFile(repo: string, relativePath: string, contents: string) {
|
||||
writeFileSync(fullPath, contents);
|
||||
}
|
||||
|
||||
function installHook(repo: string, relativePath: string, contents: string) {
|
||||
const fullPath = path.join(repo, relativePath);
|
||||
mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
writeFileSync(fullPath, contents, {
|
||||
encoding: "utf8",
|
||||
mode: 0o755,
|
||||
});
|
||||
git(repo, "config", "core.hooksPath", path.dirname(relativePath));
|
||||
}
|
||||
|
||||
function commitWithHelper(repo: string, commitMessage: string, ...args: string[]) {
|
||||
return run(repo, "bash", [scriptPath, commitMessage, ...args]);
|
||||
}
|
||||
|
||||
function commitWithHelperArgs(repo: string, ...args: string[]) {
|
||||
return run(repo, "bash", [scriptPath, ...args]);
|
||||
}
|
||||
|
||||
function committedPaths(repo: string) {
|
||||
const output = git(repo, "diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD");
|
||||
return output.split("\n").filter(Boolean).toSorted();
|
||||
@@ -105,4 +119,45 @@ describe("scripts/committer", () => {
|
||||
expect(committedPaths(repo)).toEqual(["CHANGELOG.md"]);
|
||||
expect(git(repo, "status", "--short")).toContain("M unrelated.ts");
|
||||
});
|
||||
|
||||
it("supports --fast before the commit message", () => {
|
||||
const repo = createRepo();
|
||||
writeRepoFile(repo, "note.txt", "hello\n");
|
||||
|
||||
const output = commitWithHelperArgs(repo, "--fast", "test: fast helper", "note.txt");
|
||||
|
||||
expect(output).toContain('Committed "test: fast helper" with 1 files');
|
||||
expect(committedPaths(repo)).toEqual(["note.txt"]);
|
||||
});
|
||||
|
||||
it("supports combining --force and --fast", () => {
|
||||
const repo = createRepo();
|
||||
writeRepoFile(repo, "note.txt", "hello\n");
|
||||
|
||||
const output = commitWithHelperArgs(
|
||||
repo,
|
||||
"--force",
|
||||
"--fast",
|
||||
"test: fast forced helper",
|
||||
"note.txt",
|
||||
);
|
||||
|
||||
expect(output).toContain('Committed "test: fast forced helper" with 1 files');
|
||||
expect(committedPaths(repo)).toEqual(["note.txt"]);
|
||||
});
|
||||
|
||||
it("passes FAST_COMMIT through to git hooks when using --fast", () => {
|
||||
const repo = createRepo();
|
||||
installHook(
|
||||
repo,
|
||||
".githooks/pre-commit",
|
||||
'#!/usr/bin/env bash\nset -euo pipefail\n[ "${FAST_COMMIT:-}" = "1" ] || exit 91\n',
|
||||
);
|
||||
writeRepoFile(repo, "note.txt", "hello\n");
|
||||
|
||||
const output = commitWithHelperArgs(repo, "--fast", "test: fast hook env", "note.txt");
|
||||
|
||||
expect(output).toContain('Committed "test: fast hook env" with 1 files');
|
||||
expect(committedPaths(repo)).toEqual(["note.txt"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user