Skip to content

Commit

Permalink
feat: 新增loadingSpeed和protectMainSwitch等配置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Oct 15, 2022
1 parent c5ce0b6 commit b71a9c1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
9 changes: 9 additions & 0 deletions config/config.sh
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 6 additions & 4 deletions hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 7 additions & 3 deletions hooks/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 14 additions & 1 deletion include/function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b71a9c1

Please sign in to comment.