Dominic Akadimah
Dominic Akadimah

Reputation: 11

How do I prevent hg update <branch> without committing in the active branch in Mercurial?

Let's say I have 2 branches on my local repo, case1 and case2. I'm currently working on case1 and have uncommitted changes.

When I hg up case2 I want this navigation to be prohibited unless I have made the choice of committing my changes in case1 or not.

Any idea how to do this?

Upvotes: 1

Views: 342

Answers (1)

Face
Face

Reputation: 511

If you hg up case2 with uncommitted changes, and case2 is no direct ancestor/descendant of case1, Mercurial will refuse to do it with

abort: crosses branches (merge branches or use --clean to discard changes)

You can then opt for either committing your changes, discard them by means of using the proposed option or update to the common ancestor of case1 and case2. The later case is a two-hop approach to take the uncommitted changes with you while you hop to case2.

In addition, newer versions of Mercurial have the --check option for the update command. This will do exactly what you wanted: abort the command in case your working copy is dirty.

Of course, all this is pretty obvious if you check hg help update.

Upvotes: 2

Related Questions