-
Notifications
You must be signed in to change notification settings - Fork 4
/
pre-commit
40 lines (35 loc) · 1.07 KB
/
pre-commit
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
# !/bin/sh
# To enable this hook, name this file "pre-commit".
# Remember to make it executable by calling the following in the terminal: chmod +x filename
#Setup
reponame=$(basename `git rev-parse --show-toplevel`)
#Intro text
echo testing_failed " \n -- Running pre-commit hook -- \n"
echo " \n -- Testing $reponame -- \n"
#Run quick tests
julia --project=. test/quicktests.jl
#If tests failed
if [[ $? -ne 0 ]]; then
#Raise an error
echo "\n -- ERROR: Testing failed, commit halted -- \n"
#Stop the commit
exit 1
#Otherwise
else
#Inform that all tests passed
echo "\n -- All tests passed, commit completed -- \n"
#Run formatting
julia -e '
using Pkg
Pkg.activate("./docs")
using JuliaFormatter
format(".")
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have been formatted !!!"
write(stdout, out)
exit(1)
end'
fi