FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TJ-Bot/scripts/pre-commit at develop · Together-Java/TJ-Bot · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Together-Java
/
TJ-Bot
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
116
Star
121
Code
Issues
39
Pull requests
19
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
TJ-Bot
/
scripts
/
pre-commit
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (51 loc) · 1.85 KB
Breadcrumbs
TJ-Bot
/
scripts
/
pre-commit
Copy path
File metadata and controls
60 lines (51 loc) · 1.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/bin/sh
create_stash
() {
#
Stash unstaged changes, if any
previous_stash=
$(
git rev-parse -q --verify refs/stash
)
git stash push -q
new_stash=
$(
git rev-parse -q --verify refs/stash
)
}
pop_stash
() {
#
Restore unstaged changes, if any
if
[
"
$previous_stash
"
!=
"
$new_stash
"
]
;
then
git stash apply -q
&&
git stash drop -q
fi
}
echo
"
****Running pre-commit hooks****
"
#
We want to apply spotless on all staged files. Therefore, we have to first draft a
#
WIP-commit for the staged changes and put the unstaged changes aside using stash
#
(otherwise spotless would apply on them as well, see https://github.com/diffplug/spotless/issues/623).
#
There are a few edge cases to handle here; for example if there are no unstaged changes, stash would not create a stash.
#
Hence, the following pop of the stash must be guarded (see https://stackoverflow.com/a/20480591/2411243).
#
Mini commit for staged changes, so that we can stash away unstaged in the next step (bypass hook with "no-verify" to avoid recursion)
git commit --no-verify --message
"
WIP
"
commitExitCode=
$?
if
[
"
$commitExitCode
"
-ne
0 ]
;
then
#
Commit failed (for example if there is nothing staged), early-out
exit
"
$commitExitCode
"
fi
#
Put unstaged away
create_stash
#
Get back staged changes
git reset --soft HEAD^
#
Apply spotless on the staged changes only (rest has been put away)
echo
"
**Applying spotless**
"
./gradlew spotlessApply
spotlessExitCode=
$?
if
[
"
$spotlessExitCode
"
-ne
0 ]
;
then
#
Spotless failed, restore unstaged
pop_stash
exit
"
$spotlessExitCode
"
fi
echo
"
**Running Sonarlint checks**
"
./gradlew sonarlintMain
sonarlintExitCode=
$?
if
[
"
$sonarlintExitCode
"
-ne
0 ]
;
then
pop_stash
exit
"
$sonarlintMain
"
fi
#
Spotless possibly found changes, apply them, excluding untracked files
git add -u
#
Restore back the unstaged changes
pop_stash
echo
"
****Done pre-commit hooks****
"
Back
|
FazBrowse Home
|
New Git URL