From 049a87780ee2010254d52c74552bbb0f55c989d6 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Wed, 9 Jun 2021 22:31:13 +0800 Subject: [PATCH] =?UTF-8?q?ql=20repo=E5=91=BD=E4=BB=A4=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E6=94=AF=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/share.sh | 6 ++++-- shell/update.sh | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/shell/share.sh b/shell/share.sh index 4f3f7621..248d70c2 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -275,12 +275,14 @@ git_clone_scripts() { ## 更新脚本,$1:仓库保存路径 git_pull_scripts() { local dir_current=$(pwd) - local dir_work=$1 + local dir_work="$1" + local branch="$2" + [[ $branch ]] && local cmd="origin/${branch}" cd $dir_work echo -e "开始更新仓库:$dir_work\n" git fetch --all exit_status=$? - git reset --hard + git reset --hard $cmd git pull cd $dir_current } diff --git a/shell/update.sh b/shell/update.sh index ac938540..244745df 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -14,11 +14,14 @@ reset_romote_url() { local dir_current=$(pwd) local dir_work=$1 local url=$2 + local branch="$3" + + [[ $branch ]] && local cmd="origin/${branch}" if [ -d "$dir_work/.git" ]; then cd $dir_work git remote set-url origin $url >/dev/null - git reset --hard >/dev/null + git reset --hard $cmd >/dev/null cd $dir_current fi } @@ -156,6 +159,7 @@ update_repo() { local path="$2" local blackword="$3" local dependence="$4" + local branch="$5" local urlTmp="${url%*/}" local repoTmp="${urlTmp##*/}" local repo="${repoTmp%.*}" @@ -165,11 +169,13 @@ update_repo() { local author="${authorTmp2##*.}" local repo_path="${dir_repo}/${author}_${repo}" + [[ $branch ]] && repo_path="${repo_path}_${branch}" + if [ -d ${repo_path}/.git ]; then - reset_romote_url ${repo_path} "${github_proxy_url}${url/https:\/\/ghproxy.com\//}" - git_pull_scripts ${repo_path} + reset_romote_url ${repo_path} "${github_proxy_url}${url/https:\/\/ghproxy.com\//}" "${branch}" + git_pull_scripts ${repo_path} "${branch}" else - git_clone_scripts ${url} ${repo_path} + git_clone_scripts ${url} ${repo_path} "${branch}" fi if [[ $exit_status -eq 0 ]]; then echo -e "\n更新${repo_path}成功...\n" @@ -380,6 +386,7 @@ main() { local p3=$3 local p4=$4 local p5=$5 + local p6=$6 log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_path="$dir_log/update/${log_time}_$p1.log" case $p1 in @@ -394,7 +401,7 @@ main() { local name=$(echo "${p2##*/}" | awk -F "." '{print $1}') log_path="$dir_log/update/${log_time}_$name.log" if [[ -n $p2 ]]; then - update_repo "$p2" "$p3" "$p4" "$p5" | tee $log_path + update_repo "$p2" "$p3" "$p4" "$p5" "$p6" | tee $log_path else echo -e "命令输入错误...\n" usage