Skip to content

Commit c21a083

Browse files
committed
chore: add local git hooks
1 parent eeff02c commit c21a083

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

.git_hooks/commit-msg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
npx commitlint --edit $1

.git_hooks/pre-push

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
containsref() { if [[ $2 =~ $1 ]]; then echo 1; else echo 0; fi }
5+
6+
push_command=$(ps -ocommand= -p $PPID | cut -d' ' -f 4)
7+
protected_branch='main'
8+
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
9+
is_push_to_main_origin=$(containsref '[email protected]:/?fingerprintjs/' "$push_command")
10+
11+
# Block pushes only to protected branch in main repository
12+
if [ $is_push_to_main_origin = 1 ] && [ "$protected_branch" = "$current_branch" ]; then
13+
echo "You are on the $protected_branch branch, push blocked."
14+
exit 1 # push will not execute
15+
fi

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

install_hooks.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Make .git_hooks folder as hooks source for git
4+
git config core.hooksPath .git_hooks/
5+
6+
# install commitlint and @commitlint/config-conventional globally
7+
npm install -g commitlint @commitlint/config-conventional

0 commit comments

Comments
 (0)