From 481646501c237acafaf15eadaedfe7da66467ae1 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 6 May 2023 22:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BB=93=E5=BA=93=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/Dockerfile | 1 + shell/check.sh | 2 +- shell/share.sh | 26 +++++++++++++++----------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 4f743b98..b160d95b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -41,6 +41,7 @@ RUN set -x \ jq \ openssh \ procps \ + netcat-openbsd \ npm \ && rm -rf /var/cache/apk/* \ && apk update \ diff --git a/shell/check.sh b/shell/check.sh index 7d26c8c0..33c7db8b 100755 --- a/shell/check.sh +++ b/shell/check.sh @@ -79,7 +79,7 @@ main() { npm i -g pnpm@8.3.1 patch_version - apk add procps + apk add procps netcat-openbsd if [[ $PipMirror ]]; then pip3 config set global.index-url $PipMirror diff --git a/shell/share.sh b/shell/share.sh index 29e3f84a..52419ac6 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -301,11 +301,13 @@ git_clone_scripts() { echo -e "开始克隆仓库 $url 到 $dir\n" set_proxy "$proxy" + git clone --depth=1 $part_cmd $url $dir exit_status=$? - unset_proxy - reset_branch "$branch" + reset_branch "$branch" "$dir" + + unset_proxy } git_pull_scripts() { @@ -315,21 +317,22 @@ git_pull_scripts() { local proxy="$3" cd $dir_work echo -e "开始更新仓库:$dir_work" + set_proxy "$proxy" local pre_commit_id=$(git rev-parse --short HEAD) - reset_branch "$branch" + reset_branch "$branch" "$dir_work" - set_proxy "$proxy" git fetch --depth=1 --all - git pull --depth=1 &>/dev/null + git pull --depth=1 --allow-unrelated-histories &>/dev/null exit_status=$? - unset_proxy - reset_branch "$branch" + reset_branch "$branch" "$dir_work" local cur_commit_id=$(git rev-parse --short HEAD) if [[ $cur_commit_id != $pre_commit_id ]]; then exit_status=0 fi + + unset_proxy cd $dir_current } @@ -353,11 +356,12 @@ reset_romote_url() { reset_branch() { local branch="$1" - local part_cmd="HEAD" - if [[ $branch ]]; then - part_cmd="origin/${branch}" - git remote set-branches --add origin $branch &>/dev/null + 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 reset --hard $part_cmd &>/dev/null git checkout --track $part_cmd &>/dev/null }