Merge documentation improvements.
[jelmer/subvertpy.git] / tests / test_branch.py
index 9fa49af54001c969fb1f22cf80456f9e6b6694bd..0bcf25b2e0b36af7309afa8a66d2e2f9c4455c6f 100644 (file)
@@ -19,7 +19,6 @@
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import NoSuchFile
-from bzrlib.inventory import ROOT_ID
 from bzrlib.repository import Repository
 from bzrlib.trace import mutter
 
@@ -28,6 +27,7 @@ from unittest import TestCase
 
 from branch import FakeControlFiles, SvnBranchFormat
 from convert import load_dumpfile
+from fileids import generate_svn_file_id
 from repository import MAPPING_VERSION, generate_svn_revision_id
 from tests import TestCaseWithSubversionRepository
 
@@ -36,7 +36,7 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         repos_url = self.make_client("a", "dc")
         branch = Branch.open(repos_url)
         branch.revision_history()
-        self.assertEqual(None, branch.last_revision())
+        self.assertEqual(branch.generate_revision_id(0), branch.last_revision())
 
     def test_set_parent(self):
         repos_url = self.make_client('a', 'dc')
@@ -47,7 +47,8 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         repos_url = self.make_client('a', 'dc')
         bzrdir = BzrDir.open("svn+"+repos_url)
         branch = bzrdir.open_branch()
-        self.assertEqual(None, branch.last_revision())
+        self.assertEqual(branch.generate_revision_id(0),
+                         branch.last_revision())
 
         self.build_tree({'dc/foo': "data"})
         self.client_add("dc/foo")
@@ -77,7 +78,7 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
     def test_get_root_id_empty(self):
         repos_url = self.make_client('a', 'dc')
         branch = Branch.open("svn+"+repos_url)
-        self.assertEqual(ROOT_ID, branch.get_root_id())
+        self.assertEqual(generate_svn_file_id(branch.repository.uuid, 0, "", ""), branch.get_root_id())
 
     def test_get_root_id_trunk(self):
         repos_url = self.make_client('a', 'dc')
@@ -85,7 +86,7 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         self.client_add("dc/trunk")
         self.client_commit("dc", "msg")
         branch = Branch.open("svn+"+repos_url+"/trunk")
-        self.assertEqual(ROOT_ID, branch.get_root_id())
+        self.assertEqual(generate_svn_file_id(branch.repository.uuid, 1, "trunk", ""), branch.get_root_id())
 
     def test_break_lock(self):
         repos_url = self.make_client('a', 'dc')
@@ -126,7 +127,7 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         repos_url = self.make_client('a', 'dc')
 
         branch = Branch.open("svn+"+repos_url)
-        self.assertEqual([], branch.revision_history())
+        self.assertEqual([branch.generate_revision_id(0)], branch.revision_history())
 
         self.build_tree({'dc/foo': "data"})
         self.client_add("dc/foo")
@@ -135,7 +136,8 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         branch = Branch.open("svn+"+repos_url)
         repos = Repository.open("svn+"+repos_url)
 
-        self.assertEqual([repos.generate_revision_id(1, "")], 
+        self.assertEqual([repos.generate_revision_id(0, ""), 
+                    repos.generate_revision_id(1, "")], 
                 branch.revision_history())
 
         self.build_tree({'dc/foo': "data34"})
@@ -145,6 +147,7 @@ class WorkingSubversionBranch(TestCaseWithSubversionRepository):
         repos = Repository.open("svn+"+repos_url)
 
         self.assertEqual([
+            repos.generate_revision_id(0, ""),
             repos.generate_revision_id(1, ""),
             repos.generate_revision_id(2, "")],
             branch.revision_history())
@@ -481,7 +484,7 @@ foohosts""")
     def test_generate_revision_id(self):
         self.make_client('d', 'dc')
         branch = Branch.open('d')
-        self.assertEqual("svn-v%d:1@%s-" % (MAPPING_VERSION, branch.repository.uuid),  branch.generate_revision_id(1))
+        self.assertEqual("svn-v%d-undefined:%s::1" % (MAPPING_VERSION, branch.repository.uuid),  branch.generate_revision_id(1))
 
     def test_create_checkout(self):
         repos_url = self.make_client('d', 'dc')
@@ -493,7 +496,7 @@ foohosts""")
         url = "svn+"+repos_url+"/trunk"
         oldbranch = Branch.open(url)
 
