简体   繁体   中英

How can I create a mercurial hook that prevents new heads?

I have several repositories that have been converted from SVN and moving forward we want make sure when people push to the repository they can't create additional heads. there are several hooks in the TipsAndTricks wiki page that prevent pushing if there are multiple heads, but how I can build a hook that prevents pushing new heads?

It seems like the right way to do this would be to compare the number of heads from revision 0:parent and then compare 0:tip, but I can't seem to find a way to do that. hg heads -r $HG_NODE only shows me the number of heads after the user's first commit being pushed.

By default, hg push prevents pushing of additional heads, requiring the -f flag. You could write a Mercurial extension to make it ignore that flag, effectively disabling pushing of new heads.

That said, I would question the wisdom of mechanically disallowing new heads. Instead, I would train your team to merge properly before pushing, while still allowing them to do it on the rare occasion that it makes sense, especially since Mercurial already warns you.

Mercurial wiki - Tips and Tricks - Prevent a push that would create multiple heads

Points to several existing hooks which may be useful to copy and adapt.

Check this link. It automates the process of allowing multiple heads

Mercurial Hook: forbid multiple heads

使用hg ci -m 'Closed branch feature-x' --close-branch来关闭除一个头之外的所有头,然后应用普通的单头钩。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM