fix(update.sh): pull before copy, clean state, retry push

This commit is contained in:
codex-bot 2025-08-27 20:39:48 -05:00
commit e59adf0695

View file

@ -40,10 +40,25 @@ if [[ ! -d "$REPO_DIR/.git" ]]; then
fi fi
cd "$REPO_DIR" 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" git add "$DEST_FILE"
COMMIT_MSG="Update banned IP list — $(date '+%Y-%m-%d %H:%M:%S %Z')" 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 commit -m "$COMMIT_MSG" || echo "No changes to commit."
# 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 git push
fi