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

In some cases, I need to ensure that Mercurial users run hg pull -u before allowing any hg commit , i.e. hg pull will mean that the incoming queue is empty - and in addition, I also want the person to use the head version of the branch.

How can I set such a restriction?

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

+7
source share
3 answers

You can ask your developers to install

 [hooks] pre-commit = hg pull -u 

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

This makes Mercurial a bit like Subversion: your developers will only have one outstanding set of changes. But pay attention, as soon as someone clicks on the server, hg pull -u cannot update the new tip of the branch, as it will cross the branches (topological branches) for this. Therefore, appropriate merging (or rebase , see hg pull --rebase ) will be required at this point.

+3
source

Normally, mercurial will not allow you to push the open head to the server without using the -f (force) flag. You can write a hook to automatically pull it out, but it cannot be force applied to the server side because the server does not know what you have. There is an article on the mercury website about this scenario: https://www.mercurial-scm.org/wiki/TipsAndTricks?highlight=%28heads%29#Prevent_a_push_that_would_create_multiple_heads

+1
source

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

As a result, the hook prevents any click that creates several branches on the branch (for example, one in the anonymous / default branches, plus one in the named branches). This effectively forces the pull to lock, because you need to pull, get two heads locally, then merge or reinstall to remove it.

Notice that the hook is on the server / master repo

+1
source

All Articles