Skip to content

Instantly share code, notes, and snippets.

@catrider
Last active August 29, 2015 14:16
Show Gist options
  • Save catrider/6b240a6b4065f00f7bd2 to your computer and use it in GitHub Desktop.
Save catrider/6b240a6b4065f00f7bd2 to your computer and use it in GitHub Desktop.
Git server-side 'update' hook to reject changes to 'release' branches if the changes contain one or more commits present on the 'develop' branch
#!/bin/bash
# --- Command line
refname="$1"
oldrev="$2"
newrev="$3"
$(echo $refname | grep -q /release/)
on_release_branch=$?
if [ $on_release_branch -eq 0 ] && [ "$oldrev" != "0000000000000000000000000000000000000000" ]; then
echo "refname is: $refname"
echo "oldrev is: $oldrev"
echo "newrev is: $newrev"
if [ "$(git log --oneline $oldrev..$newrev | wc -l)" -ne "$(git log --oneline $oldrev..$newrev --not develop | wc -l)" ]; then
echo "Rejected: the following commits from develop are present"
comm -23 <(echo | git log --oneline $oldrev..$newrev | grep -o "^[a-z0-9]\+") <(echo | git log --oneline $oldrev..$newrev --not develop | grep -o "^[a-z0-9]\+")
exit 1
fi
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment