#!/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