fix: fix: disinto init does not push repo to local Forgejo — repo stays empty (#682)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
28da1283e1
commit
f8c8769af3
1 changed files with 41 additions and 8 deletions
49
bin/disinto
49
bin/disinto
|
|
@ -654,19 +654,52 @@ setup_forge() {
|
||||||
# Push local clone to the Forgejo remote.
|
# Push local clone to the Forgejo remote.
|
||||||
push_to_forge() {
|
push_to_forge() {
|
||||||
local repo_root="$1" forge_url="$2" repo_slug="$3"
|
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
|
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
|
else
|
||||||
git -C "$repo_root" remote add forgejo "$remote_url" 2>/dev/null || \
|
git -C "$repo_root" remote add forgejo "$remote_url"
|
||||||
git -C "$repo_root" remote set-url forgejo "$remote_url"
|
fi
|
||||||
echo "Remote: forgejo -> ${remote_url}"
|
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
|
fi
|
||||||
|
|
||||||
# Push all branches
|
# Verify the repo is no longer empty
|
||||||
git -C "$repo_root" push forgejo --all 2>/dev/null || true
|
local repo_info
|
||||||
git -C "$repo_root" push forgejo --tags 2>/dev/null || true
|
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.
|
# Preflight check — verify all factory requirements before proceeding.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue