Added hook to prevent pushing to staging and master
This commit is contained in:
11
.githooks/pre-push
Normal file
11
.githooks/pre-push
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
protected_branches=("master" "staging")
|
||||||
|
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
|
for branch in "${protected_branches[@]}"; do
|
||||||
|
if [ "$current_branch" = "$branch" ]; then
|
||||||
|
echo "Direct pushes to '$branch' are not allowed. Use a pull request instead."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
14
setup-hooks.sh
Normal file
14
setup-hooks.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
HOOKS_DIR=".githooks"
|
||||||
|
GIT_HOOKS_DIR=".git/hooks"
|
||||||
|
|
||||||
|
mkdir -p "$GIT_HOOKS_DIR"
|
||||||
|
|
||||||
|
for hook in "$HOOKS_DIR"/*; do
|
||||||
|
hook_name=$(basename "$hook")
|
||||||
|
cp "$hook" "$GIT_HOOKS_DIR/$hook_name"
|
||||||
|
chmod +x "$GIT_HOOKS_DIR/$hook_name"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Git hooks installed!"
|
||||||
|
|
||||||
Reference in New Issue
Block a user