diff --git a/lib/onboard.sh b/lib/onboard.sh index 01a229a..69f8734 100644 --- a/lib/onboard.sh +++ b/lib/onboard.sh @@ -169,6 +169,17 @@ onboard_flow() { local import_prs import_prs=$(echo "$onboard_state" | jq -r '.import_prs // {}') + # Build the archived repo clone URL for initial_import(). + # The content lives in the archived repo — the new repo at SUBREPO_URL is empty. + local archived_url archived_clone_url + archived_url=$(echo "$onboard_state" | jq -r '.archived_url') + if [ "${SUBREPO_AUTH:-https}" = "ssh" ]; then + archived_clone_url="$archived_url" + else + # shellcheck disable=SC2001 + archived_clone_url=$(echo "$archived_url" | sed "s|https://|https://${BOT_USER}:${SUBREPO_TOKEN}@|") + fi + for branch in $branches; do local mapped mapped=$(echo "$target_json" | jq -r --arg b "$branch" '.branches[$b] // empty') @@ -185,7 +196,7 @@ onboard_flow() { log "INFO" "Importing branch: ${branch} (subrepo: ${mapped})" local result - result=$(initial_import) + result=$(initial_import "$archived_clone_url") log "INFO" "Import result for ${branch}: ${result}" if [ "$result" = "pr-created" ]; then diff --git a/lib/sync.sh b/lib/sync.sh index 91d2903..ab1b7e8 100644 --- a/lib/sync.sh +++ b/lib/sync.sh @@ -200,9 +200,13 @@ reverse_sync() { # # Used when a subrepo already has content and you're adding it to the # monorepo for the first time. Creates a PR. +# Usage: initial_import [clone_url_override] +# clone_url_override — if set, clone from this URL instead of subrepo_auth_url() +# (used by onboard to clone from the archived repo) # Returns: skip | pr-created initial_import() { + local clone_url="${1:-$(subrepo_auth_url)}" local mono_branch="$SYNC_BRANCH_MONO" local subrepo_branch="$SYNC_BRANCH_SUBREPO" local subfolder @@ -225,8 +229,8 @@ initial_import() { --branch "$mono_branch" --single-branch \ "${work_dir}/monorepo" || die "Failed to clone monorepo" - # 2. Clone subrepo - git clone "$(subrepo_auth_url)" \ + # 2. Clone subrepo (or archived repo when clone_url is overridden) + git clone "$clone_url" \ --branch "$subrepo_branch" --single-branch \ "${work_dir}/subrepo" || die "Failed to clone subrepo"