From 8b7bef097cc9409bd10706537153fe4a68a31cfc Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 12 May 2023 18:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=89=E5=8F=96=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/share.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/shell/share.sh b/shell/share.sh index 6583639f..c73275f1 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -322,11 +322,14 @@ git_pull_scripts() { echo -e "开始更新仓库:$dir_work" set_proxy "$proxy" + if [[ ! $branch ]]; then + branch=$(cd $dir_work && git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + fi + local pre_commit_id=$(git rev-parse --short HEAD) reset_branch "$branch" "$dir_work" - git fetch --depth=1 --all - git pull --depth=1 --allow-unrelated-histories &>/dev/null + git fetch --depth 1 origin $branch exit_status=$? reset_branch "$branch" "$dir_work" @@ -359,14 +362,10 @@ reset_romote_url() { reset_branch() { local branch="$1" - local dir="$2" - if [[ ! $branch ]]; then - branch=$(cd $dir && git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) - fi local part_cmd="origin/${branch}" - git remote set-branches --add origin $branch &>/dev/null + git remote set-branches origin $branch git reset --hard $part_cmd &>/dev/null - git checkout --track $part_cmd &>/dev/null + git checkout -b $branch $part_cmd &>/dev/null } random_range() {