diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2750,15 +2750,15 @@ def update(ui, repo, node=None, rev=None 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 and - there is a linear relationship between the current version and the - requested version, the result is the requested version. - - To merge the working directory with another revision, use the - merge command. - - By default, update will refuse to run if doing so would require - discarding local changes. + 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 rev and node: raise util.Abort(_("please specify just one revision")) diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -364,8 +364,11 @@ def update(repo, node, branchmerge, forc 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")) diff --git a/tests/test-merge5 b/tests/test-merge5 --- a/tests/test-merge5 +++ b/tests/test-merge5 @@ -12,9 +12,14 @@ hg commit -m"comment #1" -d "1000000 0" hg update 0 rm b hg commit -A -m"comment #2" -d "1000000 0" +mv a c # in theory, we shouldn't need the "-y" below, but it prevents # this test from hanging when "hg update" erroneously prompts the # user for "keep or delete" +echo % should abort +hg update -y 1 +mv c a +echo % should succeed hg update -y 1 exit 0 diff --git a/tests/test-merge5.out b/tests/test-merge5.out --- a/tests/test-merge5.out +++ b/tests/test-merge5.out @@ -1,4 +1,7 @@ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved removing b created new head +% should abort abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes +% should succeed +1 files updated, 0 files merged, 0 files removed, 0 files unresolved