From b8c13601751b6bba84aa11d4c284ebb527bddc96 Mon Sep 17 00:00:00 2001 From: wyc <1104749580@qq.com> Date: Mon, 3 Aug 2026 08:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/init.bash | 28 ++++++++++++++++++++++------ third_party/init.ps1 | 35 +++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/third_party/init.bash b/third_party/init.bash index b08f8b5..0b218d8 100644 --- a/third_party/init.bash +++ b/third_party/init.bash @@ -5,10 +5,27 @@ cd "$root" origin="$(git remote get-url origin)" origin="${origin%/}" 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() { 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 git -C "$dir" rev-parse --is-inside-work-tree >/dev/null git -C "$dir" remote set-url origin "$repo" @@ -21,11 +38,10 @@ fetch_repo() { } fetch_repo_ex() { local name="$1" + local branch="${2-}" local repo="${remote_root}/${name}" - local branch="master" - fetch_repo "$repo" "$branch" "third_party/${name}" + fetch_repo "$repo" "third_party/${name}" "$branch" } - fetch_repo_ex "build_infra" fetch_repo_ex "CPP_Core" -fetch_repo_ex "Renderive" +fetch_repo_ex "Renderive" "restart" diff --git a/third_party/init.ps1 b/third_party/init.ps1 index 170a7b4..e4ffb3b 100644 --- a/third_party/init.ps1 +++ b/third_party/init.ps1 @@ -13,33 +13,48 @@ function Fetch-Repo { param( [string]$Repo, - [string]$Branch, - [string]$Dir + [string]$Dir, + [string]$Branch ) if (Test-Path -LiteralPath $Dir -PathType Container) { git -C $Dir rev-parse --is-inside-work-tree *> $null git -C $Dir remote set-url origin $Repo - git -C $Dir fetch origin $Branch + 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 checkout $Branch git -C $Dir pull --ff-only origin $Branch } else { - git clone --branch $Branch --single-branch $Repo $Dir + if ( [string]::IsNullOrWhiteSpace($Branch)) + { + git clone --single-branch $Repo $Dir + } + else + { + git clone --branch $Branch --single-branch $Repo $Dir + } } } function Fetch-RepoEx { param( - [string]$Name + [string]$Name, + [string]$Branch ) $repo = "$remoteRoot/$Name" - $branch = "master" - Fetch-Repo -Repo $repo -Branch $branch -Dir "third_party/$Name" + Fetch-Repo -Repo $repo -Dir "third_party/$Name" -Branch $Branch } - - Fetch-RepoEx "build_infra" Fetch-RepoEx "CPP_Core" -Fetch-RepoEx "Renderive" \ No newline at end of file +Fetch-RepoEx "Renderive" "restart" \ No newline at end of file