#!/bin/bash

# 定义仓库和对应的分支映射
declare -A repo_branches=(
    ["cloud_mqtt"]="master"
    ["data_reporter"]="master"
    ["ems_ctrl"]="release-2023-07-17"
    ["energy_assign"]="release-2023-07-17"
    ["ems_template"]="master"
    ["factorytools"]="factory"
    ["package_repos"]="dev north-branch pure_libs"
    ["proto_forward"]="master_weiwang_merge master"
    ["rathole"]="master"
    ["ubuslog"]="master"
    ["youcan"]="master"
)

# 遍历每个仓库
for repo in "${!repo_branches[@]}"; do
    echo "Processing repository: $repo"
    # 获取该仓库的所有分支
    branches=(${repo_branches[$repo]})

    # 遍历每个分支
    for branch in "${branches[@]}"; do
        cd "./$repo" || exit
        echo "Processing branch: $branch"

        # 拉取 origin 的分支
        git checkout "$branch"
        git pull origin "$branch"

        # 推送到 origins 的分支
        git push origins "$branch"
        cd ..
    done
done

echo "All repositories have been synchronized."

