diff tests/test_single_dir_clone.py @ 500:5ddc212dbc56

push: fix for single directory repository layouts
author Daniel Tang <dytang@cs.purdue.edu>
date Tue, 20 Oct 2009 14:34:00 -0400
parents 1fd3cfa47c5e
children 89eda60c90b3
line wrap: on
line diff
--- a/tests/test_single_dir_clone.py
+++ b/tests/test_single_dir_clone.py
@@ -1,5 +1,11 @@
 import shutil
 
+from mercurial import commands
+from mercurial import context
+from mercurial import hg
+from mercurial import node
+from mercurial import ui
+
 import test_util
 
 
@@ -70,3 +76,78 @@ class TestSingleDir(test_util.TestBase):
         expect = '' # Not honestly sure what this should be...
         test = 4
         self.assertEqual(self.repo[test]['.hgsvnexternals'].data(), expect)
+
+    def test_push_single_dir(self):
+        # Tests simple pushing from default branch to a single dir repo
+        repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
+                                            stupid=False,
+                                            layout='single',
+                                            subdir='')
+        def file_callback(repo, memctx, path):
+            if path == 'adding_file':
+                return context.memfilectx(path=path,
+                                          data='foo',
+                                          islink=False,
+                                          isexec=False,
+                                          copied=False)
+            raise IOError()
+        ctx = context.memctx(repo,
+                             (repo['tip'].node(), node.nullid),
+                             'automated test',
+                             ['adding_file'],
+                             file_callback,
+                             'an_author',
+                             '2009-10-19 18:49:30 -0500',
+                             {'branch': 'default',})
+        repo.commitctx(ctx)
+        hg.update(repo, repo['tip'].node())
+        self.pushrevisions()
+        self.assertTrue('adding_file' in self.svnls(''))
+
+    def test_push_single_dir_branch(self):
+        # Tests local branches pushing to a single dir repo. Creates a fork at
+        # tip. The default branch adds a file called default, while branch foo
+        # adds a file called foo, then tries to push the foo branch and default
+        # branch in that order.
+        repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
+                                            stupid=False,
+                                            layout='single',
+                                            subdir='')
+        def file_callback(data):
+            def cb(repo, memctx, path):
+                if path == data:
+                    return context.memfilectx(path=path,
+                                              data=data,
+                                              islink=False,
+                                              isexec=False,
+                                              copied=False)
+                raise IOError()
+            return cb
+
+        def commit_to_branch(name, parent):
+            repo.commitctx(context.memctx(repo,
+                                          (parent, node.nullid),
+                                          'automated test (%s)' % name,
+                                          [name],
+                                          file_callback(name),
+                                          'an_author',
+                                          '2009-10-19 18:49:30 -0500',
+                                          {'branch': name,}))
+
+        parent = repo['tip'].node()
+        commit_to_branch('default', parent)
+        commit_to_branch('foo', parent)
+        hg.update(repo, repo['foo'].node())
+        self.pushrevisions()
+        repo = self.repo # repo is outdated after the rebase happens, refresh
+        self.assertTrue('foo' in self.svnls(''))
+        self.assertEqual(repo.branchtags().keys(), ['default'])
+        # Have to cross to another branch head, so hg.update doesn't work
+        commands.update(ui.ui(),
+                        self.repo,
+                        self.repo.branchheads('default')[1],
+                        clean=True)
+        self.pushrevisions()
+        self.assertTrue('default' in self.svnls(''))
+        self.assertEquals(len(self.repo.branchheads('default')), 1)
+