1 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from bzrlib.branch import Branch
20 from bzrlib.bzrdir import BzrDir
21 from bzrlib.errors import NoSuchFile
22 from bzrlib.inventory import ROOT_ID
23 from bzrlib.repository import Repository
24 from bzrlib.trace import mutter
27 from unittest import TestCase
29 from branch import FakeControlFiles, SvnBranchFormat
30 from convert import load_dumpfile
31 from repository import MAPPING_VERSION, generate_svn_revision_id
32 from tests import TestCaseWithSubversionRepository
34 class WorkingSubversionBranch(TestCaseWithSubversionRepository):
35 def test_last_rev_rev_hist(self):
36 repos_url = self.make_client("a", "dc")
37 branch = Branch.open(repos_url)
38 branch.revision_history()
39 self.assertEqual(None, branch.last_revision())
41 def test_set_parent(self):
42 repos_url = self.make_client('a', 'dc')
43 branch = Branch.open(repos_url)
44 branch.set_parent("foobar")
46 def test_num_revnums(self):
47 repos_url = self.make_client('a', 'dc')
48 bzrdir = BzrDir.open("svn+"+repos_url)
49 branch = bzrdir.open_branch()
50 self.assertEqual(None, branch.last_revision())
52 self.build_tree({'dc/foo': "data"})
53 self.client_add("dc/foo")
54 self.client_commit("dc", "My Message")
56 bzrdir = BzrDir.open("svn+"+repos_url)
57 branch = bzrdir.open_branch()
58 repos = bzrdir.find_repository()
60 self.assertEqual(repos.generate_revision_id(1, ""),
61 branch.last_revision())
63 self.build_tree({'dc/foo': "data2"})
64 self.client_commit("dc", "My Message")
66 branch = Branch.open("svn+"+repos_url)
67 repos = Repository.open("svn+"+repos_url)
69 self.assertEqual(repos.generate_revision_id(2, ""),
70 branch.last_revision())
72 def test_set_revision_history(self):
73 repos_url = self.make_client('a', 'dc')
74 branch = Branch.open("svn+"+repos_url)
75 self.assertRaises(NotImplementedError, branch.set_revision_history, [])
77 def test_get_root_id_empty(self):
78 repos_url = self.make_client('a', 'dc')
79 branch = Branch.open("svn+"+repos_url)
80 self.assertEqual(ROOT_ID, branch.get_root_id())
82 def test_get_root_id_trunk(self):
83 repos_url = self.make_client('a', 'dc')
84 self.build_tree({'dc/trunk': None})
85 self.client_add("dc/trunk")
86 self.client_commit("dc", "msg")
87 branch = Branch.open("svn+"+repos_url+"/trunk")
88 self.assertEqual(ROOT_ID, branch.get_root_id())
90 def test_break_lock(self):
91 repos_url = self.make_client('a', 'dc')
92 branch = Branch.open("svn+"+repos_url)
93 branch.control_files.break_lock()
96 repos_url = self.make_client('a', 'dc')
97 branch = Branch.open("svn+"+repos_url)
98 self.assertEqual("SvnBranch('svn+%s')" % repos_url, branch.__repr__())
100 def test_get_physical_lock_status(self):
101 repos_url = self.make_client('a', 'dc')
102 branch = Branch.open("svn+"+repos_url)
103 self.assertFalse(branch.get_physical_lock_status())
105 def test_set_push_location(self):
106 repos_url = self.make_client('a', 'dc')
107 branch = Branch.open("svn+"+repos_url)
108 self.assertRaises(NotImplementedError, branch.set_push_location, [])
110 def test_get_parent(self):
111 repos_url = self.make_client('a', 'dc')
112 branch = Branch.open("svn+"+repos_url)
113 self.assertEqual("svn+"+repos_url, branch.get_parent())
115 def test_append_revision(self):
116 repos_url = self.make_client('a', 'dc')
117 branch = Branch.open("svn+"+repos_url)
118 branch.append_revision([])
120 def test_get_push_location(self):
121 repos_url = self.make_client('a', 'dc')
122 branch = Branch.open("svn+"+repos_url)
123 self.assertIs(None, branch.get_push_location())
125 def test_revision_history(self):
126 repos_url = self.make_client('a', 'dc')
128 branch = Branch.open("svn+"+repos_url)
129 self.assertEqual([], branch.revision_history())
131 self.build_tree({'dc/foo': "data"})
132 self.client_add("dc/foo")
133 self.client_commit("dc", "My Message")
135 branch = Branch.open("svn+"+repos_url)
136 repos = Repository.open("svn+"+repos_url)
138 self.assertEqual([repos.generate_revision_id(1, "")],
139 branch.revision_history())
141 self.build_tree({'dc/foo': "data34"})
142 self.client_commit("dc", "My Message")
144 branch = Branch.open("svn+"+repos_url)
145 repos = Repository.open("svn+"+repos_url)
148 repos.generate_revision_id(1, ""),
149 repos.generate_revision_id(2, "")],
150 branch.revision_history())
152 def test_get_nick_none(self):
153 repos_url = self.make_client('a', 'dc')
155 self.build_tree({'dc/foo': "data"})
156 self.client_add("dc/foo")
157 self.client_commit("dc", "My Message")
159 branch = Branch.open("svn+"+repos_url)
161 self.assertIs(None, branch.nick)
163 def test_get_nick_path(self):
164 repos_url = self.make_client('a', 'dc')
166 self.build_tree({'dc/trunk': "data"})
167 self.client_add("dc/trunk")
168 self.client_commit("dc", "My Message")
170 branch = Branch.open("svn+"+repos_url+"/trunk")
172 self.assertEqual("trunk", branch.nick)
174 def test_get_revprops(self):
175 repos_url = self.make_client('a', 'dc')
177 self.build_tree({'dc/foo': "data"})
178 self.client_add("dc/foo")
179 self.client_set_prop("dc", "bzr:revprop:branch-nick", "mybranch")
180 self.client_commit("dc", "My Message")
182 branch = Branch.open("svn+"+repos_url)
184 rev = branch.repository.get_revision(branch.last_revision())
186 self.assertEqual("mybranch", rev.properties["branch-nick"])
188 def test_fetch_replace(self):
189 filename = os.path.join(self.test_dir, "dumpfile")
190 open(filename, 'w').write("""SVN-fs-dump-format-version: 2
192 UUID: 6f95bc5c-e18d-4021-aca8-49ed51dbcb75
195 Prop-content-length: 56
201 2006-07-30T12:41:25.270824Z
205 Prop-content-length: 94
219 2006-07-30T12:41:26.117512Z
225 Prop-content-length: 10
231 Node-path: trunk/hosts
234 Prop-content-length: 10
235 Text-content-length: 4
236 Text-content-md5: 771ec3328c29d17af5aacf7f895dd885
243 Prop-content-length: 94
257 2006-07-30T12:41:27.130044Z
260 Node-path: trunk/hosts
263 Text-content-length: 4
264 Text-content-md5: 6c2479dbb342b8df96d84db7ab92c412
270 Prop-content-length: 94
284 2006-07-30T12:41:28.114350Z
287 Node-path: trunk/hosts
290 Text-content-length: 4
291 Text-content-md5: 368cb8d3db6186e2e83d9434f165c525
297 Prop-content-length: 94
311 2006-07-30T12:41:29.129563Z
317 Prop-content-length: 10
324 Prop-content-length: 94
338 2006-07-30T12:41:31.130508Z
341 Node-path: branches/foobranch
345 Node-copyfrom-path: trunk
349 Prop-content-length: 94
363 2006-07-30T12:41:33.129149Z
366 Node-path: branches/foobranch/hosts
370 Node-path: branches/foobranch/hosts
374 Node-copyfrom-path: trunk/hosts
380 Prop-content-length: 94
394 2006-07-30T12:41:34.136423Z
397 Node-path: branches/foobranch/hosts
400 Text-content-length: 8
401 Text-content-md5: 0e328d3517a333a4879ebf3d88fd82bb
408 load_dumpfile("dumpfile", "old")
410 url = "old/branches/foobranch"
411 mutter('open %r' % url)
412 olddir = BzrDir.open(url)
414 newdir = olddir.sprout("new")
416 newbranch = newdir.open_branch()
418 uuid = "6f95bc5c-e18d-4021-aca8-49ed51dbcb75"
419 tree = newbranch.repository.revision_tree(
420 generate_svn_revision_id(uuid, 7, "branches/foobranch"))
422 weave = tree.get_weave(tree.inventory.path2id("hosts"))
424 generate_svn_revision_id(uuid, 6, "branches/foobranch"),
425 generate_svn_revision_id(uuid, 7, "branches/foobranch")],
429 def test_fetch_odd(self):
430 repos_url = self.make_client('d', 'dc')
432 self.build_tree({'dc/trunk': None,
433 'dc/trunk/hosts': 'hej1'})
434 self.client_add("dc/trunk")
435 self.client_commit("dc", "created trunk and added hosts") #1
437 self.build_tree({'dc/trunk/hosts': 'hej2'})
438 self.client_commit("dc", "rev 2") #2
440 self.build_tree({'dc/trunk/hosts': 'hej3'})
441 self.client_commit("dc", "rev 3") #3
443 self.build_tree({'dc/branches': None})
444 self.client_add("dc/branches")
445 self.client_commit("dc", "added branches") #4
447 self.client_copy("dc/trunk", "dc/branches/foobranch")
448 self.client_commit("dc", "added branch foobranch") #5
450 self.build_tree({'dc/branches/foobranch/hosts': 'foohosts'})
451 self.client_commit("dc", "foohosts") #6
455 url = "svn+"+repos_url+"/branches/foobranch"
456 mutter('open %r' % url)
457 olddir = BzrDir.open(url)
459 newdir = olddir.sprout("new")
461 newbranch = newdir.open_branch()
463 uuid = olddir.find_repository().uuid
464 tree = newbranch.repository.revision_tree(
465 generate_svn_revision_id(uuid, 6, "branches/foobranch"))
467 weave = tree.get_weave(tree.inventory.path2id("hosts"))
469 generate_svn_revision_id(uuid, 1, "trunk"),
470 generate_svn_revision_id(uuid, 2, "trunk"),
471 generate_svn_revision_id(uuid, 3, "trunk"),
472 generate_svn_revision_id(uuid, 6, "branches/foobranch")],
475 def test_check(self):
476 self.make_client('d', 'dc')
477 branch = Branch.open('d')
478 result = branch.check()
479 self.assertEqual(branch, result.branch)
481 def test_generate_revision_id(self):
482 self.make_client('d', 'dc')
483 branch = Branch.open('d')
484 self.assertEqual("svn-v%d:1@%s-" % (MAPPING_VERSION, branch.repository.uuid), branch.generate_revision_id(1))
486 def test_create_checkout(self):
487 repos_url = self.make_client('d', 'dc')
489 self.build_tree({'dc/trunk': None, 'dc/trunk/hosts': 'hej1'})
490 self.client_add("dc/trunk")
491 self.client_commit("dc", "created trunk and added hosts") #1
493 url = "svn+"+repos_url+"/trunk"
494 oldbranch = Branch.open(url)
496 newtree = oldbranch.create_checkout("e")
497 self.assertTrue(newtree.branch.repository.has_revision(
498 oldbranch.generate_revision_id(1)))
500 self.assertTrue(os.path.exists("e/.bzr"))
501 self.assertFalse(os.path.exists("e/.svn"))
503 def test_create_checkout_lightweight(self):
504 repos_url = self.make_client('d', 'dc')
506 self.build_tree({'dc/trunk': None,
507 'dc/trunk/hosts': 'hej1'})
508 self.client_add("dc/trunk")
509 self.client_commit("dc", "created trunk and added hosts") #1
511 url = "svn+"+repos_url+"/trunk"
512 oldbranch = Branch.open(url)
514 newtree = oldbranch.create_checkout("e", lightweight=True)
515 self.assertEqual(oldbranch.generate_revision_id(1), newtree.base_revid)
516 self.assertTrue(os.path.exists("e/.svn"))
517 self.assertFalse(os.path.exists("e/.bzr"))
519 def test_create_checkout_lightweight_stop_rev(self):
520 repos_url = self.make_client('d', 'dc')
522 self.build_tree({'dc/trunk': None,
523 'dc/trunk/hosts': 'hej1'})
524 self.client_add("dc/trunk")
525 self.client_commit("dc", "created trunk and added hosts") #1
527 self.build_tree({'dc/trunk/hosts': 'bloe'})
528 self.client_commit("dc", "added another revision")
530 url = "svn+"+repos_url+"/trunk"
531 oldbranch = Branch.open(url)
533 newtree = oldbranch.create_checkout("e", revision_id=
534 oldbranch.generate_revision_id(1), lightweight=True)
535 self.assertEqual(oldbranch.generate_revision_id(1),
537 self.assertTrue(os.path.exists("e/.svn"))
538 self.assertFalse(os.path.exists("e/.bzr"))
540 def test_fetch_branch(self):
541 self.make_client('d', 'sc')
543 self.build_tree({'sc/foo/bla': "data"})
544 self.client_add("sc/foo")
545 self.client_commit("sc", "foo")
547 olddir = BzrDir.open("sc")
551 newdir = olddir.sprout('dc')
554 olddir.open_branch().last_revision(),
555 newdir.open_branch().last_revision())
557 def test_ghost_workingtree(self):
558 # Looks like bazaar has trouble creating a working tree of a
559 # revision that has ghost parents
560 self.make_client('d', 'sc')
562 self.build_tree({'sc/foo/bla': "data"})
563 self.client_add("sc/foo")
564 self.client_set_prop("sc", "bzr:merge", "some-ghost\n")
565 self.client_commit("sc", "foo")
567 olddir = BzrDir.open("sc")
571 newdir = olddir.sprout('dc')
572 newdir.find_repository().get_revision(
573 newdir.open_branch().last_revision())
574 newdir.find_repository().get_revision_inventory(
575 newdir.open_branch().last_revision())
577 class TestFakeControlFiles(TestCase):
578 def test_get_utf8(self):
579 f = FakeControlFiles()
580 self.assertRaises(NoSuchFile, f.get_utf8, "foo")
584 f = FakeControlFiles()
585 self.assertRaises(NoSuchFile, f.get, "foobla")
587 class BranchFormatTests(TestCase):
589 self.format = SvnBranchFormat()
591 def test_initialize(self):
592 self.assertRaises(NotImplementedError, self.format.initialize, None)
594 def test_get_format_string(self):
595 self.assertEqual("Subversion Smart Server",
596 self.format.get_format_string())
598 def test_get_format_description(self):
599 self.assertEqual("Subversion Smart Server",
600 self.format.get_format_description())