diff --git a/config/config.sh b/config/config.sh index 0b5058a..c814291 100644 --- a/config/config.sh +++ b/config/config.sh @@ -1,4 +1,13 @@ #!/bin/sh +# the language of your project lang="go" + +# the token of DINGDING dingToken="example" + +# the loading speed of commit, push, etc. +loadingSpeed=4 + +# the protect rules +protectMainSwitch="on" diff --git a/hooks/commit-msg b/hooks/commit-msg index 32b7e2e..86d30ea 100755 --- a/hooks/commit-msg +++ b/hooks/commit-msg @@ -8,10 +8,12 @@ fi printLogo echo "温馨提示: 请务必在提交代码前确认分支是否正确 (Warm tips: please make sure the branch is correct before committing)" -BRANCH_NAME=$(git symbolic-ref --short -q HEAD) -if [ "${BRANCH_NAME}" == "main" ] || [ "${BRANCH_NAME}" == "master" ]; then - echo "禁止直接再主分支提交代码, 已中断! (You are not allowed to commit at main branch, has been stopped !)" - exit 1 +if [ "${protectMainSwitch}" == "on" ] ; then + BRANCH_NAME=$(git symbolic-ref --short -q HEAD) + if [ "${BRANCH_NAME}" == "main" ] || [ "${BRANCH_NAME}" == "master" ]; then + echo "禁止直接再主分支提交代码, 已中断! (You are not allowed to commit at main branch, has been stopped !)" + exit 1 + fi fi echo "> 提交本地 (your commit branch): \033[33m${BRANCH_NAME}\033[0m" diff --git a/hooks/post-checkout b/hooks/post-checkout index fb10452..d5885bf 100755 --- a/hooks/post-checkout +++ b/hooks/post-checkout @@ -5,11 +5,15 @@ if [ "${POSTUREPATH}" == "" ]; then fi . $POSTUREPATH/include/function.sh +newBranch=$(git reflog | awk 'NR==1{ print $8; }') +changeDirection=$(git reflog | awk 'NR==1{ print $6 " -> " $8; exit }') + +if [ "${newBranch}" == "" ] || [ "${changeDirection}" == "" ] ; then + exit 0 +fi + printLogo echo "温馨提示: 请及时拉取分支的最新代码 (Warm tips: Please pull the latest code in time)" -newBranch=$(git reflog | awk 'NR==1{ print $8; }') echo "> 当前分支: \033[33m${newBranch}\033[0m" - -changeDirection=$(git reflog | awk 'NR==1{ print $6 " -> " $8; exit }') echo "> 分支切换顺序 (the direction of branch switch): \033[33m${changeDirection}\033[0m" diff --git a/include/function.sh b/include/function.sh index e06dff4..9562723 100644 --- a/include/function.sh +++ b/include/function.sh @@ -115,12 +115,25 @@ writeCommitLog(){ # 加载中 loading(){ + sleepSeconds=0.2 + if [ "${loadingSpeed}" == 1 ]; then + sleepSeconds=0.2 + elif [ "${loadingSpeed}" == 2 ]; then + sleepSeconds=0.1 + elif [ "${loadingSpeed}" == 3 ]; then + sleepSeconds=0.05 + elif [ "${loadingSpeed}" == 4 ]; then + sleepSeconds=0.025 + elif [ "${loadingSpeed}" == 5 ]; then + sleepSeconds=0.01 + fi + b='' i=0 while [ $i -le 100 ] do printf "\033[32m""[%-50s] %d%%""\033[0m""\r" "$b" "$i"; - sleep 0.2 + sleep $sleepSeconds ((i=i+2)) b+='#' done