Skip to content

Instantly share code, notes, and snippets.

@ldionne
Created November 9, 2018 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldionne/2c260ce2081db74206e074e09cff71d0 to your computer and use it in GitHub Desktop.
Save ldionne/2c260ce2081db74206e074e09cff71d0 to your computer and use it in GitHub Desktop.
Pre-push hook for LLVM monorepo
#!/bin/sh
# Pre-push hook making sure there is no merge commit in the set of commits
# being pushed upstream. This hooks works by walking the set of commits being
# pushed and making sure that none of them has two parents or more (which is
# the definition of a merge commit).
#
# This hook is called with the following parameters:
#
# ${1} -- Name of the remote to which the push is being done
# ${2} -- URL to which the push is being done
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local sha1> <remote ref> <remote sha1>
set -e
remote="${1}"
url="${2}"
while read local_ref local_sha remote_ref remote_sha; do
range="${remote_sha}..${local_sha}"
new_commits="$(git rev-list "${range}")"
for commit in ${new_commits}; do
parents=$(git cat-file -p "${commit}" | grep 'parent' | wc -l)
if (( ${parents} >= 2 )); then
short="$(git rev-parse --short "${commit}")"
echo "commit ${short} appears to be a merge commit: aborting the push" >&2
exit 1
fi
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment