Skip to content

Instantly share code, notes, and snippets.

@guibeira
Last active June 5, 2023 14:25
Show Gist options
  • Save guibeira/69e7a5d35a7a2cfb56c748b732d0aedc to your computer and use it in GitHub Desktop.
Save guibeira/69e7a5d35a7a2cfb56c748b732d0aedc to your computer and use it in GitHub Desktop.
Pre commit on work folders
repos:
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: master
hooks:
- id: forbid-space-in-indent
types: [python]
#!/usr/bin/env bash
# start templated
ARGS=(hook-impl --config="$HOME"/gitglobalhooks/.pre-commit-config.yaml --hook-type=pre-commit)
# end templated
HERE="$(cd "$(dirname "$0")" && pwd)"
# run only on mashgin projects folder
LOCAL_EXE=$(pwd)
ARGS+=(--hook-dir "$HERE" -- "$@")
if [ -e ./.git/hooks/pre-commit ]; then
echo "pre-commit already installed"
./.git/hooks/pre-commit "$@"
elif [[ $LOCAL_EXE == *$COMPANY_FOLDER_NAME* ]] ; then
echo "Running ${COMPANY_FOLDER_NAME} rules."
exec pre-commit "${ARGS[@]}"
else
echo "Not a ${COMPANY_FOLDER_NAME} project."
exit 0
fi
@guibeira
Copy link
Author

guibeira commented Sep 29, 2022

Put the company name folder on your bashrc/zshrc

export COMPANY_FOLDER_NAME="foobar_company"

create a folder

cd && mkdir gitglobalhooks && cd gitglobalhooks

copy both files for this folder

wget https://gist.githubusercontent.com/guibeira/69e7a5d35a7a2cfb56c748b732d0aedc/raw/ac7a401a7a3bab7f382ed168d6bb6464c9190824/.pre-commit-config.yaml
wget https://gist.githubusercontent.com/guibeira/69e7a5d35a7a2cfb56c748b732d0aedc/raw/ac7a401a7a3bab7f382ed168d6bb6464c9190824/precommit

On your git config

[core]
    hooksPath = /Users/<username>/gitglobalhooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment