4

I have colleagues who push multiple heads by using the --force switch because they haven't merged properly.

Are there any ways to prevent this?

Joel B Fant
  • 24,406
  • 4
  • 66
  • 67
akashic
  • 85
  • 2
  • 7
  • You'd have to alter the source and recompile and make them use that, but it's a bad idea. What's the actual problem that you think eliminating `-force` would solve? – Joel B Fant Aug 16 '11 at 01:14
  • 1
    @Joel B Fant: I think that he has colleagues, that instead of merging properly just push several heads with force – zerkms Aug 16 '11 at 01:15
  • @zerkms Correct, need to ensure people merge properly. – akashic Aug 16 '11 at 01:59
  • 1
    Then *that* is the real question/problem. **:)** – Joel B Fant Aug 16 '11 at 03:03
  • 7
    ooo, if that's the question, then I vote that anyone failing to merge properly be required to write "I, $NAME, will not use --force instead of properly merging" 100 times on the whiteboard, and if they get smart about it and put "$NAME" instead of their name, then they have to write "I do not understand shell substitution variables." 100 times too. – shelleybutterfly Aug 16 '11 at 03:47
  • 1
    *Why* are they doing that? Surely they understand and know that this causes problems for other developers, and thus that they are wasting company time? In other words, *which problem are **they** trying to solve by forcing their push*? You should talk to your developers as I don't think this is a software-solvable problem, it is a personnel problem. – Lasse V. Karlsen Aug 16 '11 at 07:13
  • 1
    Duplicate of http://stackoverflow.com/questions/4350310/how-can-i-create-a-mercurial-hook-that-prevents-new-heads – gavenkoa Sep 07 '15 at 20:06

5 Answers5

6

You can do this with a pretxnchangegroup hook on the server side.

Here are a few examples: http://www.softwareprojects.com/resources/programming/t-mercurial-hook-forbid-2-heads-1910.html

All those hooks are doing is making sure that after the changegroup is applied that there's still only one head (or only one per branch if you want to get fancy).

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
2

This is the best from top proficient developers: http://hg.python.org/hooks/file/default/checkheads.py

Visit http://hg.python.org/hooks/file/default/ for list of another useful hooks.

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • I found issue this Python `cheackheads.py` implementation, see: http://stackoverflow.com/questions/32402715/merges-between-two-branches-in-two-directions-any-good-reason-or-completely-fo/ – gavenkoa Sep 07 '15 at 20:05
2

Tell them they shouldn't do it, and enforce the workflow with hooks on a repository you control.

At work, we restrict it to one head / branch. Essentially replace forbid_2head.sh with this:

#!/bin/bash

# Ensure only one head per branch in hg repository
for BRANCH in `hg branches -qa`
do
    COUNT=`hg heads -q $BRANCH | wc -l`
    if [ "$COUNT" -ne "1" ] ; then
       echo "Error: Trying to push more than one head to branch $BRANCH."
       exit 1
    fi
done
exit 0
1

You could revoke their push rights to the repository that they are --forceing to, and make them push to a different server, or submit changes via patch.

Joel B Fant
  • 24,406
  • 4
  • 66
  • 67
shelleybutterfly
  • 3,216
  • 15
  • 32
0

First off, I'd tell developers that a --force push is not allowed.

I'd also use the server side hook solution as prescribed above, and in the hook add an email to everyone stating WHO tried to push multiple heads into the central repo [and then format his hard drive ;)]