commit 06e15baf585e927a2341d24a4039c8e6167d6adb Author: Tai Groot Date: Sun May 28 13:04:08 2023 -0700 initial commit diff --git a/post-checkout b/post-checkout new file mode 100755 index 0000000..c37815e --- /dev/null +++ b/post-checkout @@ -0,0 +1,3 @@ +#!/bin/sh +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-checkout'.\n"; exit 2; } +git lfs post-checkout "$@" diff --git a/post-commit b/post-commit new file mode 100755 index 0000000..e5230c3 --- /dev/null +++ b/post-commit @@ -0,0 +1,3 @@ +#!/bin/sh +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 "$@" diff --git a/post-merge b/post-merge new file mode 100755 index 0000000..c99b752 --- /dev/null +++ b/post-merge @@ -0,0 +1,3 @@ +#!/bin/sh +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-merge'.\n"; exit 2; } +git lfs post-merge "$@" diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..fc7b9f3 --- /dev/null +++ b/pre-commit @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set +eou pipefail +size_limit=$((5 * 2**20)) +# make sure we have at least 1 commit in the repo +# so we don't fail on the first commit +test "$(git rev-list --count HEAD 2>/dev/null)" -gt 1 2> /dev/null > /dev/null || exit 0 + +repo_root=$(git rev-parse --show-toplevel) +pushd $repo_root 2>/dev/null > /dev/null +empty_tree=$(git hash-object -t tree /dev/null) +if git rev-parse --verify HEAD > /dev/null 2>&1 +then + against=HEAD +else + against="$empty_tree" +fi +IFS=' +' +hasLargeFile=false +for file in $(git diff-index --cached --name-only $against); do + file_size=$(([ ! -f $file ] && echo 0) || (ls -la $file | awk '{ print $5 }')) + if [ "$file_size" -gt "$size_limit" ]; then + echo File $file is $(( $file_size / 10**6 )) MB, which is larger than our configured limit of $(( $size_limit / 10**6 )) MB + hasLargeFile=true + fi +done + +if $hasLargeFile; then + echo Commit too large, did you add a binary file? For image assets, consider git-lfs. + popd $repo_root 2>/dev/null > /dev/null + exit 1 +fi +popd $repo_root 2>/dev/null > /dev/null || true +gitleaks protect --verbose --redact --staged diff --git a/pre-push b/pre-push new file mode 100755 index 0000000..87cf4da --- /dev/null +++ b/pre-push @@ -0,0 +1,31 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +#remote="$1" +#url="$2" + +#zero=$(git hash-object --stdin /dev/null 2> /dev/null || { echo >&2 "\nThis repository is configured for mg but 'mg' was not found on your path. Install it with go install github.com/taigrr/mg/cmd/mg@latest or remove this code from your templates in ~/.config/git/hooks.\n"; exit 2; } + +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/pre-push' and your templates in ~/.config/git/hooks.\n"; exit 2; } +git lfs pre-push "$@"