diff --git a/.gitea/workflows/mirror.yml b/.gitea/workflows/mirror.yml index f383d30..c190bfe 100644 --- a/.gitea/workflows/mirror.yml +++ b/.gitea/workflows/mirror.yml @@ -39,6 +39,7 @@ jobs: CENTER_ORG="center_dev" AUTH_HEADER="Authorization: token ${BASE_GITEA_TOKEN}" SOURCE_SSH_HOST="engdev@172.16.42.118" + ROOT_DIR="$(pwd)" set_default_branch_main() { local repo_name="$1" @@ -136,43 +137,44 @@ jobs: echo "Working directory: ${CLONE_DIR}" if ${repo_exists}; then - echo "Cloning existing target repository for update..." - if ! git clone --mirror "${GITEA_REMOTE}" "${CLONE_DIR}"; then + echo "Cloning existing target repository for update (bare)..." + if ! git clone --bare "${GITEA_REMOTE}" "${CLONE_DIR}"; then echo "::error::Failed to clone existing target repository ${GITEA_REMOTE}" rm -rf "${CLONE_DIR}" return fi cd "${CLONE_DIR}" git remote add source "${source_repo_url}" - echo "Fetching latest branch '${branch_name}' from source..." - if ! git fetch source "+refs/heads/${branch_name}:refs/heads/${branch_name}"; then - echo "::error::Failed to fetch branch '${branch_name}' from source repo" - cd .. - rm -rf "${CLONE_DIR}" - return - fi else - echo "Cloning source repository for first-time push..." - if ! git clone --mirror "${source_repo_url}" "${CLONE_DIR}"; then + echo "Cloning source repository for first-time push (bare)..." + if ! git clone --bare "${source_repo_url}" "${CLONE_DIR}"; then echo "::error::Failed to clone source repository ${source_repo_url}" rm -rf "${CLONE_DIR}" return fi cd "${CLONE_DIR}" + git remote rename origin source + git remote add origin "${GITEA_REMOTE}" fi - git remote set-url origin "${GITEA_REMOTE}" + echo "Fetching latest branch '${branch_name}' from source..." + if ! git fetch source "+refs/heads/${branch_name}:refs/heads/${branch_name}"; then + echo "::error::Failed to fetch branch '${branch_name}' from source repo" + cd "${ROOT_DIR}" + rm -rf "${CLONE_DIR}" + return + fi echo "Pushing '${branch_name}' to Gitea repository '${repo_name}'..." if ! git push --force origin "refs/heads/${branch_name}:refs/heads/main"; then echo "::error::Failed to push branch '${branch_name}' to target repository" - cd .. + cd "${ROOT_DIR}" rm -rf "${CLONE_DIR}" return fi # Cleanup - cd .. + cd "${ROOT_DIR}" rm -rf "${CLONE_DIR}" echo "Successfully mirrored ${branch_name} to center_dev/${repo_name}"