Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: enforce "hg pull -u" before "hg commit"

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)

like image 513
Peter Toft Avatar asked Apr 16 '12 13:04

Peter Toft


2 Answers

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).

like image 137
Martin Geisler Avatar answered Oct 11 '22 09:10

Martin Geisler


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

like image 34
Tyler Smith Avatar answered Oct 11 '22 08:10

Tyler Smith