-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommit-push.sh
executable file
·114 lines (73 loc) · 2.57 KB
/
commit-push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
###
# @Author: Rainy
# @Date: 2020-04-09 19:35:20
# @LastEditors: Rainy
# @LastEditTime: 2020-04-09 19:38:19
###
#!/usr/bin/env bash
echo "Deploy to gh-pages"
npm run deploy || exit 1
echo "Deploy to gh-pages"
npm run changelog
echo "Testing for codes"
npm run testing || exit 1
echo "------------ commit push shell run ------------"
read -p "Input your commit msg (*): " msg
read -p "Amend commit(Y, y, default: N): " amend
read -p "Need pull current branch(Y, y, default: N): " pull
len=72
curBranch=$(git branch | awk '/\*/ { print $2; }')
# start reg
msgRegLower='^\s*(feat|fix|docs|style|chore|build|ci|perf|refactor|revert|test|temp|update)\s*\:*\s*'
msgRegUpper='^\s*(Feat|Fix|Docs|Style|Chore|Build|Ci|Perf|Refactor|Revert|Test|Temp|Update)\s*\:*\s*'
# 另一种获取当前 branch_name 的方法
# git symbolic-ref --short HEAD
echo "Log: Cureren branch is ${curBranch}"
if [[ $pull = "Y" || $pull = "y" ]];then
read -p "Need pull branch(default: current branch, eg: it4/mobile): " branch
fi
if [ -n "$msg" ];then
echo "Log: Commit msg: $msg"
if [ ${#msg} -gt $len ];then
echo "Error: msg length must less than $len"
exit 1
fi
if [[ "$msg" =~ $msgRegLower || "$msg" =~ $msgRegUpper ]];then
git add .
lint-staged
if [[ $amend = "Y" || $amend = "y" ]];then
echo "Log: Amending message commit"
git commit --amend -m "$msg" || exit 1
else
echo "Log: Commiting"
git commit -m "$msg" || exit 1
fi
if [[ $pull = "Y" || $pull = "y" ]];then
if [ -n "$branch" ];then
echo "Log: Pulling branch is $branch"
fi
branch=curBranch
echo "Log: Pulling ${branch} from remote"
git pull origin ${branch} || exit 1
else
branch=${curBranch}
echo "Log: Current branch is $branch"
echo "Log: Jump pull branch"
fi
read -p "Auto Push(Y, y, default: Y): " push
if [ -z "${push}" ];then
push='Y'
fi
if [[ $push = "Y" || $push = "y" ]];then
echo "Log: Pushing"
git push origin ${branch} || exit 1
fi
echo "------------ commit push shell end ------------"
else
echo "Error: Commit message start type must be one of [feat, fix, docs, style, chore, build, ci, perf, refactor, revert, test, temp, Feat, Fix, Docs, Style, Chore, Build, Ci, Perf, Refactor, Revert, Test, Temp]"
exit 1
fi
else
echo "Please input commit msg"
exit 1
fi