-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithook
executable file
·85 lines (62 loc) · 1.23 KB
/
githook
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
#!/bin/bash
# 1、介绍git hooks
# 2、选择对应的操作
# 3、输入项目路径
# 4、cp对应文件
# 概述
summary(){
echo "
+------------------+
| GitHooks |
+------------------+
"
# echo "使用方法:
# deploy [options] [arguments]
# Options:
# -p,需要接入git hooks的项目路径
# "
}
# 检查git文件夹是否存在
choose_git_path(){
read -p "请输入项目地址:" -e path
if [[ ! -d ${path} ]]; then
echo "没有发现项目路径"
exit 1
fi
project_git_path=${path}'/.git/hooks'
if [[ ! -d ${project_git_path} ]]; then
echo "项目中没有发现git仓库"
exit 2
fi
}
# 选择需要进行的git操作
choose_git_option(){
echo '----需要进行检查的操作----'
echo '1)git commit时检查'
read -p '请选择需要的操作:' -n 1 -e choose
case ${choose} in
1 )
cp -r ${bash_path}'/php-hooks/pre-commit.sample' ${project_git_path}'/pre-commit'
;;
* )
echo '输入有误!'
esac
}
# 当前项目的基本路径
bash_path=$(cd `dirname $0`; pwd)
# 操作类型
# Option=${1}
# case "${Option}" in
# -p )
# Path=${2}
# ;;
# * )
# summary
# exit 3
# ;;
# esac
# has_git_path ${Path}
summary
choose_git_path
choose_git_option
echo '添加完成!'