Merge pull request 'fix: fix: disinto init does not push repo to local Forgejo — repo stays empty (#682)' (#696) from fix/issue-682 into main

This commit is contained in:
johba 2026-03-25 16:30:19 +01:00
commit ec658e3c52

View file

@ -654,19 +654,58 @@ 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:<token>@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}"
# Skip push if local repo has no commits (e.g. cloned from empty Forgejo repo)
if ! git -C "$repo_root" rev-parse HEAD >/dev/null 2>&1; then
echo "Push: skipped (local repo has no commits)"
return 0
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
# 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
# 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.