Compare commits
2 Commits
8d0fad7ed3
...
d55e6884ad
Author | SHA1 | Date | |
---|---|---|---|
d55e6884ad | |||
3a4360105b |
44
pre-receive.d/prevent-foxtrot-merge.sh
Normal file
44
pre-receive.d/prevent-foxtrot-merge.sh
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright (c) 2016 G. Sylvie Davies. http://bit-booster.com/
|
||||||
|
# Copyright (c) 2016 torek. http://stackoverflow.com/users/1256452/torek
|
||||||
|
# Copyright (c) 2021 Alfred Melch. https://melch.pro
|
||||||
|
# License: MIT license. https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# From: https://blog.developer.atlassian.com/stop-foxtrots-now/
|
||||||
|
|
||||||
|
NULL_REV="0000000000000000000000000000000000000000"
|
||||||
|
|
||||||
|
# refname (e.g. refs/head/master) will be updated from oldrev (commit hash) to newrev (commit hash)
|
||||||
|
while read oldrev newrev refname
|
||||||
|
do
|
||||||
|
if [ $oldrev = $NULL_REV ]; then
|
||||||
|
# pushing a new branch
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ $newrev = $NULL_REV ]; then
|
||||||
|
# deleting a branch
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$refname" = "refs/heads/master" ] || [ "$refname" = "refs/heads/main" ]; then
|
||||||
|
# Find the first parent of the commit where oldrev is a parent
|
||||||
|
# git log: list commits from newrev to oldrev
|
||||||
|
# %H: commit hash
|
||||||
|
# %P: parent hashes (list of parents)
|
||||||
|
# grep: filter for oldrev
|
||||||
|
# Should appear once as a parent
|
||||||
|
# awk: print the second word
|
||||||
|
# The second word is the first parent. Third word would be second parent, ...
|
||||||
|
MATCH=`git log --first-parent --pretty='%H %P' $oldrev..$newrev |
|
||||||
|
grep $oldrev |
|
||||||
|
awk '{ print $2 }'`
|
||||||
|
# First parent should be the oldrev
|
||||||
|
if [ "$oldrev" = "$MATCH" ]; then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo >&2 "*** Push rejected! Foxtrot merge blocked! ***"
|
||||||
|
echo "See: https://blog.developer.atlassian.com/stop-foxtrots-now/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
28
use-hook-dir.sh
Normal file
28
use-hook-dir.sh
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# From: https://gist.github.com/mjackson/7e602a7aa357cfe37dadcc016710931b
|
||||||
|
|
||||||
|
# Make a symlink per hook to this script you use e.g. .git/hooks/pre-receive.
|
||||||
|
# It looks for scripts in the .git/hooks/pre-receive.d directory and executes them in order,
|
||||||
|
# passing along stdin. If any script exits with a non-zero status, this script exits.
|
||||||
|
|
||||||
|
script_dir=$(dirname $0)
|
||||||
|
hook_name=$(basename $0)
|
||||||
|
|
||||||
|
hook_dir="$script_dir/$hook_name.d"
|
||||||
|
|
||||||
|
if [[ -d $hook_dir ]]; then
|
||||||
|
stdin=$(cat /dev/stdin)
|
||||||
|
|
||||||
|
for hook in $hook_dir/*; do
|
||||||
|
echo "$stdin" | $hook "$@"
|
||||||
|
|
||||||
|
exit_code=$?
|
||||||
|
|
||||||
|
if [ $exit_code != 0 ]; then
|
||||||
|
exit $exit_code
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Loading…
x
Reference in New Issue
Block a user