Install hooks into the repo's own hooks dir, ignoring core.hooksPath

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
christianandClaude Opus 5.5 committed 2026-10-21 00:55:32 +02:00
1 parent 24541f0602
commit 480ed6a8b2
2 files changed
+19 -2

No files matched your search

+15 -1
View File
@@ -1,7 +1,7 @@
import { test, after } from "node:test";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, cpSync, statSync } from "node:fs";
import { mkdtempSync, rmSync, cpSync, statSync, writeFileSync, existsSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
@@ -74,6 +74,20 @@ test("install-hooks copies every hook into .git/hooks as an executable", () => {
}
});
test("install-hooks ignores a global core.hooksPath", () => {
const repo = repoOn("fix/x");
const elsewhere = mkdtempSync(join(tmpdir(), "todo-hooks-"));
dirs.push(elsewhere);
const globalConfig = join(elsewhere, "gitconfig");
writeFileSync(globalConfig, `[core]\n\thooksPath = ${elsewhere}\n`);
cpSync(join(ROOT, "scripts"), join(repo, "scripts"), { recursive: true });
cpSync(HOOKS, join(repo, ".githooks"), { recursive: true });
const res = run("sh", [join(repo, "scripts", "install-hooks.sh")], { env: { ...env, GIT_CONFIG_GLOBAL: globalConfig } });
assert.equal(res.status, 0, res.stderr);
assert.ok(existsSync(join(repo, ".git", "hooks", "pre-push")));
assert.equal(existsSync(join(elsewhere, "pre-push")), false);
});
test("install-hooks skips cleanly outside a git checkout", () => {
const dir = mkdtempSync(join(tmpdir(), "todo-hooks-"));
dirs.push(dir);