diff --git a/bin/disinto b/bin/disinto index 83454c2..0769d75 100755 --- a/bin/disinto +++ b/bin/disinto @@ -654,19 +654,52 @@ setup_forge() { # Push local clone to the Forgejo remote. push_to_forge() { local repo_root="$1" forge_url="$2" repo_slug="$3" - local remote_url="${forge_url}/${repo_slug}.git" + # Build authenticated remote URL: http://dev-bot:@host:port/org/repo.git + if [ -z "${FORGE_TOKEN:-}" ]; then + echo "Error: FORGE_TOKEN not set — cannot push to Forgejo" >&2 + return 1 + fi + local auth_url + auth_url=$(printf '%s' "$forge_url" | sed "s|://|://dev-bot:${FORGE_TOKEN}@|") + local remote_url="${auth_url}/${repo_slug}.git" + # Display URL without token + local display_url="${forge_url}/${repo_slug}.git" + + # Always set the remote URL to ensure credentials are current if git -C "$repo_root" remote get-url forgejo >/dev/null 2>&1; then - echo "Remote: forgejo (already configured)" + git -C "$repo_root" remote set-url forgejo "$remote_url" else - git -C "$repo_root" remote add forgejo "$remote_url" 2>/dev/null || \ - git -C "$repo_root" remote set-url forgejo "$remote_url" - echo "Remote: forgejo -> ${remote_url}" + git -C "$repo_root" remote add forgejo "$remote_url" + fi + echo "Remote: forgejo -> ${display_url}" + + # Push all branches and tags + echo "Pushing: branches to forgejo" + if ! git -C "$repo_root" push forgejo --all 2>&1; then + echo "Error: failed to push branches to Forgejo" >&2 + return 1 + fi + echo "Pushing: tags to forgejo" + if ! git -C "$repo_root" push forgejo --tags 2>&1; then + echo "Error: failed to push tags to Forgejo" >&2 + return 1 fi - # Push all branches - git -C "$repo_root" push forgejo --all 2>/dev/null || true - git -C "$repo_root" push forgejo --tags 2>/dev/null || true + # Verify the repo is no longer empty + local repo_info + repo_info=$(curl -sf --max-time 10 \ + -H "Authorization: token ${FORGE_TOKEN}" \ + "${forge_url}/api/v1/repos/${repo_slug}" 2>/dev/null) || repo_info="" + if [ -n "$repo_info" ]; then + local is_empty + is_empty=$(printf '%s' "$repo_info" | jq -r '.empty // "unknown"') + if [ "$is_empty" = "true" ]; then + echo "Warning: Forgejo repo still reports empty after push" >&2 + return 1 + fi + echo "Verify: repo is not empty (push confirmed)" + fi } # Preflight check — verify all factory requirements before proceeding.