34 lines
1.3 KiB
Bash
Executable File
34 lines
1.3 KiB
Bash
Executable File
#!/bin/zsh
|
|
# Auto-commit and push the AISE502 course folder to Gitea.
|
|
# Run manually, from a background loop, or via the launchd agent in tools/ch.fhgr.aise502.autocommit.plist.
|
|
# Log: ~/Library/Logs/aise502-autocommit.log
|
|
|
|
REPO="/Users/florianherzog/development/Vorlesungen/AISE502"
|
|
LOG="$HOME/Library/Logs/aise502-autocommit.log"
|
|
export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin"
|
|
export GIT_TERMINAL_PROMPT=0
|
|
|
|
cd "$REPO" || { echo "$(date '+%F %T') repo not found" >> "$LOG"; exit 1; }
|
|
|
|
# never interfere with a rebase/merge in progress
|
|
if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ] || [ -f .git/MERGE_HEAD ]; then
|
|
echo "$(date '+%F %T') skipped: rebase/merge in progress" >> "$LOG"; exit 0
|
|
fi
|
|
|
|
git add -A
|
|
if ! git diff --cached --quiet; then
|
|
SUMMARY=$(git diff --cached --stat | tail -1 | sed 's/^ *//')
|
|
git commit -q -m "Auto-commit $(date '+%Y-%m-%d %H:%M'): ${SUMMARY}" \
|
|
&& echo "$(date '+%F %T') committed: ${SUMMARY}" >> "$LOG"
|
|
fi
|
|
|
|
# push only if local main is ahead of origin/main
|
|
if [ -n "$(git log origin/main..main --oneline 2>/dev/null)" ]; then
|
|
git pull -q --rebase --autostash origin main >> "$LOG" 2>&1
|
|
if git push -q origin main >> "$LOG" 2>&1; then
|
|
echo "$(date '+%F %T') pushed $(git rev-parse --short HEAD)" >> "$LOG"
|
|
else
|
|
echo "$(date '+%F %T') push FAILED (credentials or network)" >> "$LOG"
|
|
fi
|
|
fi
|