mercurial/hg.py
changeset 190 3dd5ce2fddb6
parent 187 aa9a0d50e612
child 191 d7e859cf2f1b
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -525,15 +525,21 @@ class localrepository:
         return nl
 
     def getchangegroup(self, remote):
-        tip = remote.branches([])[0]
-        self.ui.debug("remote tip branch is %s:%s\n" %
-                      (short(tip[0]), short(tip[1])))
         m = self.changelog.nodemap
-        unknown = [tip]
         search = []
         fetch = []
         seen = {}
         seenbranch = {}
+        tip = remote.branches([])[0]
+        self.ui.debug("remote tip branch is %s:%s\n" %
+                      (short(tip[0]), short(tip[1])))
+
+        # if we have an empty repo, fetch everything
+        if self.changelog.tip() == nullid:
+            return remote.changegroup([nullid])
+
+        # otherwise, assume we're closer to the tip than the root
+        unknown = [tip]
 
         if tip[0] in m:
             self.ui.note("nothing to do!\n")