-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre-commit.sample
More file actions
executable file
·59 lines (50 loc) · 1.87 KB
/
pre-commit.sample
File metadata and controls
executable file
·59 lines (50 loc) · 1.87 KB
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
#!/usr/bin/bash
#
# hook to verify if ZTP CRs are valid
# author: Jose Gato Luis <jgato@redhat.com>
SITECONFIGS=(ZTP/HubClusters/el8k/SpokeClusters/ztp-gitops/gitop-repo/siteconfig
ZTP/HubClusters/el8k/SpokeClusters/ztp-gitops/gitop-repo/siteconfig-4.14)
PGTS=(ZTP/HubClusters/el8k/SpokeClusters/ztp-gitops/gitop-repo/policygentemplates
ZTP/HubClusters/el8k/SpokeClusters/ztp-gitops/gitop-repo/policygentemplates-workstream)
VERIFY_SCRIPT=/home/jgato/Projects-src/my_github/ztp-prevalidate/pre-validate-manifests.sh
ERROR=0
# just check if it is the first commit
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# lets do the pre-validation but only on the proper directory
for SITECONFIG in "${SITECONFIGS[@]}";
do
if git diff --name-only --cached | grep "${SITECONFIG}" > /dev/null
then
echo -e "\nPre validation of Siteconfigs directory: $(basename "${SITECONFIG}")\n"
if ! (${VERIFY_SCRIPT} "${SITECONFIG}") then
ERROR=1
fi
fi
done
for PGT in "${PGTS[@]}";
do
if git diff --name-only --cached | grep "${PGT}" > /dev/null
then
echo -e "\nPre validation of PolicyGenTemplates directory: $(basename "${PGT}")\n"
if ! (${VERIFY_SCRIPT} "${PGT}") then
ERROR=1
fi
fi
done
if [ ${ERROR} != 0 ]
then
echo "==========================================================="
echo "| The commit is aborted until errors ar solved |"
echo "| |"
echo "| If you really need to commit, disable the hook |"
echo "| <REPO>/.git/hooks/pre-commit |"
echo "| or, do the commit with '--no-verify' |"
echo "==========================================================="
fi
exit $ERROR