mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-06 15:18:58 +00:00
fix(git-hooks): skip ignored staged paths
This commit is contained in:
@@ -103,6 +103,30 @@ describe("git-hooks/pre-commit (integration)", () => {
|
||||
expect(run(dir, "git", ["diff", "--cached", "--name-only"])).toBe("tracked.txt");
|
||||
});
|
||||
|
||||
it("does not re-add staged paths that are ignored by the current .gitignore", () => {
|
||||
const dir = makeTempRepoRoot(tempDirs, "openclaw-pre-commit-ignored-staged-");
|
||||
run(dir, "git", ["init", "-q", "--initial-branch=main"]);
|
||||
|
||||
const fakeBinDir = installPreCommitFixture(dir);
|
||||
mkdirSync(path.join(dir, ".agents", "skills", "discord-clawd"), { recursive: true });
|
||||
writeFileSync(path.join(dir, ".gitignore"), ".agents/skills/discord-clawd/\n", "utf8");
|
||||
writeFileSync(
|
||||
path.join(dir, ".agents", "skills", "discord-clawd", "SKILL.md"),
|
||||
"# Discord Clawd\n",
|
||||
"utf8",
|
||||
);
|
||||
|
||||
run(dir, "git", ["add", "--", ".gitignore"]);
|
||||
run(dir, "git", ["add", "-f", "--", ".agents/skills/discord-clawd/SKILL.md"]);
|
||||
|
||||
run(dir, "bash", ["git-hooks/pre-commit"], {
|
||||
PATH: `${fakeBinDir}:${process.env.PATH ?? ""}`,
|
||||
});
|
||||
|
||||
const staged = run(dir, "git", ["diff", "--cached", "--name-only"]).split("\n").filter(Boolean);
|
||||
expect(staged).toEqual([".agents/skills/discord-clawd/SKILL.md", ".gitignore"]);
|
||||
});
|
||||
|
||||
it("ignores FAST_COMMIT because the hook is already formatting-only", () => {
|
||||
const dir = makeTempRepoRoot(tempDirs, "openclaw-pre-commit-fast-");
|
||||
run(dir, "git", ["init", "-q", "--initial-branch=main"]);
|
||||
|
||||
Reference in New Issue
Block a user