changeset 4912:c4dd58af0fc8

issue 622: pull/unbundle -u updates to default branch if repo was empty
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 16 Jul 2007 18:01:20 -0700
parents fc502517d68d
children f0c25ed40ec6
files mercurial/commands.py tests/test-pull tests/test-pull.out
diffstat 3 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2013,11 +2013,13 @@ def paths(ui, repo, search=None):
         for name, path in ui.configitems("paths"):
             ui.write("%s = %s\n" % (name, path))
 
-def postincoming(ui, repo, modheads, optupdate):
+def postincoming(ui, repo, modheads, optupdate, wasempty):
     if modheads == 0:
         return
     if optupdate:
-        if modheads == 1:
+        if wasempty:
+            return hg.update(repo, repo.lookup('default'))
+        elif modheads == 1:
             return hg.update(repo, repo.changelog.tip()) # update
         else:
             ui.status(_("not updating, since new heads added\n"))
@@ -2079,8 +2081,9 @@ def pull(ui, repo, source="default", **o
             error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
             raise util.Abort(error)
 
+    wasempty = repo.changelog.count() == 0
     modheads = repo.pull(other, heads=revs, force=opts['force'])
-    return postincoming(ui, repo, modheads, opts['update'])
+    return postincoming(ui, repo, modheads, opts['update'], wasempty)
 
 def push(ui, repo, dest=None, **opts):
     """push changes to the specified destination
@@ -2644,6 +2647,7 @@ def unbundle(ui, repo, fname1, *fnames, 
     """
     fnames = (fname1,) + fnames
     result = None
+    wasempty = repo.changelog.count() == 0
     for fname in fnames:
         if os.path.exists(fname):
             f = open(fname, "rb")
@@ -2652,7 +2656,7 @@ def unbundle(ui, repo, fname1, *fnames, 
         gen = changegroup.readbundle(f, fname)
         modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
 
-    return postincoming(ui, repo, modheads, opts['update'])
+    return postincoming(ui, repo, modheads, opts['update'], wasempty)
 
 def update(ui, repo, node=None, rev=None, clean=False, date=None):
     """update working directory
--- a/tests/test-pull
+++ b/tests/test-pull
@@ -18,3 +18,9 @@ hg co
 cat foo
 hg manifest --debug
 hg pull
+
+echo % issue 622
+cd ..
+hg init empty
+cd empty
+hg pull -u ../test
--- a/tests/test-pull.out
+++ b/tests/test-pull.out
@@ -21,3 +21,11 @@ 2ed2a3912a0b24502043eae84ee4b279c18b90dd
 pulling from http://localhost:20059/
 searching for changes
 no changes found
+% issue 622
+pulling from ../test
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 1 changes to 1 files
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved