From 73564f578e34a22f9ded2019d349cae2d2551ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Gla=CC=88ser?= Date: Sun, 22 Mar 2026 09:22:36 +0100 Subject: [PATCH] chore: add auto-push git workflow --- AGENTS.md | 9 ++++++ scripts/install-git-hooks.sh | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 AGENTS.md create mode 100755 scripts/install-git-hooks.sh diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..bc947e0 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,9 @@ +# Agent Instructions + +- Zu jeder Codeaenderung eine Commit-Nachricht vorschlagen. +- Commit-Nachricht so kurz wie moeglich halten, maximal 120 Zeichen. +- Gilt fuer jede Sitzung in diesem Repository. +- Standard-Workflow fuer den Agenten: Nach jeder Codeaenderung automatisch `git add`, `git commit` und `git push` ausfuehren. +- Falls `git push` fehlschlaegt (z. B. Konflikt oder Reject), den Fehler sofort melden und kurz den naechsten sicheren Schritt vorschlagen. +- Ausnahme: Nur dann nicht automatisch committen und pushen, wenn der User es fuer den konkreten Task explizit anders vorgibt. +- Konsistente, saubere Loesungen umsetzen; keine Quick-Fixes als Endloesung. diff --git a/scripts/install-git-hooks.sh b/scripts/install-git-hooks.sh new file mode 100755 index 0000000..40aa34c --- /dev/null +++ b/scripts/install-git-hooks.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +set -eu + +repo_root=$(git rev-parse --show-toplevel) +hooks_dir="$repo_root/.git/hooks" + +mkdir -p "$hooks_dir" + +cat >"$hooks_dir/prepare-commit-msg" <<'EOF' +#!/bin/sh + +# Fill commit message from .git/CODEX_COMMIT_MSG when user commits via UI without text. + +msg_file="$1" +commit_source="${2:-}" + +case "$commit_source" in + message|merge|squash) + exit 0 + ;; +esac + +# If there is already a real message line, keep it untouched. +if grep -Eq '^[[:space:]]*[^#[:space:]]' "$msg_file"; then + exit 0 +fi + +codex_msg_file="$(git rev-parse --git-path CODEX_COMMIT_MSG)" + +if [ -s "$codex_msg_file" ]; then + # Take first line only to keep messages short and predictable. + head -n 1 "$codex_msg_file" | tr -d '\r' > "$msg_file" +fi +EOF + +cat >"$hooks_dir/post-commit" <<'EOF' +#!/bin/sh + +# Auto-push after each successful commit. +# If no upstream exists yet, set it to origin/. + +branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || exit 0 +codex_msg_file="$(git rev-parse --git-path CODEX_COMMIT_MSG)" + +if ! git remote get-url origin >/dev/null 2>&1; then + echo "post-commit: remote 'origin' not found, skipping auto-push." >&2 + rm -f "$codex_msg_file" >/dev/null 2>&1 || true + exit 0 +fi + +if git rev-parse --abbrev-ref --symbolic-full-name '@{u}' >/dev/null 2>&1; then + git push +else + git push --set-upstream origin "$branch" +fi + +# Consume prepared Codex message after the commit. +rm -f "$codex_msg_file" >/dev/null 2>&1 || true +EOF + +chmod +x "$hooks_dir/prepare-commit-msg" "$hooks_dir/post-commit" +echo "Installed git hooks in $hooks_dir"