asc99c
asc99c

Reputation: 3905

Mercurial pre-merge hook

Is there a way to do some checks before allowing a merge in Mercurial?

I have found the pre-update hook and have a script that runs before an update is allowed, by adding the following to ~/.hg/hgrc:

[hooks]
pre-update = ~/hg_pre_update.sh

But I'd like to run the check before allowing a merge as well, and currently it just allows the merge to go through without running my checks.

Background

In case there are alternative ways to solve the problem...

We have been having a number of problems with 'lost' edits under Mercurial. I've tracked down most of them now to the same underlying cause: someone has vim edit sessions open while either they or someone else does a hg update or merge. The editor warns the file has changed externally, the user ignores the warning and saves their changes.

When these changes are committed, for Mercurial there is nothing controversial. The user has simply reverted all the changes brought in with the last update and put in their own changes.

Some time later, we notice the code has gone walkabouts. Cue assorted insults flung the way of mercurial...

Upvotes: 1

Views: 642

Answers (2)

asc99c
asc99c

Reputation: 3905

Sorry just worked out there is a pre-merge hook that works just the same as pre-update. I tried it before asking the question, but now just looking at my hgrc I realise I put the script being called for that hook to ~/hg_pre_merge.sh which doesn't exist.

I can't find the existence of pre-merge documented anywhere but still feeling like a bit of a muppet now.

Feeling like a bit of a muppet now.

Upvotes: 1

Macke
Macke

Reputation: 25710

Set vim to autoreload changes if no local changes where done. (otherwise ask, or force a merge)

that's how I avoid such issues in any editor...

Upvotes: 1

Related Questions