[monorepo] Pre-push hook to prevent pushing merge commits

Hi,

At the LLVM dev meeting, some people discussed the possibility of having pre-push and/or pre-commit hooks to avoid messing up the history when we move on to the monorepo. One of the concerns was about people starting to push merge commits and unsquashed commits upstream, resulting in a messy history.

I had volunteered to write a hook that would check for the absence of merge commits in the set of commits being pushed upstream, which I did. The hook is available here: https://gist.github.com/ldionne/2c260ce2081db74206e074e09cff71d0.

If there is any interest for something like this, the code’s there.

Cheers,
Louis

Hi,

At the LLVM dev meeting, some people discussed the possibility of having pre-push and/or pre-commit hooks to avoid messing up the history when we move on to the monorepo. One of the concerns was about people starting to push merge commits and unsquashed commits upstream, resulting in a messy history.

I had volunteered to write a hook that would check for the absence of merge commits in the set of commits being pushed upstream, which I did. The hook is available here: https://gist.github.com/ldionne/2c260ce2081db74206e074e09cff71d0.

If there is any interest for something like this, the code’s there.

I would like to note that it is a client-side hook. So every one would
need to install it.
To be actually able to prevent such things, it needs to be
centralized, server-side hook.
(I don't think you can have server-side hooks on github, so if that is required,
the master (as in, not a mirror, but the one you commit things into)
git monorepo can't be located on github..)

Cheers,
Louis

Roman.

Roman Lebedev via llvm-dev <llvm-dev@lists.llvm.org> writes:

(I don't think you can have server-side hooks on github, so if that is required,
the master (as in, not a mirror, but the one you commit things into)
git monorepo can't be located on github..)

This is the main reason we did not go with a GitHub solution for our
code.

If we used a pull request model for the monorepo then review can
mitigate the kinds of problems that server-side hooks address, but of
course it's a more manual process and prone to mistakes. I understand
that a decision in that direction is orthogonal to moving to git.

                         -David

I agree that a server side hook would be much better, but encouraging contributors to install a client side hook may still be better than nothing. We could for example put a link to the hook in the setup instructions for the monorepo. People don’t have to set it up but I expect most people would.

If we go with a pull request model, it should be possible to create a hook that checks for that using GitHub. However, this is orthogonal and I am not proposing that at this moment.

Louis

Github has the notion of protected branches. This is the same way you disable the ability to force push to a branch, which I dare say is absolute mandatory that we enable for master, and probably every other branch as well, except for perhaps 1-2 admins.

I haven’t studied the API in detail, but I believe it should be possible to create a required check that a commit is not a merge commit (among other things), and reject it if it is.