flake-update-20260505
 1#!/usr/bin/env bash
 2# Git post-checkout hook (installed via git template)
 3# Automatically installs GitHub Copilot hooks to .github/hooks/
 4#
 5# This runs after:
 6# - git clone (prev_head is null-ref)
 7# - git checkout/switch (branch checkout when flag=1)
 8
 9set -euo pipefail
10
11COPILOT_HOOKS_SOURCE="${XDG_CONFIG_HOME:-$HOME/.config}/copilot-hooks"
12
13# Only proceed if we have hooks to install
14if [[ ! -d "$COPILOT_HOOKS_SOURCE" ]]; then
15    exit 0
16fi
17
18# Only install if .github/hooks doesn't exist yet
19if [[ -d ".github/hooks" ]]; then
20    exit 0
21fi
22
23# Check if this looks like a repo that might use Copilot
24# (has .github/ directory or is a code project)
25if [[ ! -d ".github" ]] && [[ ! -f "package.json" ]] && [[ ! -f "go.mod" ]] && [[ ! -f "Cargo.toml" ]] && [[ ! -f "flake.nix" ]] && [[ ! -f "pyproject.toml" ]]; then
26    exit 0
27fi
28
29# Install hooks
30mkdir -p .github/hooks
31cp -r "$COPILOT_HOOKS_SOURCE"/* .github/hooks/ 2>/dev/null || true
32
33# Make scripts executable
34chmod +x .github/hooks/*.sh 2>/dev/null || true
35
36echo "Installed Copilot hooks to .github/hooks/"