mirror of
https://github.com/amatya-aditya/advanced-multi-column.git
synced 2026-07-22 06:13:08 +00:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { chmodSync, existsSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { spawnSync } from "node:child_process";
|
|
|
|
const proc = globalThis.process;
|
|
|
|
function run(command, args, options = {}) {
|
|
return spawnSync(command, args, {
|
|
stdio: "pipe",
|
|
encoding: "utf8",
|
|
...options,
|
|
});
|
|
}
|
|
|
|
const insideRepo = run("git", ["rev-parse", "--is-inside-work-tree"]);
|
|
if (insideRepo.status !== 0 || insideRepo.stdout.trim() !== "true") {
|
|
proc.stdout.write("[hooks] Not a git repository. Skipping git hook setup.\n");
|
|
proc.exit(0);
|
|
}
|
|
|
|
const setHooksPath = run("git", ["config", "core.hooksPath", ".githooks"]);
|
|
if (setHooksPath.status !== 0) {
|
|
proc.stderr.write(
|
|
setHooksPath.stderr || "[hooks] Failed to set core.hooksPath.\n",
|
|
);
|
|
proc.exit(setHooksPath.status ?? 1);
|
|
}
|
|
|
|
proc.stdout.write("[hooks] Installed git hooks path: .githooks\n");
|
|
|
|
const hooks = ["pre-commit", "pre-push", "commit-msg"];
|
|
for (const hook of hooks) {
|
|
const fullPath = join(proc.cwd(), ".githooks", hook);
|
|
if (!existsSync(fullPath)) continue;
|
|
try {
|
|
chmodSync(fullPath, 0o755);
|
|
} catch {
|
|
// Best effort on platforms/filesystems that ignore POSIX perms.
|
|
}
|
|
}
|