fix(update.sh): pull before copy, clean state, retry push
This commit is contained in:
parent
55fd509305
commit
e59adf0695
1 changed files with 18 additions and 3 deletions
19
update.sh
19
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."
|
||||
|
||||
# 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue