1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from bzrlib.branch import Branch, BranchReferenceFormat
20 from bzrlib.bzrdir import BzrDir, BzrDirFormat
21 from bzrlib.errors import AlreadyBranchError, BzrError, DivergedBranches
22 from bzrlib.inventory import Inventory
23 from bzrlib.merge import Merger, Merge3Merger
24 from bzrlib.osutils import has_symlinks
25 from bzrlib.progress import DummyProgress
26 from bzrlib.repository import Repository
27 from bzrlib.tests import KnownFailure, TestCaseWithTransport
28 from bzrlib.trace import mutter
29 from bzrlib.workingtree import WorkingTree
33 from bzrlib.plugins.svn.errors import ChangesRootLHSHistory, MissingPrefix
34 from time import sleep
35 from commit import push
36 from mapping import SVN_PROP_BZR_REVISION_ID
37 from tests import TestCaseWithSubversionRepository
39 class TestPush(TestCaseWithSubversionRepository):
41 super(TestPush, self).setUp()
42 self.repos_url = self.make_client('d', 'sc')
44 self.build_tree({'sc/foo/bla': "data"})
45 self.client_add("sc/foo")
46 self.client_commit("sc", "foo")
48 self.svndir = BzrDir.open("sc")
50 self.bzrdir = self.svndir.sprout("dc")
53 svnbranch = self.svndir.open_branch()
54 bzrbranch = self.bzrdir.open_branch()
55 result = svnbranch.pull(bzrbranch)
56 self.assertEqual(0, result.new_revno - result.old_revno)
57 self.assertEqual(svnbranch.revision_history(),
58 bzrbranch.revision_history())
61 self.build_tree({'sc/foo/bar': "data"})
62 self.client_add("sc/foo/bar")
63 self.client_commit("sc", "second message")
65 svnbranch = self.svndir.open_branch()
66 bzrbranch = self.bzrdir.open_branch()
67 result = svnbranch.pull(bzrbranch)
68 self.assertEqual(0, result.new_revno - result.old_revno)
70 def test_diverged(self):
71 self.build_tree({'sc/foo/bar': "data"})
72 self.client_add("sc/foo/bar")
73 self.client_commit("sc", "second message")
75 svndir = BzrDir.open("sc")
77 self.build_tree({'dc/file': 'data'})
78 wt = self.bzrdir.open_workingtree()
80 wt.commit(message="Commit from Bzr")
82 self.assertRaises(DivergedBranches,
83 svndir.open_branch().pull,
84 self.bzrdir.open_branch())
86 def test_change(self):
87 self.build_tree({'dc/foo/bla': 'other data'})
88 wt = self.bzrdir.open_workingtree()
89 newid = wt.commit(message="Commit from Bzr")
91 svnbranch = self.svndir.open_branch()
92 svnbranch.pull(self.bzrdir.open_branch())
94 repos = self.svndir._find_repository()
95 mapping = repos.get_mapping()
96 self.assertEquals(newid, svnbranch.last_revision())
97 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
98 self.assertEqual(newid, inv[inv.path2id('foo/bla')].revision)
99 self.assertEqual(wt.branch.last_revision(),
100 repos.generate_revision_id(2, "", mapping))
101 self.assertEqual(repos.generate_revision_id(2, "", mapping),
102 self.svndir.open_branch().last_revision())
103 self.assertEqual("other data",
104 repos.revision_tree(repos.generate_revision_id(2, "",
105 mapping)).get_file_text(inv.path2id("foo/bla")))
107 def test_simple(self):
108 self.build_tree({'dc/file': 'data'})
109 wt = self.bzrdir.open_workingtree()
111 wt.commit(message="Commit from Bzr")
113 self.svndir.open_branch().pull(self.bzrdir.open_branch())
115 repos = self.svndir._find_repository()
116 mapping = repos.get_mapping()
117 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
118 self.assertTrue(inv.has_filename('file'))
119 self.assertEquals(wt.branch.last_revision(),
120 repos.generate_revision_id(2, "", mapping))
121 self.assertEqual(repos.generate_revision_id(2, "", mapping),
122 self.svndir.open_branch().last_revision())
124 def test_override_revprops(self):
125 self.svndir._find_repository().get_config().set_user_option("override-svn-revprops", "True")
126 self.build_tree({'dc/file': 'data'})
127 wt = self.bzrdir.open_workingtree()
129 wt.commit(message="Commit from Bzr", committer="Sombody famous", timestamp=1012604400, timezone=0)
131 self.svndir.open_branch().pull(self.bzrdir.open_branch())
133 self.assertEquals(("Sombody famous", "2002-02-01T23:00:00.000000Z", "Commit from Bzr"),
134 self.client_log(self.repos_url)[2][1:])
136 def test_empty_file(self):
137 self.build_tree({'dc/file': ''})
138 wt = self.bzrdir.open_workingtree()
140 wt.commit(message="Commit from Bzr")
142 self.svndir.open_branch().pull(self.bzrdir.open_branch())
144 repos = self.svndir._find_repository()
145 mapping = repos.get_mapping()
146 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
147 self.assertTrue(inv.has_filename('file'))
148 self.assertEquals(wt.branch.last_revision(),
149 repos.generate_revision_id(2, "", mapping))
150 self.assertEqual(repos.generate_revision_id(2, "", mapping),
151 self.svndir.open_branch().last_revision())
153 def test_symlink(self):
154 if not has_symlinks():
156 os.symlink("bla", "dc/south")
157 assert os.path.islink("dc/south")
158 wt = self.bzrdir.open_workingtree()
160 wt.commit(message="Commit from Bzr")
162 self.svndir.open_branch().pull(self.bzrdir.open_branch())
164 repos = self.svndir._find_repository()
165 mapping = repos.get_mapping()
166 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
167 self.assertTrue(inv.has_filename('south'))
168 self.assertEquals('symlink', inv[inv.path2id('south')].kind)
169 self.assertEquals('bla', inv[inv.path2id('south')].symlink_target)
171 def test_pull_after_push(self):
172 self.build_tree({'dc/file': 'data'})
173 wt = self.bzrdir.open_workingtree()
175 wt.commit(message="Commit from Bzr")
177 self.svndir.open_branch().pull(self.bzrdir.open_branch())
179 repos = self.svndir._find_repository()
180 mapping = repos.get_mapping()
181 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
182 self.assertTrue(inv.has_filename('file'))
183 self.assertEquals(wt.branch.last_revision(),
184 repos.generate_revision_id(2, "", mapping))
185 self.assertEqual(repos.generate_revision_id(2, "", mapping),
186 self.svndir.open_branch().last_revision())
188 self.bzrdir.open_branch().pull(self.svndir.open_branch())
190 self.assertEqual(repos.generate_revision_id(2, "", mapping),
191 self.bzrdir.open_branch().last_revision())
193 def test_branch_after_push(self):
194 self.build_tree({'dc/file': 'data'})
195 wt = self.bzrdir.open_workingtree()
197 wt.commit(message="Commit from Bzr")
199 self.svndir.open_branch().pull(self.bzrdir.open_branch())
202 repos = self.svndir.sprout("b")
204 self.assertEqual(Branch.open("dc").revision_history(),
205 Branch.open("b").revision_history())
207 def test_message(self):
208 self.build_tree({'dc/file': 'data'})
209 wt = self.bzrdir.open_workingtree()
211 wt.commit(message="Commit from Bzr")
213 self.svndir.open_branch().pull(self.bzrdir.open_branch())
215 repos = self.svndir._find_repository()
216 mapping = repos.get_mapping()
217 self.assertEqual("Commit from Bzr",
218 repos.get_revision(repos.generate_revision_id(2, "", mapping)).message)
220 def test_commit_set_revid(self):
221 self.build_tree({'dc/file': 'data'})
222 wt = self.bzrdir.open_workingtree()
224 wt.commit(message="Commit from Bzr", rev_id="some-rid")
226 self.svndir.open_branch().pull(self.bzrdir.open_branch())
228 self.client_update("sc")
229 self.assertEqual("3 some-rid\n",
230 self.client_get_prop("sc", SVN_PROP_BZR_REVISION_ID+"none"))
232 def test_commit_check_rev_equal(self):
233 self.build_tree({'dc/file': 'data'})
234 wt = self.bzrdir.open_workingtree()
236 wt.commit(message="Commit from Bzr")
238 self.svndir.open_branch().pull(self.bzrdir.open_branch())
240 rev1 = self.svndir._find_repository().get_revision(wt.branch.last_revision())
241 rev2 = self.bzrdir.find_repository().get_revision(wt.branch.last_revision())
243 self.assertEqual(rev1.committer, rev2.committer)
244 self.assertEqual(rev1.timestamp, rev2.timestamp)
245 self.assertEqual(rev1.timezone, rev2.timezone)
246 self.assertEqual(rev1.properties, rev2.properties)
247 self.assertEqual(rev1.message, rev2.message)
248 self.assertEqual(rev1.revision_id, rev2.revision_id)
250 def test_multiple(self):
251 self.build_tree({'dc/file': 'data'})
252 wt = self.bzrdir.open_workingtree()
254 wt.commit(message="Commit from Bzr")
256 self.build_tree({'dc/file': 'data2', 'dc/adir': None})
258 wt.commit(message="Another commit from Bzr")
260 self.svndir.open_branch().pull(self.bzrdir.open_branch())
262 repos = self.svndir._find_repository()
264 mapping = repos.get_mapping()
266 self.assertEqual(repos.generate_revision_id(3, "", mapping),
267 self.svndir.open_branch().last_revision())
269 inv = repos.get_inventory(repos.generate_revision_id(2, "", mapping))
270 self.assertTrue(inv.has_filename('file'))
271 self.assertFalse(inv.has_filename('adir'))
273 inv = repos.get_inventory(repos.generate_revision_id(3, "", mapping))
274 self.assertTrue(inv.has_filename('file'))
275 self.assertTrue(inv.has_filename('adir'))
277 self.assertEqual(self.svndir.open_branch().revision_history(),
278 self.bzrdir.open_branch().revision_history())
280 self.assertEqual(wt.branch.last_revision(),
281 repos.generate_revision_id(3, "", mapping))
283 wt.branch.repository.get_ancestry(wt.branch.last_revision()),
284 repos.get_ancestry(wt.branch.last_revision()))
286 def test_multiple_diverged(self):
287 oc_url = self.make_client("o", "oc")
289 self.build_tree({'dc/file': 'data'})
290 wt = self.bzrdir.open_workingtree()
292 wt.commit(message="Commit from Bzr")
294 self.build_tree({'oc/file': 'data2', 'oc/adir': None})
295 self.client_add("oc/file")
296 self.client_add("oc/adir")
297 self.client_commit("oc", "Another commit from Bzr")
299 self.assertRaises(DivergedBranches,
300 lambda: Branch.open(oc_url).pull(self.bzrdir.open_branch()))
302 def test_different_branch_path(self):
305 self.build_tree({'sc/trunk/foo': "data", 'sc/branches': None})
306 self.client_add("sc/trunk")
307 self.client_add("sc/branches")
308 self.client_commit("sc", "foo")
310 self.client_copy('sc/trunk', 'sc/branches/mybranch')
311 self.build_tree({'sc/branches/mybranch/foo': "data2"})
312 self.client_commit("sc", "add branch")
314 self.svndir = BzrDir.open("sc/branches/mybranch")
316 self.bzrdir = self.svndir.sprout("mybranch")
318 self.build_tree({'mybranch/foo': 'bladata'})
319 wt = self.bzrdir.open_workingtree()
320 revid = wt.commit(message="Commit from Bzr")
321 push(Branch.open("sc/trunk"), wt.branch,
322 wt.branch.revision_history()[-2])
323 mutter('log %r' % self.client_log("sc/trunk")[4][0])
324 self.assertEquals('M',
325 self.client_log("sc/trunk")[4][0]['/trunk'].action)
326 push(Branch.open("sc/trunk"), wt.branch, wt.branch.last_revision())
327 mutter('log %r' % self.client_log("sc/trunk")[5][0])
328 self.assertEquals("/branches/mybranch",
329 self.client_log("sc/trunk")[5][0]['/trunk'].copyfrom_path)
331 class PushNewBranchTests(TestCaseWithSubversionRepository):
332 def test_single_revision(self):
333 repos_url = self.make_client("a", "dc")
334 bzrwt = BzrDir.create_standalone_workingtree("c",
335 format=format.get_rich_root_format())
336 self.build_tree({'c/test': "Tour"})
338 revid = bzrwt.commit("Do a commit")
339 newdir = BzrDir.open("%s/trunk" % repos_url)
340 newbranch = newdir.import_branch(bzrwt.branch)
341 newtree = newbranch.repository.revision_tree(revid)
343 self.assertEquals(bzrwt.inventory.root.file_id,
344 newtree.inventory.root.file_id)
346 self.assertEquals(revid, newbranch.last_revision())
347 self.assertEquals([revid], newbranch.revision_history())
349 def test_single_revision_single_branching_scheme(self):
350 repos_url = self.make_client("a", "dc")
351 bzrwt = BzrDir.create_standalone_workingtree("c",
352 format=format.get_rich_root_format())
353 self.build_tree({'c/test': "Tour"})
355 revid = bzrwt.commit("Do a commit")
356 self.build_tree({"dc/some/funny/branch": None})
357 self.client_add("dc/some")
358 self.client_commit("dc", "msg")
359 newdir = BzrDir.open("%s/some/funny/branch/name" % repos_url)
360 newbranch = newdir.import_branch(bzrwt.branch)
361 self.assertEquals(revid, newbranch.last_revision())
363 # revision graph for the two tests below:
372 def test_push_replace_existing_root(self):
373 repos_url = self.make_client("test", "svnco")
374 self.build_tree({'svnco/foo.txt': 'foo'})
375 self.client_add("svnco/foo.txt")
376 self.client_commit("svnco", "add file") #1
377 self.client_update("svnco")
380 dir = BzrDir.open(repos_url).sprout("bzrco")
381 wt = dir.open_workingtree()
382 self.build_tree({'bzrco/bar.txt': 'bar'})
384 base_revid = wt.commit("add another file", rev_id="mybase")
385 wt.branch.push(Branch.open(repos_url))
387 self.build_tree({"svnco/baz.txt": "baz"})
388 self.client_add("svnco/baz.txt")
390 self.client_commit("svnco", "add yet another file")[0])
391 self.client_update("svnco")
393 self.build_tree({"bzrco/qux.txt": "qux"})
395 wt.commit("add still more files", rev_id="mydiver")
397 repos = Repository.open(repos_url)
398 wt.branch.repository.fetch(repos)
399 mapping = repos.get_mapping()
400 other_rev = repos.generate_revision_id(3, "", mapping)
403 merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
404 merge.merge_type = Merge3Merger
406 self.assertEquals(base_revid, merge.base_rev_id)
408 self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
409 wt.commit("merge", rev_id="mymerge")
412 self.assertTrue(os.path.exists("bzrco/baz.txt"))
413 self.assertRaises(BzrError,
414 lambda: wt.branch.push(Branch.open(repos_url)))
416 def test_push_replace_existing_branch(self):
417 repos_url = self.make_client("test", "svnco")
418 self.build_tree({'svnco/trunk/foo.txt': 'foo'})
419 self.client_add("svnco/trunk")
420 self.client_commit("svnco", "add file") #1
421 self.client_update("svnco")
424 dir = BzrDir.open(repos_url+"/trunk").sprout("bzrco")
425 wt = dir.open_workingtree()
426 self.build_tree({'bzrco/bar.txt': 'bar'})
428 base_revid = wt.commit("add another file", rev_id="mybase")
429 wt.branch.push(Branch.open(repos_url+"/trunk"))
431 self.build_tree({"svnco/trunk/baz.txt": "baz"})
432 self.client_add("svnco/trunk/baz.txt")
434 self.client_commit("svnco", "add yet another file")[0])
435 self.client_update("svnco")
437 self.build_tree({"bzrco/qux.txt": "qux"})
439 wt.commit("add still more files", rev_id="mydiver")
441 repos = Repository.open(repos_url)
442 wt.branch.repository.fetch(repos)
443 mapping = repos.get_mapping()
444 other_rev = repos.generate_revision_id(3, "trunk", mapping)
447 merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
448 merge.merge_type = Merge3Merger
450 self.assertEquals(base_revid, merge.base_rev_id)
452 self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
453 wt.commit("merge", rev_id="mymerge")
456 self.assertTrue(os.path.exists("bzrco/baz.txt"))
457 wt.branch.push(Branch.open(repos_url+"/trunk"))
459 def test_missing_prefix_error(self):
460 repos_url = self.make_client("a", "dc")
461 bzrwt = BzrDir.create_standalone_workingtree("c",
462 format=format.get_rich_root_format())
463 self.build_tree({'c/test': "Tour"})
465 revid = bzrwt.commit("Do a commit")
466 newdir = BzrDir.open(repos_url+"/foo/trunk")
467 self.assertRaises(MissingPrefix,
468 lambda: newdir.import_branch(bzrwt.branch))
470 def test_repeat(self):
471 repos_url = self.make_client("a", "dc")
472 bzrwt = BzrDir.create_standalone_workingtree("c",
473 format=format.get_rich_root_format())
474 self.build_tree({'c/test': "Tour"})
476 revid = bzrwt.commit("Do a commit")
477 newdir = BzrDir.open(repos_url+"/trunk")
478 newbranch = newdir.import_branch(bzrwt.branch)
479 self.assertEquals(revid, newbranch.last_revision())
480 self.assertEquals([revid], newbranch.revision_history())
481 self.build_tree({'c/test': "Tour de France"})
482 bzrwt.commit("Do a commit")
483 newdir = BzrDir.open(repos_url+"/trunk")
484 self.assertRaises(AlreadyBranchError, newdir.import_branch,
487 def test_multiple(self):
488 repos_url = self.make_client("a", "dc")
489 bzrwt = BzrDir.create_standalone_workingtree("c",
490 format=format.get_rich_root_format())
491 self.build_tree({'c/test': "Tour"})
493 revid1 = bzrwt.commit("Do a commit")
494 self.build_tree({'c/test': "Tour de France"})
495 revid2 = bzrwt.commit("Do a commit")
496 newdir = BzrDir.open(repos_url+"/trunk")
497 newbranch = newdir.import_branch(bzrwt.branch)
498 self.assertEquals(revid2, newbranch.last_revision())
499 self.assertEquals([revid1, revid2], newbranch.revision_history())
502 repos_url = self.make_client("a", "dc")
503 bzrwt = BzrDir.create_standalone_workingtree("c",
504 format=format.get_rich_root_format())
505 self.build_tree({'c/foo.txt': "foo"})
507 revid1 = bzrwt.commit("Do a commit",
508 committer=u"Adeodato Simó <dato@net.com.org.es>")
509 newdir = BzrDir.open(repos_url+"/trunk")
510 newdir.import_branch(bzrwt.branch)
511 self.assertEquals(u"Adeodato Simó <dato@net.com.org.es>",
512 Repository.open(repos_url).get_revision(revid1).committer)
514 def test_utf8_commit_msg(self):
515 repos_url = self.make_client("a", "dc")
516 bzrwt = BzrDir.create_standalone_workingtree("c",
517 format=format.get_rich_root_format())
518 self.build_tree({'c/foo.txt': "foo"})
520 revid1 = bzrwt.commit(u"Do á commït")
521 newdir = BzrDir.open(repos_url+"/trunk")
522 newdir.import_branch(bzrwt.branch)
523 self.assertEquals(u"Do á commït",
524 Repository.open(repos_url).get_revision(revid1).message)
526 def test_multiple_part_exists(self):
527 repos_url = self.make_client("a", "dc")
528 self.build_tree({'dc/trunk/myfile': "data", 'dc/branches': None})
529 self.client_add('dc/trunk')
530 self.client_add('dc/branches')
531 self.client_commit("dc", "Message")
532 svnrepos = Repository.open(repos_url)
534 bzrdir = BzrDir.open(repos_url+"/trunk").sprout("c")
535 bzrwt = bzrdir.open_workingtree()
536 self.build_tree({'c/myfile': "Tour"})
537 revid1 = bzrwt.commit("Do a commit")
538 self.build_tree({'c/myfile': "Tour de France"})
539 revid2 = bzrwt.commit("Do a commit")
540 newdir = BzrDir.open(repos_url+"/branches/mybranch")
541 newbranch = newdir.import_branch(bzrwt.branch)
542 self.assertEquals(revid2, newbranch.last_revision())
543 mapping = svnrepos.get_mapping()
545 svnrepos.generate_revision_id(1, "trunk", mapping)
546 , revid1, revid2], newbranch.revision_history())
548 def test_push_overwrite(self):
549 repos_url = self.make_client("a", "dc")
550 self.build_tree({'dc/trunk/bloe': "text"})
551 self.client_add("dc/trunk")
552 self.client_commit("dc", "initial")
555 bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d1")
556 bzrwt1 = bzrdir.open_workingtree()
559 bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d2")
560 bzrwt2 = bzrdir.open_workingtree()
562 self.build_tree({'d1/myfile': "Tour"})
564 revid1 = bzrwt1.commit("Do a commit")
566 self.build_tree({'d2/myfile': "France"})
568 revid2 = bzrwt1.commit("Do a commit")
570 bzrwt1.branch.push(Branch.open(repos_url+"/trunk"))
572 raise KnownFailure("push --overwrite not supported yet")
574 bzrwt2.branch.push(Branch.open(repos_url+"/trunk"), overwrite=True)
576 self.assertEquals([revid2],
577 Branch.open(repos_url+"/trunk").revision_history())
579 def test_complex_rename(self):
580 repos_url = self.make_client("a", "dc")
581 bzrwt = BzrDir.create_standalone_workingtree("c",
582 format=format.get_rich_root_format())
583 self.build_tree({'c/registry/generic.c': "Tour"})
584 bzrwt.add("registry")
585 bzrwt.add("registry/generic.c")
586 revid1 = bzrwt.commit("Add initial directory + file")
587 bzrwt.rename_one("registry", "registry.moved")
588 os.unlink("c/registry.moved/generic.c")
589 bzrwt.remove("registry.moved/generic.c")
590 self.build_tree({'c/registry/generic.c': "bla"})
591 bzrwt.add("registry")
592 bzrwt.add("registry/generic.c")
593 revid2 = bzrwt.commit("Do some funky things")
594 newdir = BzrDir.open(repos_url+"/trunk")
595 newbranch = newdir.import_branch(bzrwt.branch)
596 self.assertEquals(revid2, newbranch.last_revision())
597 self.assertEquals([revid1, revid2], newbranch.revision_history())
598 tree = newbranch.repository.revision_tree(revid2)
599 mutter("inventory: %r" % tree.inventory.entries())
600 delta = tree.changes_from(bzrwt)
601 self.assertFalse(delta.has_changed())
602 self.assertTrue(tree.inventory.has_filename("registry"))
603 self.assertTrue(tree.inventory.has_filename("registry.moved"))
604 self.assertTrue(tree.inventory.has_filename("registry/generic.c"))
605 self.assertFalse(tree.inventory.has_filename("registry.moved/generic.c"))
607 BzrDir.open(repos_url+"/trunk").sprout("n")
609 def test_rename_dir_changing_contents(self):
610 repos_url = self.make_client("a", "dc")
611 bzrwt = BzrDir.create_standalone_workingtree("c",
612 format=format.get_rich_root_format())
613 self.build_tree({'c/registry/generic.c': "Tour"})
614 bzrwt.add("registry", "dirid")
615 bzrwt.add("registry/generic.c", "origid")
616 revid1 = bzrwt.commit("Add initial directory + file")
617 bzrwt.rename_one("registry/generic.c", "registry/c.c")
618 self.build_tree({'c/registry/generic.c': "Tour2"})
619 bzrwt.add("registry/generic.c", "newid")
620 revid2 = bzrwt.commit("Other change")
621 bzrwt.rename_one("registry", "registry.moved")
622 revid3 = bzrwt.commit("Rename")
623 newdir = BzrDir.open(repos_url+"/trunk")
624 newbranch = newdir.import_branch(bzrwt.branch)
626 self.assertEquals([revid1, revid2, revid3], b.revision_history())
627 tree = b.repository.revision_tree(revid3)
628 self.assertEquals("origid", tree.path2id("registry.moved/c.c"))
629 self.assertEquals("newid", tree.path2id("registry.moved/generic.c"))
630 self.assertEquals("dirid", tree.path2id("registry.moved"))
633 BzrDir.open(repos_url+"/trunk").sprout("n")
634 copybranch = Branch.open("n")
637 def test_rename_dir(self):
638 repos_url = self.make_client("a", "dc")
639 bzrwt = BzrDir.create_standalone_workingtree("c",
640 format=format.get_rich_root_format())
641 self.build_tree({'c/registry/generic.c': "Tour"})
642 bzrwt.add("registry", "dirid")
643 bzrwt.add("registry/generic.c", "origid")
644 revid1 = bzrwt.commit("Add initial directory + file")
645 bzrwt.rename_one("registry", "registry.moved")
646 revid2 = bzrwt.commit("Rename")
647 newdir = BzrDir.open(repos_url+"/trunk")
648 newbranch = newdir.import_branch(bzrwt.branch)
650 self.assertEquals([revid1, revid2], b.revision_history())
651 tree = b.repository.revision_tree(revid2)
652 self.assertEquals("origid", tree.path2id("registry.moved/generic.c"))
653 self.assertEquals("dirid", tree.path2id("registry.moved"))
656 BzrDir.open(repos_url+"/trunk").sprout("n")
657 copybranch = Branch.open("n")
660 def test_push_non_lhs_parent(self):
661 from bzrlib.debug import debug_flags
662 debug_flags.add("commit")
663 debug_flags.add("fetch")
664 repos_url = self.make_client("a", "dc")
665 bzrwt = BzrDir.create_standalone_workingtree("c",
666 format=format.get_rich_root_format())
667 self.build_tree({'c/registry/generic.c': "Tour"})
668 bzrwt.add("registry")
669 bzrwt.add("registry/generic.c")
670 revid1 = bzrwt.commit("Add initial directory + file",
671 rev_id="initialrevid")
673 # Push first branch into Subversion
674 newdir = BzrDir.open(repos_url+"/trunk")
675 mapping = newdir.find_repository().get_mapping()
676 newbranch = newdir.import_branch(bzrwt.branch)
678 # Should create dc/trunk
679 self.client_update("dc")
681 self.build_tree({'dc/branches': None})
682 self.client_add("dc/branches")
683 self.client_copy("dc/trunk", "dc/branches/foo")
684 self.client_commit("dc", "Copy branches")
685 self.client_update("dc")
687 self.build_tree({'dc/branches/foo/registry/generic.c': "France"})
688 merge_revno = self.client_commit("dc", "Change copied branch")[0]
689 merge_revid = newdir.find_repository().generate_revision_id(merge_revno, "branches/foo", mapping)
691 self.build_tree({'c/registry/generic.c': "de"})
692 revid2 = bzrwt.commit("Change something", rev_id="changerevid")
695 self.build_tree({'c/registry/generic.c': "France"})
696 bzrwt.add_pending_merge(merge_revid)
697 revid3 = bzrwt.commit("Merge something", rev_id="mergerevid")
699 trunk = Branch.open(repos_url + "/branches/foo")
700 trunk.pull(bzrwt.branch)
702 self.assertEquals([revid1, revid2, revid3], trunk.revision_history())
703 self.client_update("dc")
705 '1 initialrevid\n2 changerevid\n3 mergerevid\n',
706 self.client_get_prop("dc/branches/foo", SVN_PROP_BZR_REVISION_ID+"trunk0"))
708 def test_complex_replace_dir(self):
709 repos_url = self.make_client("a", "dc")
710 bzrwt = BzrDir.create_standalone_workingtree("c",
711 format=format.get_rich_root_format())
712 self.build_tree({'c/registry/generic.c': "Tour"})
713 bzrwt.add(["registry"], ["origdir"])
714 bzrwt.add(["registry/generic.c"], ["file"])
715 revid1 = bzrwt.commit("Add initial directory + file")
717 bzrwt.remove('registry/generic.c')
718 bzrwt.remove('registry')
719 bzrwt.add(["registry"], ["newdir"])
720 bzrwt.add(["registry/generic.c"], ["file"])
721 revid2 = bzrwt.commit("Do some funky things")
723 newdir = BzrDir.open(repos_url+"/trunk")
724 newbranch = newdir.import_branch(bzrwt.branch)
725 self.assertEquals(revid2, newbranch.last_revision())
726 self.assertEquals([revid1, revid2], newbranch.revision_history())
729 BzrDir.open(repos_url+"/trunk").sprout("n")
731 def test_push_unnecessary_merge(self):
732 from bzrlib.debug import debug_flags
733 debug_flags.add("commit")
734 debug_flags.add("fetch")
735 repos_url = self.make_client("a", "dc")
736 bzrwt = BzrDir.create_standalone_workingtree("c",
737 format=format.get_rich_root_format())
738 self.build_tree({'c/registry/generic.c': "Tour"})
739 bzrwt.add("registry")
740 bzrwt.add("registry/generic.c")
741 revid1 = bzrwt.commit("Add initial directory + file",
742 rev_id="initialrevid")
744 # Push first branch into Subversion
745 newdir = BzrDir.open(repos_url+"/trunk")
746 newbranch = newdir.import_branch(bzrwt.branch)
748 # Should create dc/trunk
749 self.client_update("dc")
751 self.assertTrue(os.path.exists("dc/trunk/registry/generic.c"))
752 sleep(1) # Subversion relies on timestamps to detect
754 self.build_tree({'dc/trunk/registry/generic.c': "BLA"})
755 self.client_commit("dc/trunk", "Change copied branch")
756 self.client_update("dc")
757 mapping = newdir.find_repository().get_mapping()
758 merge_revid = newdir.find_repository().generate_revision_id(2, "trunk", mapping)
761 self.build_tree({'c/registry/generic.c': "DE"})
762 bzrwt.add_pending_merge(merge_revid)
763 self.assertEquals(bzrwt.get_parent_ids()[1], merge_revid)
764 revid2 = bzrwt.commit("Merge something", rev_id="mergerevid")
765 bzr_parents = bzrwt.branch.repository.get_revision(revid2).parent_ids
766 trunk = Branch.open(repos_url + "/trunk")
767 trunk.pull(bzrwt.branch)
769 self.assertEquals(tuple(bzr_parents),
770 trunk.repository.get_revision(revid2).parent_ids)
772 self.assertEquals([revid1, revid2], trunk.revision_history())
773 self.client_update("dc")
775 '1 initialrevid\n2 mergerevid\n',
776 self.client_get_prop("dc/trunk", SVN_PROP_BZR_REVISION_ID+"trunk0"))