-        newtree = oldbranch.create_checkout("e")
+        newtree = self.create_checkout(oldbranch, "e")
         self.assertTrue(newtree.branch.repository.has_revision(
            oldbranch.generate_revision_id(1)))
 
@@ -511,7 +514,7 @@ foohosts""")
         url = "svn+"+repos_url+"/trunk"
         oldbranch = Branch.open(url)
 
-        newtree = oldbranch.create_checkout("e", lightweight=True)
+        newtree = self.create_checkout(oldbranch, "e", lightweight=True)
         self.assertEqual(oldbranch.generate_revision_id(1), newtree.base_revid)
         self.assertTrue(os.path.exists("e/.svn"))
         self.assertFalse(os.path.exists("e/.bzr"))
@@ -530,7 +533,7 @@ foohosts""")
         url = "svn+"+repos_url+"/trunk"
         oldbranch = Branch.open(url)
 
-        newtree = oldbranch.create_checkout("e", revision_id=
+        newtree = self.create_checkout(oldbranch, "e", revision_id=
            oldbranch.generate_revision_id(1), lightweight=True)
         self.assertEqual(oldbranch.generate_revision_id(1),
            newtree.base_revid)
@@ -544,7 +547,7 @@ foohosts""")
         self.client_add("sc/foo")
         self.client_commit("sc", "foo")
 
-        olddir = BzrDir.open("sc")
+        olddir = self.open_checkout_bzrdir("sc")
 
         os.mkdir("dc")
         
@@ -554,6 +557,50 @@ foohosts""")
                 olddir.open_branch().last_revision(),
                 newdir.open_branch().last_revision())
 
+    def test_fetch_dir_upgrade(self):
+        repos_url = self.make_client('d', 'sc')
+
+        self.build_tree({'sc/trunk/mylib/bla': "data", "sc/branches": None})
+        self.client_add("sc/trunk")
+        self.client_add("sc/branches")
+        self.client_commit("sc", "foo")
+
+        self.client_copy("sc/trunk/mylib", "sc/branches/abranch")
+        self.client_commit("sc", "Promote mylib")
+
+        olddir = self.open_checkout_bzrdir("sc/branches/abranch")
+
+        os.mkdir("dc")
+        
+        newdir = olddir.sprout('dc')
+
+        self.assertEqual(
+                olddir.open_branch().last_revision(),
+                newdir.open_branch().last_revision())
+
+    def test_fetch_branch_downgrade(self):
+        repos_url = self.make_client('d', 'sc')
+
+        self.build_tree({'sc/trunk': None, "sc/branches/abranch/bla": 'foo'})
+        self.client_add("sc/trunk")
+        self.client_add("sc/branches")
+        self.client_commit("sc", "foo")
+
+        self.client_copy("sc/branches/abranch", "sc/trunk/mylib")
+        self.client_commit("sc", "Demote mylib")
+
+        olddir = self.open_checkout_bzrdir("sc/trunk")
+
+        os.mkdir("dc")
+        
+        newdir = olddir.sprout('dc')
+
+        self.assertEqual(
+                olddir.open_branch().last_revision(),
+                newdir.open_branch().last_revision())
+
+
+
     def test_ghost_workingtree(self):
         # Looks like bazaar has trouble creating a working tree of a 
         # revision that has ghost parents
@@ -564,7 +611,7 @@ foohosts""")
         self.client_set_prop("sc", "bzr:merge", "some-ghost\n")
         self.client_commit("sc", "foo")
 
-        olddir = BzrDir.open("sc")
+        olddir = self.open_checkout_bzrdir("sc")
 
         os.mkdir("dc")