diff --git a/hgext3rd/tweakdefaults.py b/hgext3rd/tweakdefaults.py --- a/hgext3rd/tweakdefaults.py +++ b/hgext3rd/tweakdefaults.py @@ -204,6 +204,7 @@ # remotenames is loaded, wrap its wrapper directly remotenames = extensions.find('remotenames') wrapfunction(remotenames, 'exbookmarks', unfilteredcmd) + wrapfunction(remotenames, 'expullcmd', pullrebaseffwd) else: # otherwise wrap the bookmarks command wrapcommand(commands.table, 'bookmarks', unfilteredcmd) @@ -318,12 +319,45 @@ # NB: we use rebase and not isrebase on the next line because # remotenames may have already handled the rebase. if dest and rebase: - ret = ret or rebasemodule.rebase(ui, repo, dest=dest, tool=tool) + ret = ret or rebaseorfastforward(rebasemodule.rebase, ui, repo, + dest=dest, tool=tool) if dest and update: ret = ret or commands.update(ui, repo, node=dest, check=True) return ret +def rebaseorfastforward(orig, ui, repo, dest, **args): + """Wrapper for rebasemodule.rebase that fast-forwards the working directory + and any active bookmark to the rebase destination if there is actually + nothing to rebase. + """ + prev = repo['.'] + destrev = scmutil.revsingle(repo, dest) + common = destrev.ancestor(prev) + if prev == common and destrev != prev: + result = hg.update(repo, destrev.node()) + if bmactive(repo): + with repo.wlock(): + bookmarks.update(repo, [prev.node()], destrev.node()) + ui.status(_("nothing to rebase - fast-forwarded to %s\n") % dest) + return result + return orig(ui, repo, dest=dest, **args) + +def pullrebaseffwd(orig, rebasefunc, ui, repo, source="default", **opts): + # The remotenames module also wraps "pull --rebase", and if it is active, it + # is the module that actually performs the rebase. If it is rebasing, we + # need to wrap the rebasemodule.rebase function that it calls to replace it + # with our rebaseorfastforward method. + rebasing = 'rebase' in opts + if rebasing: + rebasemodule = extensions.find('rebase') + if rebasemodule: + wrapfunction(rebasemodule, 'rebase', rebaseorfastforward) + ret = orig(rebasefunc, ui, repo, source, **opts) + if rebasing and rebasemodule: + extensions.unwrapfunction(rebasemodule, 'rebase', rebaseorfastforward) + return ret + def tweakbehaviors(ui): """Tweak Behaviors diff --git a/tests/test-tweakdefaults-pullrebaseffwd.t b/tests/test-tweakdefaults-pullrebaseffwd.t new file mode 100644 --- /dev/null +++ b/tests/test-tweakdefaults-pullrebaseffwd.t @@ -0,0 +1,55 @@ +Set up without remotenames + $ cat >> $HGRCPATH << EOF + > [extensions] + > rebase= + > tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py + > EOF + + $ hg init repo + $ echo a > repo/a + $ hg -R repo commit -qAm a + $ hg clone -q repo clone + $ cd clone + +Pull --rebase with no local changes + $ echo b > ../repo/b + $ hg -R ../repo commit -qAm b + $ hg pull --rebase -d default + pulling from $TESTTMP/repo (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + (run 'hg update' to get a working copy) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + nothing to rebase - fast-forwarded to default + $ hg log -G -T "{rev} {desc}" + @ 1 b + | + o 0 a + +Make a local commit and check pull --rebase still works. + $ echo x > x + $ hg commit -qAm x + $ echo c > ../repo/c + $ hg -R ../repo commit -qAm c + $ hg pull --rebase -d default + pulling from $TESTTMP/repo (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files (+1 heads) + (run 'hg heads' to see heads, 'hg merge' to merge) + rebasing 2:* "x" (glob) + saved backup bundle * (glob) + $ hg log -G -T "{rev} {desc}" + @ 3 x + | + o 2 c + | + o 1 b + | + o 0 a + diff --git a/tests/test-tweakdefaults-pullrebaseremotenames.t b/tests/test-tweakdefaults-pullrebaseremotenames.t new file mode 100644 --- /dev/null +++ b/tests/test-tweakdefaults-pullrebaseremotenames.t @@ -0,0 +1,59 @@ + $ . $TESTDIR/require-ext.sh remotenames + +Set up with remotenames + $ cat >> $HGRCPATH << EOF + > [extensions] + > rebase= + > remotenames= + > tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py + > EOF + + $ hg init repo + $ echo a > repo/a + $ hg -R repo commit -qAm a + $ hg clone -q repo clone + $ cd clone + +Pull --rebase with no local changes + $ hg bookmark localbookmark -t default/default + $ echo b > ../repo/b + $ hg -R ../repo commit -qAm b + $ hg pull --rebase + pulling from $TESTTMP/repo (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + (run 'hg update' to get a working copy) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + nothing to rebase - fast-forwarded to default/default + $ hg log -G -T "{rev} {desc}: {bookmarks}" + @ 1 b: localbookmark + | + o 0 a: + +Make a local commit and check pull --rebase still works. + $ echo x > x + $ hg commit -qAm x + $ echo c > ../repo/c + $ hg -R ../repo commit -qAm c + $ hg pull --rebase + pulling from $TESTTMP/repo (glob) + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files (+1 heads) + (run 'hg heads' to see heads, 'hg merge' to merge) + rebasing 2:* "x" (localbookmark) (glob) + saved backup bundle * (glob) + $ hg log -G -T "{rev} {desc}: {bookmarks}" + @ 3 x: localbookmark + | + o 2 c: + | + o 1 b: + | + o 0 a: +