diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 0000000..8908590 --- /dev/null +++ b/.githooks/post-commit @@ -0,0 +1,28 @@ +#!/bin/sh + +branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) +if [ -z "$branch" ]; then + echo "[post-commit] Detached HEAD; skipping auto-push." + exit 0 +fi + +if git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" >/dev/null 2>&1; then + echo "[post-commit] Pushing $branch to upstream..." + git push + push_status=$? +else + if git remote get-url origin >/dev/null 2>&1; then + echo "[post-commit] No upstream configured; pushing $branch to origin..." + git push -u origin "$branch" + push_status=$? + else + echo "[post-commit] No upstream or origin remote; skipping auto-push." + exit 0 + fi +fi + +if [ "$push_status" -ne 0 ]; then + echo "[post-commit] Auto-push failed with exit code $push_status. Commit was created locally." +fi + +exit 0