整理
This commit is contained in:
Vendored
+35
-9
@@ -5,23 +5,49 @@ cd "$root"
|
||||
origin="$(git remote get-url origin)"
|
||||
origin="${origin%/}"
|
||||
remote_root="$(printf '%s\n' "$origin" | sed -E 's#/[^/]+(\.git)?$##')"
|
||||
remote_root="${remote_root%/*}"
|
||||
echo "remote_root: $remote_root"
|
||||
get_default_branch() {
|
||||
local repo="$1"
|
||||
local branch
|
||||
branch="$(git ls-remote --symref "$repo" HEAD | awk '$1 == "ref:" {
|
||||
sub("^refs/heads/", "", $2)
|
||||
print $2
|
||||
exit
|
||||
}')"
|
||||
if [ -z "$branch" ]; then
|
||||
printf '无法获取远程仓库默认分支: %s\n' "$repo" >&2
|
||||
return 1
|
||||
fi
|
||||
printf '%s\n' "$branch"
|
||||
}
|
||||
fetch_repo() {
|
||||
local repo="$1"
|
||||
local branch="$2"
|
||||
local dir="$3"
|
||||
local dir="$2"
|
||||
local branch="${3-}"
|
||||
if [ -z "$branch" ]; then
|
||||
branch="$(get_default_branch "$repo")"
|
||||
fi
|
||||
if [ -d "$dir" ]; then
|
||||
echo "文件夹【$dir】已存在 跳过初始化 "
|
||||
git -C "$dir" rev-parse --is-inside-work-tree >/dev/null
|
||||
git -C "$dir" remote set-url origin "$repo"
|
||||
git -C "$dir" fetch origin "$branch"
|
||||
git -C "$dir" checkout "$branch"
|
||||
git -C "$dir" pull --ff-only origin "$branch"
|
||||
else
|
||||
git clone --branch "$branch" --single-branch "$repo" "$dir"
|
||||
fi
|
||||
}
|
||||
fetch_repo_ex() {
|
||||
local name="$1"
|
||||
local branch="${2-}"
|
||||
local repo="${remote_root}/${name}"
|
||||
local branch="master"
|
||||
fetch_repo "$repo" "$branch" "third_party/${name}"
|
||||
local dir="${name##*/}"
|
||||
fetch_repo "$repo" "third_party/${dir}" "$branch"
|
||||
}
|
||||
fetch_repo_ex "build_infra"
|
||||
fetch_repo_ex "CPP_Core"
|
||||
fetch_repo_ex "SSR"
|
||||
fetch_repo_ex "eacp_webapp"
|
||||
fetch_repo_ex "ae/build_infra"
|
||||
fetch_repo_ex "ae/CPP_Core"
|
||||
fetch_repo_ex "ae/SSR"
|
||||
fetch_repo_ex "ae/eacp_webapp"
|
||||
fetch_repo_ex "psc/Structive"
|
||||
fetch_repo_ex "psc/Adminive"
|
||||
|
||||
Reference in New Issue
Block a user