hg update without -C to switch branches

Matt Mackall mpm at selenic.com
Sat Mar 22 18:03:38 UTC 2008


On Sat, 2008-03-22 at 17:41 +0100, Florent Guillaume wrote:
> Hi,
> 
> Would there be opposition to not having the
>    update spans branches, use 'hg merge' or 'hg update -C' to lose changes
> message when you update to a different branch but there are no local 
> changes?
> 
> I find the current behavior very harmful when working with named 
> branches. I have to tell my users to do "hg up -C" to switch branches, 
> but using -C all the time is a very bad habit that could lead to loss of 
> local changes when done at the wrong time. I'd much rather have them do 
> "hg up otherbanch", and if there *are* local changes then update would 
> output its message above and stop.

Something like this?

diff -r 351da911f739 mercurial/merge.py
--- a/mercurial/merge.py	Fri Mar 21 17:22:47 2008 -0500
+++ b/mercurial/merge.py	Sat Mar 22 13:01:38 2008 -0500
@@ -364,8 +364,11 @@
                     raise util.Abort(_("there is nothing to merge, just use "
                                        "'hg update' or look at 'hg heads'"))
         elif not (overwrite or branchmerge):
-            raise util.Abort(_("update spans branches, use 'hg merge' "
-                               "or 'hg update -C' to lose changes"))
+            if wc.files() or wc.deleted():
+                raise util.Abort(_("update spans branches, use 'hg merge' "
+                                   "or 'hg update -C' to lose changes"))
+            # Allow jumping branches if there are no changes
+            overwrite = True
         if branchmerge and not forcemerge:
             if wc.files() or wc.deleted():
                 raise util.Abort(_("outstanding uncommitted changes"))

Seems reasonable.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list