1

I'm using server-side (remote) hooks to prevent specific kind of pushes. Among other thing, I want to ban pushes that are creating new heads in mercurial repository even if they were pushed with --force.

I can think only of one way to achieve this: just iterate through ancestors and fail on first ancestor that has two children.

This approach actually works, but I'll be very glad if someone can show me a more elegant way of achieving the same.

shabunc
  • 23,119
  • 19
  • 77
  • 102
  • Have a look at the existing question and in particular the accepted answer along with its comments: http://stackoverflow.com/questions/1705921/useful-mercurial-hooks Also see https://www.mercurial-scm.org/wiki/TipsAndTricks#Prevent_a_push_that_would_create_multiple_heads – planetmaker Dec 15 '16 at 14:25

1 Answers1

1

OK, so it turns out it's done much easier than I've anticipated. Basically all you need is to check for the number of head in the repo repo object, so:

if repo.heads() > 1:
     return True
shabunc
  • 23,119
  • 19
  • 77
  • 102
  • in addition, your first proposal would not allow branches that split even if they merge and end up with a single head, because there would be a point of bifurcation with two children, therefore rejected – arhak Dec 16 '16 at 16:04
  • @arhak good point! In our case though merges are not allowed, so there's no such thing like bifurcation. – shabunc Dec 16 '16 at 18:59