Created
October 18, 2025 17:26
-
-
Save steipete/88a38157e8c9d1896443eca09e95e163 to your computer and use it in GitHub Desktop.
Simple commit script so agents don't f*ck up. Disallow other git commands. (except status/diff)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| usage() { | |
| printf 'Usage: %s "commit message" "file" ["file" ...]\n' "$(basename "$0")" >&2 | |
| exit 2 | |
| } | |
| if [ "$#" -lt 2 ]; then | |
| usage | |
| fi | |
| commit_message=$1 | |
| shift | |
| if [[ "$commit_message" != *[![:space:]]* ]]; then | |
| printf 'Error: commit message must not be empty\n' >&2 | |
| exit 1 | |
| fi | |
| if [ -e "$commit_message" ]; then | |
| printf 'Error: first argument looks like a file path ("%s"); provide the commit message first\n' "$commit_message" >&2 | |
| exit 1 | |
| fi | |
| if [ "$#" -eq 0 ]; then | |
| usage | |
| fi | |
| files=("$@") | |
| for file in "${files[@]}"; do | |
| if [ ! -e "$file" ]; then | |
| printf 'Error: file not found: %s\n' "$file" >&2 | |
| exit 1 | |
| fi | |
| done | |
| git restore --staged :/ | |
| git add -- "${files[@]}" | |
| if git diff --staged --quiet; then | |
| printf 'Warning: no staged changes detected for: %s\n' "${files[*]}" >&2 | |
| exit 1 | |
| fi | |
| git commit -m "$commit_message" -- "${files[@]}" | |
| printf 'Committed "%s" with files: %s\n' "$commit_message" "${files[*]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment