1 # Copyright (C) 2006 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
17 from bzrlib.branch import Branch
18 from bzrlib.bzrdir import BzrDir, BzrDirTestProviderAdapter, BzrDirFormat
19 from bzrlib.errors import NoSuchFile
20 from bzrlib.repository import Repository
21 from bzrlib.trace import mutter
24 from unittest import TestCase
26 import svn.core, svn.client
28 from branch import FakeControlFiles
29 from convert import load_dumpfile
31 from repository import MAPPING_VERSION
32 from tests import TestCaseWithSubversionRepository
34 class WorkingSubversionBranch(TestCaseWithSubversionRepository):
35 def test_num_revnums(self):
36 repos_url = self.make_client('a', 'dc')
37 bzrdir = BzrDir.open("svn+"+repos_url)
38 branch = bzrdir.open_branch()
39 self.assertEqual(None, branch.last_revision())
41 self.build_tree({'dc/foo': "data"})
42 self.client_add("dc/foo")
43 self.client_commit("dc", "My Message")
45 bzrdir = BzrDir.open("svn+"+repos_url)
46 branch = bzrdir.open_branch()
47 repos = bzrdir.open_repository()
49 self.assertEqual("svn-v%d:1@%s-" % (MAPPING_VERSION, repos.uuid),
50 branch.last_revision())
52 self.build_tree({'dc/foo': "data2"})
53 self.client_commit("dc", "My Message")
55 branch = Branch.open("svn+"+repos_url)
56 repos = Repository.open("svn+"+repos_url)
58 self.assertEqual("svn-v%d:2@%s-" % (MAPPING_VERSION, repos.uuid),
59 branch.last_revision())
61 def test_set_revision_history(self):
62 repos_url = self.make_client('a', 'dc')
63 branch = Branch.open("svn+"+repos_url)
64 self.assertRaises(NotImplementedError, branch.set_revision_history, [])
66 def test_set_push_location(self):
67 repos_url = self.make_client('a', 'dc')
68 branch = Branch.open("svn+"+repos_url)
69 self.assertRaises(NotImplementedError, branch.set_push_location, [])
71 def test_get_parent(self):
72 repos_url = self.make_client('a', 'dc')
73 branch = Branch.open("svn+"+repos_url)
74 self.assertEqual("svn+"+repos_url, branch.get_parent())
76 def test_append_revision(self):
77 repos_url = self.make_client('a', 'dc')
78 branch = Branch.open("svn+"+repos_url)
79 branch.append_revision([])
81 def test_get_push_location(self):
82 repos_url = self.make_client('a', 'dc')
83 branch = Branch.open("svn+"+repos_url)
84 self.assertIs(None, branch.get_push_location())
86 def test_revision_history(self):
87 repos_url = self.make_client('a', 'dc')
89 branch = Branch.open("svn+"+repos_url)
90 self.assertEqual([], branch.revision_history())
92 self.build_tree({'dc/foo': "data"})
93 self.client_add("dc/foo")
94 self.client_commit("dc", "My Message")
96 branch = Branch.open("svn+"+repos_url)
97 repos = Repository.open("svn+"+repos_url)
99 self.assertEqual(["svn-v%d:1@%s-" % (MAPPING_VERSION, repos.uuid)],
100 branch.revision_history())
102 self.build_tree({'dc/foo': "data34"})
103 self.client_commit("dc", "My Message")
105 branch = Branch.open("svn+"+repos_url)
106 repos = Repository.open("svn+"+repos_url)
109 "svn-v%d:1@%s-" % (MAPPING_VERSION, repos.uuid),
110 "svn-v%d:2@%s-" % (MAPPING_VERSION, repos.uuid)],
111 branch.revision_history())
113 def test_get_nick_none(self):
114 repos_url = self.make_client('a', 'dc')
116 self.build_tree({'dc/foo': "data"})
117 self.client_add("dc/foo")
118 self.client_commit("dc", "My Message")
120 branch = Branch.open("svn+"+repos_url)
122 self.assertIs(None, branch.nick)
124 def test_get_revprops(self):
125 repos_url = self.make_client('a', 'dc')
127 self.build_tree({'dc/foo': "data"})
128 self.client_add("dc/foo")
129 self.client_set_prop("dc", "bzr:revprop:branch-nick", "mybranch")
130 self.client_commit("dc", "My Message")
132 branch = Branch.open("svn+"+repos_url)
134 rev = branch.repository.get_revision(branch.last_revision())
136 self.assertEqual("mybranch", rev.properties["branch-nick"])
138 def test_fetch_replace(self):
139 filename = os.path.join(self.test_dir, "dumpfile")
140 open(filename, 'w').write("""SVN-fs-dump-format-version: 2
142 UUID: 6f95bc5c-e18d-4021-aca8-49ed51dbcb75
145 Prop-content-length: 56
151 2006-07-30T12:41:25.270824Z
155 Prop-content-length: 94
169 2006-07-30T12:41:26.117512Z
175 Prop-content-length: 10
181 Node-path: trunk/hosts
184 Prop-content-length: 10
185 Text-content-length: 4
186 Text-content-md5: 771ec3328c29d17af5aacf7f895dd885
193 Prop-content-length: 94
207 2006-07-30T12:41:27.130044Z
210 Node-path: trunk/hosts
213 Text-content-length: 4
214 Text-content-md5: 6c2479dbb342b8df96d84db7ab92c412
220 Prop-content-length: 94
234 2006-07-30T12:41:28.114350Z
237 Node-path: trunk/hosts
240 Text-content-length: 4
241 Text-content-md5: 368cb8d3db6186e2e83d9434f165c525
247 Prop-content-length: 94
261 2006-07-30T12:41:29.129563Z
267 Prop-content-length: 10
274 Prop-content-length: 94
288 2006-07-30T12:41:31.130508Z
291 Node-path: branches/foobranch
295 Node-copyfrom-path: trunk
299 Prop-content-length: 94
313 2006-07-30T12:41:33.129149Z
316 Node-path: branches/foobranch/hosts
320 Node-path: branches/foobranch/hosts
324 Node-copyfrom-path: trunk/hosts
330 Prop-content-length: 94
344 2006-07-30T12:41:34.136423Z
347 Node-path: branches/foobranch/hosts
350 Text-content-length: 8
351 Text-content-md5: 0e328d3517a333a4879ebf3d88fd82bb
358 load_dumpfile("dumpfile", "old")
360 url = "old/branches/foobranch"
361 mutter('open %r' % url)
362 olddir = BzrDir.open(url)
364 newdir = olddir.sprout("new")
366 newbranch = newdir.open_branch()
368 uuid = "6f95bc5c-e18d-4021-aca8-49ed51dbcb75"
369 tree = newbranch.repository.revision_tree(
370 "svn-v%d:7@%s-branches%%2ffoobranch" % (MAPPING_VERSION, uuid))
372 weave = tree.get_weave(tree.inventory.path2id("hosts"))
374 'svn-v%d:6@%s-branches%%2ffoobranch' % (MAPPING_VERSION, uuid),
375 'svn-v%d:7@%s-branches%%2ffoobranch' % (MAPPING_VERSION, uuid)],
379 def test_fetch_odd(self):
380 repos_url = self.make_client('d', 'dc')
382 self.build_tree({'dc/trunk': None,
383 'dc/trunk/hosts': 'hej1'})
384 self.client_add("dc/trunk")
385 self.client_commit("dc", "created trunk and added hosts") #1
387 self.build_tree({'dc/trunk/hosts': 'hej2'})
388 self.client_commit("dc", "rev 2") #2
390 self.build_tree({'dc/trunk/hosts': 'hej3'})
391 self.client_commit("dc", "rev 3") #3
393 self.build_tree({'dc/branches': None})
394 self.client_add("dc/branches")
395 self.client_commit("dc", "added branches") #4
397 self.client_copy("dc/trunk", "dc/branches/foobranch")
398 self.client_commit("dc", "added branch foobranch") #5
400 self.build_tree({'dc/branches/foobranch/hosts': 'foohosts'})
401 self.client_commit("dc", "foohosts") #6
405 url = "svn+"+repos_url+"/branches/foobranch"
406 mutter('open %r' % url)
407 olddir = BzrDir.open(url)
409 newdir = olddir.sprout("new")
411 newbranch = newdir.open_branch()
413 uuid = olddir.open_repository().uuid
414 tree = newbranch.repository.revision_tree(
415 "svn-v%d:6@%s-branches%%2ffoobranch" % (MAPPING_VERSION, uuid))
417 weave = tree.get_weave(tree.inventory.path2id("hosts"))
419 'svn-v%d:1@%s-trunk' % (MAPPING_VERSION, uuid),
420 'svn-v%d:2@%s-trunk' % (MAPPING_VERSION, uuid),
421 'svn-v%d:3@%s-trunk' % (MAPPING_VERSION, uuid),
422 'svn-v%d:6@%s-branches%%2ffoobranch' % (MAPPING_VERSION, uuid)],
425 def test_check(self):
426 repos_url = self.make_client('d', 'dc')
427 branch = Branch.open('d')
428 result = branch.check()
429 self.assertEqual(branch, result.branch)
431 def test_create_checkout(self):
432 repos_url = self.make_client('d', 'dc')
434 self.build_tree({'dc/trunk': None,
435 'dc/trunk/hosts': 'hej1'})
436 self.client_add("dc/trunk")
437 self.client_commit("dc", "created trunk and added hosts") #1
439 url = "svn+"+repos_url+"/trunk"
440 oldbranch = Branch.open(url)
442 newtree = oldbranch.create_checkout("e")
444 newtree.branch.repository.has_revision(
445 'svn-v%d:1@%s-trunk' % (MAPPING_VERSION, oldbranch.repository.uuid)))
447 self.assertTrue(os.path.exists("e/.bzr"))
448 self.assertFalse(os.path.exists("e/.svn"))
450 def test_create_checkout_lightweight(self):
451 repos_url = self.make_client('d', 'dc')
453 self.build_tree({'dc/trunk': None,
454 'dc/trunk/hosts': 'hej1'})
455 self.client_add("dc/trunk")
456 self.client_commit("dc", "created trunk and added hosts") #1
458 url = "svn+"+repos_url+"/trunk"
459 oldbranch = Branch.open(url)
461 newtree = oldbranch.create_checkout("e", lightweight=True)
463 newtree.branch.repository.has_revision(
464 'svn-v%d:1@%s-trunk' % (MAPPING_VERSION, oldbranch.repository.uuid)))
465 self.assertTrue(os.path.exists("e/.svn"))
466 self.assertFalse(os.path.exists("e/.bzr"))
468 def test_fetch_branch(self):
469 repos_url = self.make_client('d', 'sc')
471 self.build_tree({'sc/foo/bla': "data"})
472 self.client_add("sc/foo")
473 self.client_commit("sc", "foo")
475 olddir = BzrDir.open("sc")
479 newdir = olddir.sprout('dc')
482 olddir.open_branch().last_revision(),
483 newdir.open_branch().last_revision())
485 def test_ghost_workingtree(self):
486 # Looks like bazaar has trouble creating a working tree of a
487 # revision that has ghost parents
488 repos_url = self.make_client('d', 'sc')
490 self.build_tree({'sc/foo/bla': "data"})
491 self.client_add("sc/foo")
492 self.client_set_prop("sc", "bzr:merge", "some-ghost\n")
493 self.client_commit("sc", "foo")
495 olddir = BzrDir.open("sc")
499 newdir = olddir.sprout('dc')
500 newdir.open_repository().get_revision(
501 newdir.open_branch().last_revision())
502 newdir.open_repository().get_revision_inventory(
503 newdir.open_branch().last_revision())
505 class TestFakeControlFiles(TestCase):
506 def test_get_utf8(self):
507 f = FakeControlFiles()
508 self.assertRaises(NoSuchFile, f.get_utf8, "foo")
512 f = FakeControlFiles()
513 self.assertRaises(NoSuchFile, f.get, "foobla")