Files
TX/sync-to-gitea.sh
T
Replit Agent 83ba0e9671 Create a script to easily sync local work with the Gitea server
Add a new shell script to automate fetching, merging, and pushing changes to the Gitea remote repository.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 66d30e41-f995-49c8-bcc0-9c5fdebac0ab
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/fKZh36i
Replit-Helium-Checkpoint-Created: true
2026-06-03 20:14:00 +00:00

60 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# One-command helper: merge the Gitea server's changes into this Repl's work and push.
# Run from the Replit Shell with: bash sync-to-gitea.sh
set -uo pipefail
REMOTE="origin"
BRANCH="main"
echo "==> Checking GITEA_TOKEN secret is available..."
if [ -z "${GITEA_TOKEN:-}" ]; then
echo "ERROR: GITEA_TOKEN is not set in this shell. Cannot authenticate to Gitea."
exit 1
fi
echo "==> Preparing credential helper (token never printed)..."
cat > /tmp/ap.sh <<'EOF'
#!/usr/bin/env bash
case "$1" in
*Username*) echo "rafraa" ;;
*) printf '%s' "$GITEA_TOKEN" ;;
esac
EOF
chmod +x /tmp/ap.sh
export GIT_ASKPASS=/tmp/ap.sh GIT_TERMINAL_PROMPT=0
echo "==> Current branch:"
git rev-parse --abbrev-ref HEAD
echo "==> Fetching $REMOTE/$BRANCH ..."
if ! git fetch "$REMOTE" "$BRANCH"; then
echo "ERROR: fetch failed. The Gitea server may be unreachable right now. Try again in a moment."
exit 1
fi
echo "==> Merging $REMOTE/$BRANCH into local $BRANCH (keeping both sides)..."
if ! git merge "$REMOTE/$BRANCH" -m "Merge Gitea server changes with Replit work"; then
echo ""
echo "MERGE CONFLICT: the merge could not finish automatically."
echo "Nothing was pushed. Copy everything above and send it to the assistant to resolve."
exit 1
fi
echo "==> Pushing local $BRANCH to $REMOTE ..."
if ! git push "$REMOTE" "$BRANCH"; then
echo "ERROR: push failed. Copy everything above and send it to the assistant."
exit 1
fi
echo ""
echo "==> SUCCESS. Verifying remote now matches local..."
LOCAL=$(git rev-parse "$BRANCH")
REMOTE_SHA=$(git ls-remote "$REMOTE" -h "refs/heads/$BRANCH" | awk '{print $1}')
echo " local $BRANCH = $LOCAL"
echo " server $BRANCH = $REMOTE_SHA"
if [ "$LOCAL" = "$REMOTE_SHA" ]; then
echo " MATCH — your work is now on Gitea."
else
echo " WARNING: they do not match yet. Send this output to the assistant."
fi