From e59adf069504db1386581c8a6a62faf0cee6b2c7 Mon Sep 17 00:00:00 2001 From: codex-bot Date: Wed, 27 Aug 2025 20:39:48 -0500 Subject: [PATCH] fix(update.sh): pull before copy, clean state, retry push --- update.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/update.sh b/update.sh index 51a0443..bceffa1 100755 --- a/update.sh +++ b/update.sh @@ -40,10 +40,25 @@ if [[ ! -d "$REPO_DIR/.git" ]]; then fi cd "$REPO_DIR" -cp "$SRC_FILE" "$DEST_FILE" -git pull +# Ensure a clean state for pulling: discard any local changes to the target file +# from previous failed runs so that pull (especially with pull.rebase=true) works. +if ! git diff --quiet -- "$DEST_FILE" 2>/dev/null || ! git diff --quiet --cached -- "$DEST_FILE" 2>/dev/null; then + git restore --worktree --staged -- "$DEST_FILE" || true +fi + +# Update from remote before making local changes (works with pull.rebase=true) +git pull --rebase --autostash || git pull --rebase + +# Copy and commit if there are changes +cp "$SRC_FILE" "$DEST_FILE" git add "$DEST_FILE" COMMIT_MSG="Update banned IP list — $(date '+%Y-%m-%d %H:%M:%S %Z')" git commit -m "$COMMIT_MSG" || echo "No changes to commit." -git push + +# Push; if rejected due to remote updates, rebase and retry once +if ! git push; then + echo "Push failed; rebasing onto remote and retrying..." >&2 + git pull --rebase --autostash || git pull --rebase + git push +fi