File: pre-commit

package info (click to toggle)
checksec 2.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 10,936 kB
  • sloc: sh: 1,882; makefile: 2
file content (36 lines) | stat: -rwxr-xr-x 1,176 bytes parent folder | download
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
#!/usr/bin/env bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

# The git hooks repo
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
REPO_ROOT=$(cd "${DIR}" && git rev-parse --show-toplevel)
# The current repo root, in case the repo is different from the hooks (this allows using a single pre-commit across multiple repos)
CURRENT_REPO=$(git rev-parse --show-toplevel)

# Redirect output to stderr.
exec 1>&2

# check to ensure all tools exist
tools=('pre-commit' 'checkov' 'shfmt')
for tool in "${tools[@]}"; do
  if ! command -v "${tool}" > /dev/null 2>&1; then
    cat << EOF
    Error: ${tool} not found
    Please install via brew or package manager
    'brew install ${tool}'
    or
    install required tools
    ${tools[*]}
EOF
    exit 2
  fi
done

# run pre-commit checks
pre-commit hook-impl --config="${REPO_ROOT}"/.pre-commit-config.yaml --hook-type=pre-commit --hook-dir "${CURRENT_REPO}" -- "$@"