[PATCH] clone: update to branch of parent for local source repos by default

Adrian Buehlmann adrian at cadifra.com
Mon Oct 19 16:53:44 CDT 2009


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1255989153 -7200
# Node ID 56363f62752ecb33134c7272acb7dedd34debc9c
# Parent  6578bc930174a1d312f4198d36bd43ebcd24cfc2
clone: update to branch of parent for local source repos by default

(I'm sending this mostly for historic/documentation purposes as Matt has
mixed feelings about it. It's just amazing how small and effective this
patch actually is)

would allow to do things like

$ hg clone thg-stable thg-stable-bug1234
updating to branch stable
297 files updated, 0 files merged, 0 files removed, 0 files unresolved

provided thg-stable's parent is at branch 'stable'.

Today, the same can only be achieved by doing

hg clone -U thg-stable thg-stable-bug1234
cd thg-stable-bug1234
hg up stable

which needs a lot of foresight (the argument being that the source
repo's parent branch being probably a more sensible default than
just the default branch).

-r/--rev or 'clone url#branch' can't be used as both imply --pull, which voids
fast local hardlink cloning.

The argument against doing this patch probably is that this would be the
first time that clone would be influenced by the state of the source _working
directory_ ("layering violation", as Dirkjan put it).

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -309,6 +309,8 @@ def clone(ui, source, dest=None, pull=Fa
             if update:
                 if update is not True:
                     checkout = update
+                elif src_repo.local() and checkout is None:
+                    checkout = src_repo['.'].branch()
                 for test in (checkout, 'default', 'tip'):
                     if test is None:
                         continue


More information about the Mercurial-devel mailing list