更新安装脚本

This commit is contained in:
2026-08-03 08:35:15 +08:00
parent b0fba42e8f
commit b8c1360175
2 changed files with 47 additions and 16 deletions
+22 -6
View File
@@ -5,10 +5,27 @@ cd "$root"
origin="$(git remote get-url origin)" origin="$(git remote get-url origin)"
origin="${origin%/}" origin="${origin%/}"
remote_root="$(printf '%s\n' "$origin" | sed -E 's#/[^/]+(\.git)?$##')" remote_root="$(printf '%s\n' "$origin" | sed -E 's#/[^/]+(\.git)?$##')"
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() { fetch_repo() {
local repo="$1" local repo="$1"
local branch="$2" local dir="$2"
local dir="$3" local branch="${3-}"
if [ -z "$branch" ]; then
branch="$(get_default_branch "$repo")"
fi
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
git -C "$dir" rev-parse --is-inside-work-tree >/dev/null git -C "$dir" rev-parse --is-inside-work-tree >/dev/null
git -C "$dir" remote set-url origin "$repo" git -C "$dir" remote set-url origin "$repo"
@@ -21,11 +38,10 @@ fetch_repo() {
} }
fetch_repo_ex() { fetch_repo_ex() {
local name="$1" local name="$1"
local branch="${2-}"
local repo="${remote_root}/${name}" local repo="${remote_root}/${name}"
local branch="master" fetch_repo "$repo" "third_party/${name}" "$branch"
fetch_repo "$repo" "$branch" "third_party/${name}"
} }
fetch_repo_ex "build_infra" fetch_repo_ex "build_infra"
fetch_repo_ex "CPP_Core" fetch_repo_ex "CPP_Core"
fetch_repo_ex "Renderive" fetch_repo_ex "Renderive" "restart"
+23 -8
View File
@@ -13,33 +13,48 @@ function Fetch-Repo
{ {
param( param(
[string]$Repo, [string]$Repo,
[string]$Branch, [string]$Dir,
[string]$Dir [string]$Branch
) )
if (Test-Path -LiteralPath $Dir -PathType Container) if (Test-Path -LiteralPath $Dir -PathType Container)
{ {
git -C $Dir rev-parse --is-inside-work-tree *> $null git -C $Dir rev-parse --is-inside-work-tree *> $null
git -C $Dir remote set-url origin $Repo git -C $Dir remote set-url origin $Repo
if ( [string]::IsNullOrWhiteSpace($Branch))
{
git -C $Dir fetch origin
git -C $Dir remote set-head origin --auto
$remoteHead = git -C $Dir symbolic-ref --short refs/remotes/origin/HEAD
$Branch = $remoteHead -replace "^origin/", ""
}
else
{
git -C $Dir fetch origin $Branch git -C $Dir fetch origin $Branch
}
git -C $Dir checkout $Branch git -C $Dir checkout $Branch
git -C $Dir pull --ff-only origin $Branch git -C $Dir pull --ff-only origin $Branch
} }
else else
{
if ( [string]::IsNullOrWhiteSpace($Branch))
{
git clone --single-branch $Repo $Dir
}
else
{ {
git clone --branch $Branch --single-branch $Repo $Dir git clone --branch $Branch --single-branch $Repo $Dir
} }
}
} }
function Fetch-RepoEx function Fetch-RepoEx
{ {
param( param(
[string]$Name [string]$Name,
[string]$Branch
) )
$repo = "$remoteRoot/$Name" $repo = "$remoteRoot/$Name"
$branch = "master" Fetch-Repo -Repo $repo -Dir "third_party/$Name" -Branch $Branch
Fetch-Repo -Repo $repo -Branch $branch -Dir "third_party/$Name"
} }
Fetch-RepoEx "build_infra" Fetch-RepoEx "build_infra"
Fetch-RepoEx "CPP_Core" Fetch-RepoEx "CPP_Core"
Fetch-RepoEx "Renderive" Fetch-RepoEx "Renderive" "restart"