# HG changeset patch # User Martin von Zweigbergk # Date 2020-01-31 18:53:50 # Node ID 830eae18b2f3194630fa99780c9451ae01ca1ecc # Parent 6e4ff6a766c2c4b3574a787f7c33ff393a4e7cc7 rebase: abort if the user tries to rebase the working copy I think it's more correct to treat `hg rebase -r 'wdir()' -d foo` as `hg co -m foo`, but I'm instead making it error out. That's partly because it's probably what the user wanted (in the case I heard from a user, they had done `hg rebase -s f` where `f` resolved to `wdir()`) and partly because I don't want to think about more complicated cases where the user specifies the working copy together with other commits. Differential Revision: https://phab.mercurial-scm.org/D8057 diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -37,6 +37,7 @@ from mercurial import ( hg, merge as mergemod, mergeutil, + node as nodemod, obsolete, obsutil, patch, @@ -1265,8 +1266,7 @@ def _definedestmap( if not src: ui.status(_(b'empty "source" revision set - nothing to rebase\n')) return None - rebaseset = repo.revs(b'(%ld)::', src) - assert rebaseset + rebaseset = repo.revs(b'(%ld)::', src) or src else: base = scmutil.revrange(repo, [basef or b'.']) if not base: @@ -1341,6 +1341,8 @@ def _definedestmap( ) return None + if nodemod.wdirrev in rebaseset: + raise error.Abort(_(b'cannot rebase the working copy')) rebasingwcp = repo[b'.'].rev() in rebaseset ui.log( b"rebase", diff --git a/tests/test-rebase-parameters.t b/tests/test-rebase-parameters.t --- a/tests/test-rebase-parameters.t +++ b/tests/test-rebase-parameters.t @@ -93,11 +93,12 @@ These fail: [1] $ hg rebase --rev 'wdir()' --dest 6 - abort: working directory revision cannot be specified + abort: cannot rebase the working copy [255] - $ hg rebase --source 'wdir()' --dest 6 2>&1 | grep assert - assert rebaseset + $ hg rebase --source 'wdir()' --dest 6 + abort: cannot rebase the working copy + [255] $ hg rebase --source '1 & !1' --dest 8 empty "source" revision set - nothing to rebase