#!/usr/bin/env node
import { execFileSync, spawnSync } from "node:child_process"
import path from "node:path"
import { fileURLToPath } from "node:url"

const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..")
const gitCheck = spawnSync("git", ["rev-parse", "--show-toplevel"], {
  cwd: repoRoot,
  encoding: "utf8",
})

if (gitCheck.status !== 0) {
  process.exit(0)
}

const topLevel = gitCheck.stdout.trim()

execFileSync("git", ["config", "core.hooksPath", ".githooks"], {
  cwd: topLevel,
  stdio: "ignore",
})
