레포 타입을 mirror에서 bare로 변경. 기본 브렌치 Main 명시

This commit is contained in:
Lectom C Han
2025-12-16 09:04:13 +09:00
parent 762360dc45
commit 1af38d18e7

View File

@@ -39,6 +39,7 @@ jobs:
CENTER_ORG="center_dev" CENTER_ORG="center_dev"
AUTH_HEADER="Authorization: token ${BASE_GITEA_TOKEN}" AUTH_HEADER="Authorization: token ${BASE_GITEA_TOKEN}"
SOURCE_SSH_HOST="engdev@172.16.42.118" SOURCE_SSH_HOST="engdev@172.16.42.118"
ROOT_DIR="$(pwd)"
set_default_branch_main() { set_default_branch_main() {
local repo_name="$1" local repo_name="$1"
@@ -136,43 +137,44 @@ jobs:
echo "Working directory: ${CLONE_DIR}" echo "Working directory: ${CLONE_DIR}"
if ${repo_exists}; then if ${repo_exists}; then
echo "Cloning existing target repository for update..." echo "Cloning existing target repository for update (bare)..."
if ! git clone --mirror "${GITEA_REMOTE}" "${CLONE_DIR}"; then if ! git clone --bare "${GITEA_REMOTE}" "${CLONE_DIR}"; then
echo "::error::Failed to clone existing target repository ${GITEA_REMOTE}" echo "::error::Failed to clone existing target repository ${GITEA_REMOTE}"
rm -rf "${CLONE_DIR}" rm -rf "${CLONE_DIR}"
return return
fi fi
cd "${CLONE_DIR}" cd "${CLONE_DIR}"
git remote add source "${source_repo_url}" 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 else
echo "Cloning source repository for first-time push..." echo "Cloning source repository for first-time push (bare)..."
if ! git clone --mirror "${source_repo_url}" "${CLONE_DIR}"; then if ! git clone --bare "${source_repo_url}" "${CLONE_DIR}"; then
echo "::error::Failed to clone source repository ${source_repo_url}" echo "::error::Failed to clone source repository ${source_repo_url}"
rm -rf "${CLONE_DIR}" rm -rf "${CLONE_DIR}"
return return
fi fi
cd "${CLONE_DIR}" cd "${CLONE_DIR}"
git remote rename origin source
git remote add origin "${GITEA_REMOTE}"
fi 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}'..." echo "Pushing '${branch_name}' to Gitea repository '${repo_name}'..."
if ! git push --force origin "refs/heads/${branch_name}:refs/heads/main"; then if ! git push --force origin "refs/heads/${branch_name}:refs/heads/main"; then
echo "::error::Failed to push branch '${branch_name}' to target repository" echo "::error::Failed to push branch '${branch_name}' to target repository"
cd .. cd "${ROOT_DIR}"
rm -rf "${CLONE_DIR}" rm -rf "${CLONE_DIR}"
return return
fi fi
# Cleanup # Cleanup
cd .. cd "${ROOT_DIR}"
rm -rf "${CLONE_DIR}" rm -rf "${CLONE_DIR}"
echo "Successfully mirrored ${branch_name} to center_dev/${repo_name}" echo "Successfully mirrored ${branch_name} to center_dev/${repo_name}"