-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.sh
More file actions
executable file
·38 lines (27 loc) · 978 Bytes
/
pre-commit.sh
File metadata and controls
executable file
·38 lines (27 loc) · 978 Bytes
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
#! /bin/bash
# Pre-commit githook to run before every commit to validate it locally
# 1. Check that branch name matches conventions (branch-name.sh)
# set directory for calling other scripts
DIR=$(dirname "${BASH_SOURCE[0]}")
# if in hook, then prep PATH to find in repo `scripts/hooks/` dir
# shellcheck disable=SC2076
if [[ $DIR =~ ".git" ]]; then
DIR+="/../../scripts/hooks"
fi
BRANCH_NAME_ERROR=" ! Branch name does not match conventions "
BRANCH_PROTECTION_ERROR=" ! No commits on this branch "
main() {
# Call branch protection script
if ! $DIR/internal/branch-protections.sh; then
echo "$(tput setaf 1)$(tput setab 7)$BRANCH_PROTECTION_ERROR$(tput sgr 0)"
return 1
fi
# Call branch name script
if ! $DIR/internal/branch-name.sh; then
echo "$(tput setaf 1)$(tput setab 7)$BRANCH_NAME_ERROR$(tput sgr 0)"
echo " <prefix>/<description>"
echo "prefix options: ($($DIR/internal/prefix-list.sh))"
return 1
fi
}
main