TsukiNi22/ai-utils / skills/git/pre-commit
pre-commit
FlaggedSet up the xstyle pre-commit hook of a git repository in Tsukini's way - checks the style of what is committed with xstyle (only the staged lines by default), refuses the commit on a major / unforgivable issue, warns on minor ones, only warns when xstyle is not installed - every option asked first with several choices (scope, fail / warn levels, safe auto fixes, missing xstyle, output, languages / excludes / ignored rules, local or shared .githooks), the needed tools checked and installed on request (xstyle, cmake, clang++, libutils), an existing hook kept and chained, and a throwaway demo repository to try it. Use whenever the user wants a pre-commit hook, a git hook checking the style, to block commits with style errors, or to change / remove that hook.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.4 KB |
| requires.txt | markdown | 16 B |
| scripts/demo_repo.shexecutable | script | 3.6 KB |
| scripts/install_hook.shexecutable | script | 8.0 KB |
| templates/pre-commitexecutable | script | 4.7 KB |
scripts/demo_repo.sh
View on GitHub#!/bin/bash
# Create a throwaway git repository to try the xstyle pre-commit hook (clean / warning / refused / no xstyle).
#
# Usage: demo_repo.sh [dir] [install_hook.sh options...] (default dir: /tmp/xstyle-hook-demo, recreated)
# The demo files hold their issues on purpose: xstyle: ignore-file G-TODO,G-TRAILING
set -euo pipefail
# Command running a remote setup.sh, with the download tool available: curl, else wget, else python3, else curl
remote_setup() {
local url="$1" fetch
shift
if command -v curl > /dev/null 2>&1; then fetch="curl -fsSL $url"
elif command -v wget > /dev/null 2>&1; then fetch="wget -qO- $url"
elif command -v python3 > /dev/null 2>&1; then
fetch="python3 -c 'import sys, urllib.request; sys.stdout.buffer.write(urllib.request.urlopen(sys.argv[1]).read())' $url"
else fetch="curl -fsSL $url"
fi
echo "$fetch | bash${*:+ -s -- $*}"
}
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[[ "${1:-}" = "-h" ]] || [[ "${1:-}" = "--help" ]] && { sed -n '2,5p' "$0" | sed 's/^# \{0,1\}//'; exit 0; }
DIR="${1:-/tmp/xstyle-hook-demo}"
[[ $# -gt 0 ]] && shift
case "$DIR" in
/tmp/*) ;;
*) [[ ! -e "$DIR" ]] || [[ -f "$DIR/TRY.md" ]] || { echo "Error: $DIR exists and is not a demo repository" >&2; exit 1; } ;;
esac
[[ -f "$DIR/TRY.md" ]] && rm -rf "$DIR"
mkdir -p "$DIR/src"
cd "$DIR"
git init -q
git config user.name "xstyle demo"
git config user.email "demo@example.com"
# One file per verdict of the hook (default config: fail on major, warn on minor)
cat > src/clean.py << 'EOF'
def add(a: int, b: int) -> int:
return a + b
EOF
cat > src/minor.py << 'EOF'
def sub(a: int, b: int) -> int:
return a - b # TODO: check the underflow
EOF
cat > src/major.cpp << 'EOF'
int main(void)
{
char* p = NULL;
return p == nullptr ? 0 : 1;
}
EOF
cat > src/fixable.sh << 'EOF'
#!/bin/bash
set -euo pipefail
if [[ -n "${1:-}" ]]; then
echo "$1"
fi
EOF
cat > TRY.md << 'EOF'
# xstyle pre-commit hook: try it
Hook: `.git/hooks/pre-commit` (config block at its top). Each scenario is independent.
| Try | Command | Expected |
|---|---|---|
| clean file | `git add src/clean.py && git commit -m clean` | commit accepted, nothing printed |
| minor issue | `git add src/minor.py && git commit -m minor` | issue listed + warning, commit accepted |
| major issue | `git add src/major.cpp && git commit -m major` | issue listed, **commit refused** (exit 1) |
| auto fixable | `git add src/fixable.sh && git commit -m sh` | trailing space: minor warning (or fixed with `--fix safe`) |
| fix then commit | `xstyle --fix --staged && git add -u && git commit -m major` | accepted once fixed |
| xstyle missing | `XSTYLE_BIN=/nonexistent git commit -m major` | warning "xstyle not found", commit accepted |
| skip once | `git commit --no-verify -m major` or `XSTYLE_HOOK=0 git commit ...` | no check |
| only staged lines | edit a committed file, stage one line | only the staged lines are checked |
| other config | `{{SETUP}} hook --fail-on minor` (or `--fix safe`, `--scope files`, `--missing fail`...) | new behavior |
| state | `{{SETUP}} hook status` | config of the hook |
Undo the last commit to retry: `git reset --soft HEAD~1`. Recreate everything: `demo_repo.sh` again (or `{{SETUP}} hook` in a new repository).
EOF
# Remote setup command of this machine in the scenarios ('|' escaped in the Markdown table)
setup="$(remote_setup https://raw.githubusercontent.com/TsukiNi22/ai-utils/main/setup.sh)"
setup="${setup% | bash} \\| bash -s --"
content="$(< TRY.md)"
printf '%s\n' "${content//\{\{SETUP\}\}/$setup}" > TRY.md
"$SELF_DIR/install_hook.sh" install "$@" | sed 's/^/ /'
echo "Demo repository ready: $DIR (scenarios in $DIR/TRY.md)"
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |