Mercurial: enforce "hg pull -u" before "hg commit"
Asked Answered
L

3

7

I have in some cases a need to enforce that Mercurial-users have run hg pull -u before any hg commit can be allowed, i.e., hg pull will mean that the incoming queue is empty — and furthermore I also want that the person is using the head version of the branch.

How can I set up such a restriction?

(I am fully aware that this goes against parts of the DVCS design core)

Lema answered 16/4, 2012 at 13:57 Comment(3)
Another way of asking this is how to implement a server trigger to disallow pushes that create multiple heads.Abroms
I can not tell you how to automate, but I use "hg incoming" to check whether I need to pull. You might want to use that.Seer
It would be better if you explained the problem you are trying to solve rather than the broken solution you want to fix.Cann
F
3

You could ask your developers to install

[hooks]
pre-commit = hg pull -u

in their config files (it should probably be installed in the per-repository .hg/hgrc file since this workflow is repository specific).

This makes Mercurial a little Subversion-like: your developers will only have one outstanding changeset. But note as soon as someone pushes to the server, hg pull -u cannot update to the new branch tip since it will cross branches (topological branches) to do so. So a proper merge will be needed at that point (or a rebase, see hg pull --rebase).

Fiorenze answered 16/4, 2012 at 15:42 Comment(0)
W
1

Normally mercurial will NOT let you push an open head to the server without using the -f flag (force). You can write a hook to pull automatically but that can not be enforced server side due to the server not knowing what you have. There is an article on mercurial's website about this scenario: https://www.mercurial-scm.org/wiki/TipsAndTricks?highlight=%28heads%29#Prevent_a_push_that_would_create_multiple_heads

Whaleboat answered 16/4, 2012 at 15:16 Comment(0)
O
1

As Adam says, perhaps what you really need to do is prevent multiple heads (per branch). This is what we do, using the 'forbid_2head' hook from Netbeans (linked from here https://www.mercurial-scm.org/wiki/TipsAndTricks#Prevent_a_push_that_would_create_multiple_heads)

The result is that the hook prevents any push that creates multiple heads on a branch (so one on the anonymous/default branch plus one each on named branches). This effectively forces a pull before commit because you have to pull, get the two heads locally, then merge or rebase to remove it.

note, the hook is on the server/master repo

Overstuffed answered 7/9, 2012 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.