Skip to content

Instantly share code, notes, and snippets.

@withzombies
Created July 10, 2025 00:03
Show Gist options
  • Save withzombies/6dcfbd064c70d478f8aa06dd328b801e to your computer and use it in GitHub Desktop.
Save withzombies/6dcfbd064c70d478f8aa06dd328b801e to your computer and use it in GitHub Desktop.
a git wrapper for LLMs
#!/bin/bash
# A git wrapper to prevent the use of '--no-verify' on commits.
# This ensures that all pre-commit hooks, such as linters and tests, are always executed.
# Find the absolute path to the real git executable, avoiding this script itself.
# 'command -v' is a reliable way to find the first 'git' in the PATH.
REAL_GIT=$(command -v git)
# If this script is the first 'git' in the PATH, we need to find the *next* one.
if [ "$REAL_GIT" = "$0" ]; then
# Use 'which -a' to find all instances and grep to exclude this script's path.
REAL_GIT=$(which -a git | grep -v "^$0$" | head -n 1)
fi
# Failsafe in case the real git cannot be found.
if [ -z "$REAL_GIT" ]; then
echo "FATAL: Could not locate the real 'git' executable. Please check your PATH." >&2
exit 127
fi
# --- Main Logic ---
# We only care about the 'commit' subcommand.
if [ "$1" = "commit" ]; then
# Iterate through all arguments passed to the script.
for arg in "$@"; do
if [ "$arg" = "--no-verify" ]; then
# The forbidden flag was found. Block the commit and provide guidance.
echo "------------------------------------------------------------------" >&2
echo "❌ ERROR: Commit Rejected." >&2
echo "The use of the '--no-verify' flag is disabled for this repository." >&2
echo "------------------------------------------------------------------" >&2
echo "" >&2
echo "🤖 GUIDANCE FOR THE AI AGENT:" >&2
echo "You have attempted to bypass the required pre-commit verification steps. All code must pass quality checks (formatting, linting, and tests) before it can be committed." >&2
echo "" >&2
echo "DO NOT BYPASS THE CHECKS. YOU MUST FIX THE UNDERLYING ERRORS." >&2
echo "" >&2
echo "The pre-commit hook is likely failing. Diagnose and fix the issues. Search for advice if you get stuck." >&2
echo "" >&2
echo "After all commands complete successfully, attempt the commit again *without* the '--no-verify' flag." >&2
# Exit with a non-zero status code to indicate failure.
exit 1
fi
done
fi
# If the script reaches this point, the command is valid.
# Execute the real git command with all the original arguments.
exec "$REAL_GIT" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment