#!/usr/bin/env bash # Sync to Hugging Face Space — bypasses Cursor's broken GIT_ASKPASS. set -euo pipefail cd "$(dirname "$0")" unset GIT_ASKPASS SSH_ASKPASS SPACE_REMOTE="${SPACE_REMOTE:-https://huggingface.co/spaces/vinayedula/RefDiffNet}" USER="${HF_USER:-vinayedula}" FORCE="${FORCE_PUSH:-0}" if ! command -v hf >/dev/null 2>&1; then echo "ERROR: 'hf' not found. Run: pip install -U huggingface_hub" exit 1 fi TOKEN="$(hf auth token 2>/dev/null | tr -d '[:space:]')" if [[ -z "${TOKEN}" ]]; then echo "ERROR: No HF token. Run: hf auth login" exit 1 fi CRED_FILE="${HOME}/.git-credentials" LINE="https://${USER}:${TOKEN}@huggingface.co" if [[ -f "${CRED_FILE}" ]] && grep -q "huggingface.co" "${CRED_FILE}" 2>/dev/null; then grep -v "huggingface.co" "${CRED_FILE}" > "${CRED_FILE}.tmp" || true mv "${CRED_FILE}.tmp" "${CRED_FILE}" fi echo "${LINE}" >> "${CRED_FILE}" chmod 600 "${CRED_FILE}" git branch -M main 2>/dev/null || true git remote set-url origin "${SPACE_REMOTE}" # Clean up a stuck rebase from a previous attempt if [[ -d .git/rebase-merge ]] || [[ -d .git/rebase-apply ]]; then echo "==> Aborting in-progress rebase..." git rebase --abort 2>/dev/null || true fi git add -A if ! git diff --cached --quiet 2>/dev/null; then git commit -m "RefDiffNet demo" || true fi if [[ "${FORCE}" == "1" ]]; then echo "==> Force pushing to ${SPACE_REMOTE}" git push -u origin main --force else echo "==> Pulling remote..." if git pull origin main --rebase --allow-unrelated-histories; then echo "==> Pushing to ${SPACE_REMOTE}" git push -u origin main else echo "" echo "Pull/rebase failed (conflicts?). Options:" echo " 1) Resolve conflicts, then: git rebase --continue && git push -u origin main" echo " 2) Overwrite remote Space: FORCE_PUSH=1 bash git_hf_sync.sh" exit 1 fi fi echo "==> Done: https://huggingface.co/spaces/${USER}/RefDiffNet"