-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pre-commit hooks setup
- Loading branch information
Showing
15 changed files
with
124 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# The current repo root | ||
CURRENT_REPO=$(git rev-parse --show-toplevel) | ||
if [[ -f $CURRENT_REPO/.gitlfs ]]; then | ||
command -v git-lfs > /dev/null 2>&1 || { | ||
echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n" | ||
exit 2 | ||
} | ||
git lfs post-checkout "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
# The current repo root | ||
CURRENT_REPO=$(git rev-parse --show-toplevel) | ||
if [[ -f $CURRENT_REPO/.gitlfs ]]; then | ||
command -v git-lfs > /dev/null 2>&1 || { | ||
echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n" | ||
exit 2 | ||
} | ||
git lfs post-commit "$@" | ||
fi | ||
|
||
"${CURRENT_REPO}"/helpers/enable-git-hooks.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# The current repo root | ||
CURRENT_REPO=$(git rev-parse --show-toplevel) | ||
if [[ -f $CURRENT_REPO/.gitlfs ]]; then | ||
command -v git-lfs > /dev/null 2>&1 || { | ||
echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n" | ||
exit 2 | ||
} | ||
git lfs post-merge "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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}" -- "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# The current repo root | ||
CURRENT_REPO=$(git rev-parse --show-toplevel) | ||
if [[ -f $CURRENT_REPO/.gitlfs ]]; then | ||
command -v git-lfs > /dev/null 2>&1 || { | ||
echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n" | ||
exit 2 | ||
} | ||
git lfs pre-push "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# enable git commit hooks | ||
|
||
LOCAL_REPO="$(git rev-parse --show-toplevel)" | ||
if [[ -d ${LOCAL_REPO}/.git-hooks/ ]]; then | ||
git config core.hooksPath "${LOCAL_REPO}/.git-hooks/" > /dev/null | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters