@@ -343,9 +343,7 @@ jobs:
343343 if [[ "${project_created}" == "true" ]]; then
344344 project_empty=true
345345 else
346- project_empty="$(
347- jq -r '(.empty_repo == true) or (.default_branch == null)' "${response_file}"
348- )"
346+ project_empty="$(jq -r '.empty_repo == true' "${response_file}")"
349347 fi
350348
351349 # Make a private source private before changing metadata or pushing any Git data.
@@ -489,30 +487,43 @@ jobs:
489487 fi
490488 fi
491489
492- if [[ "${gitlab_incremental_seed}" == "true" ]]; then
493- mapfile -t seed_refs < <(
494- git -C "${mirror_dir}" for-each-ref --format='%(refname)' refs/heads/ refs/tags/
495- )
496- echo "Seeding ${#seed_refs[@]} branches and tags in separate pushes..."
497- for seed_ref in "${seed_refs[@]}"; do
498- echo "Seeding ${seed_ref}..."
499- if ! git \
500- -C "${mirror_dir}" \
501- -c core.sshCommand="${gitlab_ssh_command}" \
502- push --progress "${target_clone_url}" "+${seed_ref}:${seed_ref}"; then
503- echo "::error title=Mirror failed: ${source_name}::Unable to seed ${seed_ref} on GitLab."
504- exit 1
505- fi
506- done
507- fi
490+ mapfile -t mirror_refs < <(
491+ git -C "${mirror_dir}" for-each-ref --format='%(refname)'
492+ )
493+ if ((${#mirror_refs[@]} == 0)); then
494+ echo "The GitHub repository has no refs to mirror."
495+ if [[ "${project_empty}" != "true" ]]; then
496+ echo "::error title=Mirror failed: ${source_name}::The GitHub repository is empty, but" \
497+ "the GitLab repository is not. Refusing to leave stale GitLab refs."
498+ exit 1
499+ fi
500+ echo "The GitLab repository is also empty; no Git push is required."
501+ else
502+ if [[ "${gitlab_incremental_seed}" == "true" ]]; then
503+ mapfile -t seed_refs < <(
504+ git -C "${mirror_dir}" for-each-ref --format='%(refname)' refs/heads/ refs/tags/
505+ )
506+ echo "Seeding ${#seed_refs[@]} branches and tags in separate pushes..."
507+ for seed_ref in "${seed_refs[@]}"; do
508+ echo "Seeding ${seed_ref}..."
509+ if ! git \
510+ -C "${mirror_dir}" \
511+ -c core.sshCommand="${gitlab_ssh_command}" \
512+ push --progress "${target_clone_url}" "+${seed_ref}:${seed_ref}"; then
513+ echo "::error title=Mirror failed: ${source_name}::Unable to seed ${seed_ref} on GitLab."
514+ exit 1
515+ fi
516+ done
517+ fi
508518
509- echo "Pushing the mirror to ${target_clone_url}..."
510- if ! git \
511- -C "${mirror_dir}" \
512- -c core.sshCommand="${gitlab_ssh_command}" \
513- push --mirror --progress "${target_clone_url}"; then
514- echo "::error title=Mirror failed: ${source_name}::Unable to push the GitLab mirror."
515- exit 1
519+ echo "Pushing the mirror to ${target_clone_url}..."
520+ if ! git \
521+ -C "${mirror_dir}" \
522+ -c core.sshCommand="${gitlab_ssh_command}" \
523+ push --mirror --progress "${target_clone_url}"; then
524+ echo "::error title=Mirror failed: ${source_name}::Unable to push the GitLab mirror."
525+ exit 1
526+ fi
516527 fi
517528 rm -rf "${mirror_dir}"
518529 echo "Completed mirror for ${source_name}."
0 commit comments