@@ -7,48 +7,115 @@ This project contains a Maven project with tests. Git-Hooks are configured and b
7
7
8
8
### Version controlled git-hooks:
9
9
* ProjectDirectory/.githooks
10
- * pre-commit
10
+ * < b > pre-commit</ b >
11
11
``` sh
12
- CWD=` pwd`
13
- # Move to the project directory which you want to build
14
- # cd glide-template
15
- # Build the maven project
16
- mvn clean verify -Dmaven.test.skip=true
17
- if [ $? -ne 0 ]; then
18
- cd $CWD
19
- exit 1
12
+ # ------------------- Check for white-space error -------------------- #
13
+ # Check if this is the initial commit
14
+ if git rev-parse --verify HEAD > /dev/null 2>&1
15
+ then
16
+ echo " pre-commit: About to create a new commit..."
17
+ against=HEAD
18
+ else
19
+ echo " pre-commit: About to create the first commit..."
20
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
21
+ fi
22
+
23
+ # Use git diff-index to check for whitespace errors
24
+ echo " pre-commit: Testing for whitespace errors..."
25
+ if ! git diff-index --check --cached $against
26
+ then
27
+ echo " pre-commit: Aborting commit due to whitespace errors"
28
+ exit 1
29
+ else
30
+ echo " pre-commit: No whitespace errors :)"
31
+ exit 0
20
32
fi
21
- cd $CWD
22
33
```
23
- * prepare-commit-msg
34
+ * < b > prepare-commit-msg< /b >
24
35
` ` ` sh
25
- # Prepends commit message with STRY, DEF, BAK tickets or MAINT
36
+ # Append commit message with STRY, DEF, BAK tickets or MAINT
26
37
27
38
COMMIT_MSG_FILE=$1
28
39
COMMIT_SOURCE=$2
29
40
SHA1=$3
30
41
31
42
CURRENT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
32
- if [ $CURRENT_BRANCH == " HEAD" ]
43
+ # echo "CURRENT_BRANCH = "${CURRENT_BRANCH}
44
+
45
+ separator=" "
46
+ if [[ $CURRENT_BRANCH == * " _" * ]]
33
47
then
34
- exit 0;
48
+ # echo "branch name cotains underscore"
49
+ separator=" _"
50
+ elif [[ $CURRENT_BRANCH == * " -" * ]]
51
+ then
52
+ # echo "branch name cotains hyphen"
53
+ separator=" -"
54
+ else
55
+ separator=" "
35
56
fi
36
57
37
- PREFIX_REGEX=" ((DEF|BAK|STRY|MAINT|def|bak|stry|maint)[0-9]*)"
58
+ arr=(${CURRENT_BRANCH// ${separator} / } )
59
+ CURRENT_BRANCH=${arr[0]}
60
+
61
+ echo " CURRENT_BRANCH = " ${CURRENT_BRANCH} #
62
+
63
+ # PREFIX_REGEX="((DEF|BAK|STRY|MAINT|def|bak|stry|maint|TNTC)[0-9]*)(_*).*"
64
+
65
+ PREFIX_REGEX="((DEF|BAK|STRY|MAINT|def|bak|stry|maint|TNTC)[0-9]*)"
66
+ COMMIT_MESSAGE=$(cat $COMMIT_MSG_FILE)
38
67
if [[ $CURRENT_BRANCH =~ $PREFIX_REGEX ]]
39
68
then
40
69
TICKET="${BASH_REMATCH[0]}"
41
- COMMIT_MESSAGE= $( cat $COMMIT_MSG_FILE )
70
+ # echo "TICKET IS = "${TICKET}
42
71
43
72
if [[ $COMMIT_MESSAGE =~ $TICKET ]]
44
73
then
45
74
exit 0;
46
75
fi
47
76
48
- echo " ${TICKET} : ${COMMIT_MESSAGE} " > $COMMIT_MSG_FILE
49
- echo " Ticket '${TICKET} ', matched in current branch name, prepended to commit message."
77
+ echo "Ticket '${TICKET}', matched in current branch name, appended to commit message."
78
+
79
+ if [[ $COMMIT_MESSAGE == "TEST"* ]] || [[ $COMMIT_MESSAGE == "test"* ]] || [[ $COMMIT_MESSAGE == "MAINT"* ]] || [[ $COMMIT_MESSAGE == "maint"* ]]
80
+ then
81
+ echo ${COMMIT_MESSAGE}" - "${TICKET} > $COMMIT_MSG_FILE
82
+ else
83
+ echo "TEST: ${COMMIT_MESSAGE} - ${TICKET}" > $COMMIT_MSG_FILE
84
+ echo "TEST: was pre-fixed to the commit message"
85
+ fi
86
+
87
+ elif [[ $COMMIT_MESSAGE == "MAINT"* ]] || [[ $COMMIT_MESSAGE == "TEST"* ]] || [[ $COMMIT_MESSAGE == "test"* ]] || [[ $COMMIT_MESSAGE == "maint"* ]]
88
+ then
89
+ exit 0;
90
+ else
91
+ echo "TEST: "${COMMIT_MESSAGE} > $COMMIT_MSG_FILE
92
+ echo "TEST: was pre-fixed to the commit message"
50
93
fi
51
94
` ` `
95
+ * < b> pre-push< /b>
96
+ ` ` ` sh
97
+ # ------------------- Compile Maven Project -------------------- #
98
+
99
+ # changes directory to glide-template and runs mvn clean verify
100
+
101
+ CWD=` pwd`
102
+
103
+ # Get the path of the files which are getting modified
104
+ # need to write code
105
+
106
+ # Move to the project directory which you want to compile
107
+
108
+ mvn test-compile
109
+ if [ $? -ne 0 ]; then
110
+ cd $CWD
111
+ echo ' Git Push [ABORTED] >-----------> because of existing issues, Please check logs!'
112
+ exit 1
113
+ else
114
+ echo ' Compilation Status: No issues found >--------------------------> [SUCCESSFUL]'
115
+ echo ' Git Push >-----------------------------------------------------> [SUCCESSFUL]'
116
+ fi
117
+ cd $CWD
118
+ ` ` `
52
119
# ## Master git-hooks installer:
53
120
* ProjectDirectory/install_hooks.sh
54
121
` ` ` sh
@@ -73,11 +140,12 @@ This project contains a Maven project with tests. Git-Hooks are configured and b
73
140
fi
74
141
75
142
echo " Hooks installed successfully"
143
+
76
144
` ` `
77
145
78
146
# ## Makefile for setups:
79
147
* makefile
80
- ` ` ` Makefile
148
+ ` ` ` makefile
81
149
all: say_hello change_hooks_config
82
150
# all: say_hello generate_textfiles clean_textfiles
83
151
# Note - First Line of the make file is always the default goal/target
@@ -129,7 +197,8 @@ This project contains a Maven project with tests. Git-Hooks are configured and b
129
197
3. There is a ` Makefile` inside the project directory which is an easy to go step to do all the githooks setups in just one signle shot command which is ` make` .
130
198
131
199
* make file will first of all run ./install_hooks.sh or just set the ` git config core.hooksPath` .
132
- * < b> pre-commit< /b> has the code to build the project using maven comamnd ` mvn clean verify -Dmaven.test.skip=true`
200
+ * < b> pre-commit< /b> script looks for white-space errors in any of the newly added or modified files.
201
+ * < b> pre-push< /b> has the code to build the project using maven comamnd ` mvn clean verify -Dmaven.test.skip=true` before doing the actual push to the remote repository.
133
202
* < b> prepare-commit-msg< /b> has code to update commit message according to the branch name. If the branch name contains any defect, story or testcase number in that case the same will be appended to the start of the commit message also.
134
203
135
204
< ! -- < details><summary><b> Show instructions< /b></summary>
@@ -144,7 +213,7 @@ This project contains a Maven project with tests. Git-Hooks are configured and b
144
213
145
214
146
215
# ## Setup
147
- * Fire Below command
216
+ * Fire Below command inside the project directory ::
148
217
` ` ` sh
149
218
make
150
219
` ` `
0 commit comments