# HG changeset patch # User Matt Mackall # Date 1206370865 18000 # Node ID cdc458b12f0f3f18e79ba37d5ab277fc681061c6 # Parent 31a01e3d99ccbbd2e74f2c3c43001ace8af636ea update: better logic and messages for updates - complain about attempts to merge with ancestor - when updating, differentiate between - crossing named branches with no local changes (jump) - crossing named branches with local changes (complain) - nonlinear update on the same named branch, no changes (complain some more) - nonlinear update on the same named branch, changes (different complaining) diff -r 31a01e3d99cc -r cdc458b12f0f mercurial/commands.py --- a/mercurial/commands.py Mon Mar 24 16:20:15 2008 +0100 +++ b/mercurial/commands.py Mon Mar 24 10:01:05 2008 -0500 @@ -2764,17 +2764,17 @@ Update the working directory to the specified revision, or the tip of the current branch if none is specified. - See 'hg help dates' for a list of formats valid for -d/--date. - - If there are no outstanding changes in the working directory, the - result is the requested version. - - If the requested version is a descendant of the working directory - and there are outstanding changes, those changes will be merged - into the result. - - By default, update will refuse to run if there are outstanding - changes and the update spans branches. + + If the requested revision is a descendant of the working + directory, any outstanding changes in the working directory will + be merged into the result. If it is not directly descended but is + on the same named branch, update aborts with a suggestion to use + merge or update -C instead. + + If the requested revision is on a different named branch and the + working directory is clean, update quietly switches branches. + + See 'hg help dates' for a list of formats valid for --date. """ if rev and node: raise util.Abort(_("please specify just one revision")) diff -r 31a01e3d99cc -r cdc458b12f0f mercurial/merge.py --- a/mercurial/merge.py Mon Mar 24 16:20:15 2008 +0100 +++ b/mercurial/merge.py Mon Mar 24 10:01:05 2008 -0500 @@ -346,7 +346,6 @@ else: raise util.Abort(_("branch %s not found") % wc.branch()) overwrite = force and not branchmerge - forcemerge = force and branchmerge pl = wc.parents() p1, p2 = pl[0], repo.changectx(node) pa = p1.ancestor(p2) @@ -356,22 +355,32 @@ ### check phase if not overwrite and len(pl) > 1: raise util.Abort(_("outstanding uncommitted merges")) - if pa == p1 or pa == p2: # is there a linear path from p1 to p2? - if branchmerge: - if p1.branch() != p2.branch() and pa != p2: + if branchmerge: + if pa == p2: + raise util.Abort(_("can't merge with ancestor")) + elif pa == p1: + if p1.branch() != p2.branch(): fastforward = True else: - raise util.Abort(_("there is nothing to merge, just use " - "'hg update' or look at 'hg heads'")) - elif not (overwrite or branchmerge): - 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(_("nothing to merge (use 'hg update'" + " or check 'hg heads')")) + if not force and (wc.files() or wc.deleted()): raise util.Abort(_("outstanding uncommitted changes")) + elif not overwrite: + if pa == p1 or pa == p2: # linear + pass # all good + elif p1.branch() == p2.branch(): + if wc.files() or wc.deleted(): + raise util.Abort(_("crosses branches (use 'hg merge' or " + "'hg update -C' to discard changes)")) + raise util.Abort(_("crosses branches (use 'hg merge'" + "or 'hg update -C')")) + elif wc.files() or wc.deleted(): + raise util.Abort(_("crosses named branches (use " + "'hg update -C' to discard changes)")) + else: + # Allow jumping branches if there are no changes + overwrite = True ### calculate phase action = [] diff -r 31a01e3d99cc -r cdc458b12f0f tests/test-issue619.out --- a/tests/test-issue619.out Mon Mar 24 16:20:15 2008 +0100 +++ b/tests/test-issue619.out Mon Mar 24 10:01:05 2008 -0500 @@ -6,5 +6,5 @@ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) bogus fast-forward should fail -abort: there is nothing to merge, just use 'hg update' or look at 'hg heads' +abort: can't merge with ancestor done diff -r 31a01e3d99cc -r cdc458b12f0f tests/test-merge5.out --- a/tests/test-merge5.out Mon Mar 24 16:20:15 2008 +0100 +++ b/tests/test-merge5.out Mon Mar 24 10:01:05 2008 -0500 @@ -2,6 +2,6 @@ removing b created new head % should abort -abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes +abort: crosses branches (use 'hg merge' or 'hg update -C' to discard changes) % should succeed -1 files updated, 0 files merged, 0 files removed, 0 files unresolved +abort: crosses branches (use 'hg merge'or 'hg update -C') diff -r 31a01e3d99cc -r cdc458b12f0f tests/test-up-local-change.out --- a/tests/test-up-local-change.out Mon Mar 24 16:20:15 2008 +0100 +++ b/tests/test-up-local-change.out Mon Mar 24 10:01:05 2008 -0500 @@ -103,7 +103,7 @@ date: Mon Jan 12 13:46:40 1970 +0000 summary: 2 -abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes +abort: crosses branches (use 'hg merge' or 'hg update -C' to discard changes) failed abort: outstanding uncommitted changes failed