Use locking and write groups properly, fixes compatibility with packs.
[jelmer/subvertpy.git] / tests / test_push.py
1 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
2
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.
7
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.
12
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
16
17 from bzrlib.branch import Branch, BranchReferenceFormat
18 from bzrlib.bzrdir import BzrDir, BzrDirFormat
19 from bzrlib.errors import AlreadyBranchError, DivergedBranches
20 from bzrlib.inventory import Inventory
21 from bzrlib.merge import Merger, Merge3Merger
22 from bzrlib.progress import DummyProgress
23 from bzrlib.repository import Repository
24 from bzrlib.tests import KnownFailure, TestCaseWithTransport
25 from bzrlib.trace import mutter
26 from bzrlib.workingtree import WorkingTree
27
28 import os
29 import format
30 import svn.core
31 from time import sleep
32 from commit import push
33 from repository import MAPPING_VERSION, SVN_PROP_BZR_REVISION_ID
34 from revids import generate_svn_revision_id
35 from tests import TestCaseWithSubversionRepository
36
37 class TestPush(TestCaseWithSubversionRepository):
38     def setUp(self):
39         super(TestPush, self).setUp()
40         self.repos_url = self.make_client('d', 'sc')
41
42         self.build_tree({'sc/foo/bla': "data"})
43         self.client_add("sc/foo")
44         self.client_commit("sc", "foo")
45
46         self.svndir = BzrDir.open("sc")
47         os.mkdir("dc")
48         self.bzrdir = self.svndir.sprout("dc")
49
50     def test_empty(self):
51         svnbranch = self.svndir.open_branch()
52         bzrbranch = self.bzrdir.open_branch()
53         result = svnbranch.pull(bzrbranch)
54         self.assertEqual(0, result.new_revno - result.old_revno)
55         self.assertEqual(svnbranch.revision_history(),
56                          bzrbranch.revision_history())
57
58     def test_child(self):
59         self.build_tree({'sc/foo/bar': "data"})
60         self.client_add("sc/foo/bar")
61         self.client_commit("sc", "second message")
62
63         svnbranch = self.svndir.open_branch()
64         bzrbranch = self.bzrdir.open_branch()
65         result = svnbranch.pull(bzrbranch)
66         self.assertEqual(0, result.new_revno - result.old_revno)
67
68     def test_diverged(self):
69         self.build_tree({'sc/foo/bar': "data"})
70         self.client_add("sc/foo/bar")
71         self.client_commit("sc", "second message")
72
73         svndir = BzrDir.open("sc")
74
75         self.build_tree({'dc/file': 'data'})
76         wt = self.bzrdir.open_workingtree()
77         wt.add('file')
78         wt.commit(message="Commit from Bzr")
79
80         self.assertRaises(DivergedBranches, 
81                           svndir.open_branch().pull,
82                           self.bzrdir.open_branch())
83
84     def test_change(self):
85         self.build_tree({'dc/foo/bla': 'other data'})
86         wt = self.bzrdir.open_workingtree()
87         newid = wt.commit(message="Commit from Bzr")
88
89         svnbranch = self.svndir.open_branch()
90         svnbranch.pull(self.bzrdir.open_branch())
91
92         repos = self.svndir.find_repository()
93         self.assertEquals(newid, svnbranch.last_revision())
94         inv = repos.get_inventory(repos.generate_revision_id(2, "", "none"))
95         self.assertEqual(newid, inv[inv.path2id('foo/bla')].revision)
96         self.assertEqual(wt.branch.last_revision(),
97           repos.generate_revision_id(2, "", "none"))
98         self.assertEqual(repos.generate_revision_id(2, "", "none"),
99                         self.svndir.open_branch().last_revision())
100         self.assertEqual("other data", 
101             repos.revision_tree(repos.generate_revision_id(2, "", 
102                                 "none")).get_file_text(inv.path2id("foo/bla")))
103
104     def test_simple(self):
105         self.build_tree({'dc/file': 'data'})
106         wt = self.bzrdir.open_workingtree()
107         wt.add('file')
108         wt.commit(message="Commit from Bzr")
109
110         self.svndir.open_branch().pull(self.bzrdir.open_branch())
111
112         repos = self.svndir.find_repository()
113         inv = repos.get_inventory(repos.generate_revision_id(2, "", "none"))
114         self.assertTrue(inv.has_filename('file'))
115         self.assertEquals(wt.branch.last_revision(),
116                 repos.generate_revision_id(2, "", "none"))
117         self.assertEqual(repos.generate_revision_id(2, "", "none"),
118                         self.svndir.open_branch().last_revision())
119
120     def test_empty_file(self):
121         self.build_tree({'dc/file': ''})
122         wt = self.bzrdir.open_workingtree()
123         wt.add('file')
124         wt.commit(message="Commit from Bzr")
125
126         self.svndir.open_branch().pull(self.bzrdir.open_branch())
127
128         repos = self.svndir.find_repository()
129         inv = repos.get_inventory(repos.generate_revision_id(2, "", "none"))
130         self.assertTrue(inv.has_filename('file'))
131         self.assertEquals(wt.branch.last_revision(),
132                 repos.generate_revision_id(2, "", "none"))
133         self.assertEqual(repos.generate_revision_id(2, "", "none"),
134                         self.svndir.open_branch().last_revision())
135
136     def test_pull_after_push(self):
137         self.build_tree({'dc/file': 'data'})
138         wt = self.bzrdir.open_workingtree()
139         wt.add('file')
140         wt.commit(message="Commit from Bzr")
141
142         self.svndir.open_branch().pull(self.bzrdir.open_branch())
143
144         repos = self.svndir.find_repository()
145         inv = repos.get_inventory(repos.generate_revision_id(2, "", "none"))
146         self.assertTrue(inv.has_filename('file'))
147         self.assertEquals(wt.branch.last_revision(),
148                          repos.generate_revision_id(2, "", "none"))
149         self.assertEqual(repos.generate_revision_id(2, "", "none"),
150                         self.svndir.open_branch().last_revision())
151
152         self.bzrdir.open_branch().pull(self.svndir.open_branch())
153
154         self.assertEqual(repos.generate_revision_id(2, "", "none"),
155                         self.bzrdir.open_branch().last_revision())
156
157     def test_branch_after_push(self):
158         self.build_tree({'dc/file': 'data'})
159         wt = self.bzrdir.open_workingtree()
160         wt.add('file')
161         wt.commit(message="Commit from Bzr")
162
163         self.svndir.open_branch().pull(self.bzrdir.open_branch())
164
165         os.mkdir("b")
166         repos = self.svndir.sprout("b")
167
168         self.assertEqual(Branch.open("dc").revision_history(), 
169                          Branch.open("b").revision_history())
170
171     def test_message(self):
172         self.build_tree({'dc/file': 'data'})
173         wt = self.bzrdir.open_workingtree()
174         wt.add('file')
175         wt.commit(message="Commit from Bzr")
176
177         self.svndir.open_branch().pull(self.bzrdir.open_branch())
178
179         repos = self.svndir.find_repository()
180         self.assertEqual("Commit from Bzr",
181           repos.get_revision(repos.generate_revision_id(2, "", "none")).message)
182
183     def test_commit_set_revid(self):
184         self.build_tree({'dc/file': 'data'})
185         wt = self.bzrdir.open_workingtree()
186         wt.add('file')
187         wt.commit(message="Commit from Bzr", rev_id="some-rid")
188
189         self.svndir.open_branch().pull(self.bzrdir.open_branch())
190
191         self.client_update("sc")
192         self.assertEqual("3 some-rid\n", 
193                 self.client_get_prop("sc", SVN_PROP_BZR_REVISION_ID+"none"))
194
195     def test_commit_check_rev_equal(self):
196         self.build_tree({'dc/file': 'data'})
197         wt = self.bzrdir.open_workingtree()
198         wt.add('file')
199         wt.commit(message="Commit from Bzr")
200
201         self.svndir.open_branch().pull(self.bzrdir.open_branch())
202
203         rev1 = self.svndir.find_repository().get_revision(wt.branch.last_revision())
204         rev2 = self.bzrdir.find_repository().get_revision(wt.branch.last_revision())
205
206         self.assertEqual(rev1.committer, rev2.committer)
207         self.assertEqual(rev1.timestamp, rev2.timestamp)
208         self.assertEqual(rev1.timezone, rev2.timezone)
209         self.assertEqual(rev1.properties, rev2.properties)
210         self.assertEqual(rev1.message, rev2.message)
211         self.assertEqual(rev1.revision_id, rev2.revision_id)
212
213     def test_multiple(self):
214         self.build_tree({'dc/file': 'data'})
215         wt = self.bzrdir.open_workingtree()
216         wt.add('file')
217         wt.commit(message="Commit from Bzr")
218
219         self.build_tree({'dc/file': 'data2', 'dc/adir': None})
220         wt.add('adir')
221         wt.commit(message="Another commit from Bzr")
222
223         self.svndir.open_branch().pull(self.bzrdir.open_branch())
224
225         repos = self.svndir.find_repository()
226
227         self.assertEqual(repos.generate_revision_id(3, "", "none"), 
228                         self.svndir.open_branch().last_revision())
229
230         inv = repos.get_inventory(repos.generate_revision_id(2, "", "none"))
231         self.assertTrue(inv.has_filename('file'))
232         self.assertFalse(inv.has_filename('adir'))
233
234         inv = repos.get_inventory(repos.generate_revision_id(3, "", "none"))
235         self.assertTrue(inv.has_filename('file'))
236         self.assertTrue(inv.has_filename('adir'))
237
238         self.assertEqual(self.svndir.open_branch().revision_history(),
239                          self.bzrdir.open_branch().revision_history())
240
241         self.assertEqual(wt.branch.last_revision(), 
242                 repos.generate_revision_id(3, "", "none"))
243         self.assertEqual(
244                 wt.branch.repository.get_ancestry(wt.branch.last_revision()), 
245                 repos.get_ancestry(wt.branch.last_revision()))
246
247     def test_multiple_diverged(self):
248         oc_url = self.make_client("o", "oc")
249
250         self.build_tree({'dc/file': 'data'})
251         wt = self.bzrdir.open_workingtree()
252         wt.add('file')
253         wt.commit(message="Commit from Bzr")
254
255         self.build_tree({'oc/file': 'data2', 'oc/adir': None})
256         self.client_add("oc/file")
257         self.client_add("oc/adir")
258         self.client_commit("oc", "Another commit from Bzr")
259
260         self.assertRaises(DivergedBranches, 
261                 lambda: Branch.open(oc_url).pull(self.bzrdir.open_branch()))
262
263     def test_different_branch_path(self):
264         # A       ,> C
265         # \ -> B /
266         self.build_tree({'sc/trunk/foo': "data", 'sc/branches': None})
267         self.client_add("sc/trunk")
268         self.client_add("sc/branches")
269         self.client_commit("sc", "foo")
270
271         self.client_copy('sc/trunk', 'sc/branches/mybranch')
272         self.build_tree({'sc/branches/mybranch/foo': "data2"})
273         self.client_commit("sc", "add branch")
274
275         self.svndir = BzrDir.open("sc/branches/mybranch")
276         os.mkdir("mybranch")
277         self.bzrdir = self.svndir.sprout("mybranch")
278
279         self.build_tree({'mybranch/foo': 'bladata'})
280         wt = self.bzrdir.open_workingtree()
281         revid = wt.commit(message="Commit from Bzr")
282         push(Branch.open("sc/trunk"), wt.branch, 
283              wt.branch.revision_history()[-2])
284         mutter('log %r' % self.client_log("sc/trunk")[4][0])
285         self.assertEquals('M',
286             self.client_log("sc/trunk")[4][0]['/trunk'].action)
287         push(Branch.open("sc/trunk"), wt.branch, wt.branch.last_revision())
288         mutter('log %r' % self.client_log("sc/trunk")[5][0])
289         self.assertEquals("/branches/mybranch", 
290             self.client_log("sc/trunk")[5][0]['/trunk'].copyfrom_path)
291
292 class PushNewBranchTests(TestCaseWithSubversionRepository):
293     def test_single_revision(self):
294         repos_url = self.make_client("a", "dc")
295         bzrwt = BzrDir.create_standalone_workingtree("c", 
296             format=format.get_rich_root_format())
297         self.build_tree({'c/test': "Tour"})
298         bzrwt.add("test")
299         revid = bzrwt.commit("Do a commit")
300         newdir = BzrDir.open(repos_url+"/trunk")
301         newbranch = newdir.import_branch(bzrwt.branch)
302         newtree = newbranch.repository.revision_tree(revid)
303         bzrwt.lock_read()
304         self.assertEquals(bzrwt.inventory.root.file_id,
305                           newtree.inventory.root.file_id)
306         bzrwt.unlock()
307         self.assertEquals(revid, newbranch.last_revision())
308         self.assertEquals([revid], newbranch.revision_history())
309
310     # revision graph for the two tests below:
311     # svn-1
312     # |
313     # base
314     # |    \
315     # diver svn2
316     # |    /
317     # merge
318
319     def test_push_replace_existing_root(self):
320         repos_url = self.make_client("test", "svnco")
321         self.build_tree({'svnco/foo.txt': 'foo'})
322         self.client_add("svnco/foo.txt")
323         self.client_commit("svnco", "add file") #1
324         self.client_update("svnco")
325
326         os.mkdir('bzrco')
327         dir = BzrDir.open(repos_url).sprout("bzrco")
328         wt = dir.open_workingtree()
329         self.build_tree({'bzrco/bar.txt': 'bar'})
330         wt.add("bar.txt")
331         base_revid = wt.commit("add another file", rev_id="mybase")
332         wt.branch.push(Branch.open(repos_url))
333
334         self.build_tree({"svnco/baz.txt": "baz"})
335         self.client_add("svnco/baz.txt")
336         self.assertEquals(3, 
337                 self.client_commit("svnco", "add yet another file")[0])
338         self.client_update("svnco")
339
340         self.build_tree({"bzrco/qux.txt": "qux"})
341         wt.add("qux.txt")
342         wt.commit("add still more files", rev_id="mydiver")
343
344         repos = Repository.open(repos_url)
345         wt.branch.repository.fetch(repos)
346         other_rev = repos.generate_revision_id(3, "", "none")
347         wt.lock_write()
348         try:
349             merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
350             merge.merge_type = Merge3Merger
351             merge.do_merge()
352             self.assertEquals(base_revid, merge.base_rev_id)
353             merge.set_pending()
354             self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
355             wt.commit("merge", rev_id="mymerge")
356         finally:
357             wt.unlock()
358         self.assertTrue(os.path.exists("bzrco/baz.txt"))
359         raise KnownFailure("can't work for repository root")
360         wt.branch.push(Branch.open(repos_url))
361
362     def test_push_replace_existing_branch(self):
363         repos_url = self.make_client("test", "svnco")
364         self.build_tree({'svnco/trunk/foo.txt': 'foo'})
365         self.client_add("svnco/trunk")
366         self.client_commit("svnco", "add file") #1
367         self.client_update("svnco")
368
369         os.mkdir('bzrco')
370         dir = BzrDir.open(repos_url+"/trunk").sprout("bzrco")
371         wt = dir.open_workingtree()
372         self.build_tree({'bzrco/bar.txt': 'bar'})
373         wt.add("bar.txt")
374         base_revid = wt.commit("add another file", rev_id="mybase")
375         wt.branch.push(Branch.open(repos_url+"/trunk"))
376
377         self.build_tree({"svnco/trunk/baz.txt": "baz"})
378         self.client_add("svnco/trunk/baz.txt")
379         self.assertEquals(3, 
380                 self.client_commit("svnco", "add yet another file")[0])
381         self.client_update("svnco")
382
383         self.build_tree({"bzrco/qux.txt": "qux"})
384         wt.add("qux.txt")
385         wt.commit("add still more files", rev_id="mydiver")
386
387         repos = Repository.open(repos_url)
388         wt.branch.repository.fetch(repos)
389         other_rev = repos.generate_revision_id(3, "trunk", "trunk0")
390         wt.lock_write()
391         try:
392             merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
393             merge.merge_type = Merge3Merger
394             merge.do_merge()
395             self.assertEquals(base_revid, merge.base_rev_id)
396             merge.set_pending()
397             self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
398             wt.commit("merge", rev_id="mymerge")
399         finally:
400             wt.unlock()
401         self.assertTrue(os.path.exists("bzrco/baz.txt"))
402         wt.branch.push(Branch.open(repos_url+"/trunk"))
403
404
405
406     def test_repeat(self):
407         repos_url = self.make_client("a", "dc")
408         bzrwt = BzrDir.create_standalone_workingtree("c", 
409             format=format.get_rich_root_format())
410         self.build_tree({'c/test': "Tour"})
411         bzrwt.add("test")
412         revid = bzrwt.commit("Do a commit")
413         newdir = BzrDir.open(repos_url+"/trunk")
414         newbranch = newdir.import_branch(bzrwt.branch)
415         self.assertEquals(revid, newbranch.last_revision())
416         self.assertEquals([revid], newbranch.revision_history())
417         self.build_tree({'c/test': "Tour de France"})
418         bzrwt.commit("Do a commit")
419         newdir = BzrDir.open(repos_url+"/trunk")
420         self.assertRaises(AlreadyBranchError, newdir.import_branch, 
421                           bzrwt.branch)
422
423     def test_multiple(self):
424         repos_url = self.make_client("a", "dc")
425         bzrwt = BzrDir.create_standalone_workingtree("c", 
426             format=format.get_rich_root_format())
427         self.build_tree({'c/test': "Tour"})
428         bzrwt.add("test")
429         revid1 = bzrwt.commit("Do a commit")
430         self.build_tree({'c/test': "Tour de France"})
431         revid2 = bzrwt.commit("Do a commit")
432         newdir = BzrDir.open(repos_url+"/trunk")
433         newbranch = newdir.import_branch(bzrwt.branch)
434         self.assertEquals(revid2, newbranch.last_revision())
435         self.assertEquals([revid1, revid2], newbranch.revision_history())
436
437     def test_multiple_part_exists(self):
438         repos_url = self.make_client("a", "dc")
439         self.build_tree({'dc/trunk/myfile': "data", 'dc/branches': None})
440         self.client_add('dc/trunk')
441         self.client_add('dc/branches')
442         self.client_commit("dc", "Message")
443         svnrepos = Repository.open(repos_url)
444         os.mkdir("c")
445         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("c")
446         bzrwt = bzrdir.open_workingtree()
447         self.build_tree({'c/myfile': "Tour"})
448         revid1 = bzrwt.commit("Do a commit")
449         self.build_tree({'c/myfile': "Tour de France"})
450         revid2 = bzrwt.commit("Do a commit")
451         newdir = BzrDir.open(repos_url+"/branches/mybranch")
452         newbranch = newdir.import_branch(bzrwt.branch)
453         self.assertEquals(revid2, newbranch.last_revision())
454         self.assertEquals([
455             svnrepos.generate_revision_id(1, "trunk", "trunk0") 
456             , revid1, revid2], newbranch.revision_history())
457
458     def test_push_overwrite(self):
459         repos_url = self.make_client("a", "dc")
460         self.build_tree({'dc/trunk/bloe': "text"})
461         self.client_add("dc/trunk")
462         self.client_commit("dc", "initial")
463
464         os.mkdir("d1")
465         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d1")
466         bzrwt1 = bzrdir.open_workingtree()
467
468         os.mkdir("d2")
469         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d2")
470         bzrwt2 = bzrdir.open_workingtree()
471
472         self.build_tree({'d1/myfile': "Tour"})
473         bzrwt1.add("myfile")
474         revid1 = bzrwt1.commit("Do a commit")
475
476         self.build_tree({'d2/myfile': "France"})
477         bzrwt2.add("myfile")
478         revid2 = bzrwt1.commit("Do a commit")
479
480         bzrwt1.branch.push(Branch.open(repos_url+"/trunk"))
481
482         raise KnownFailure("push --overwrite not supported yet")
483
484         bzrwt2.branch.push(Branch.open(repos_url+"/trunk"), overwrite=True)
485
486         self.assertEquals([revid2], 
487                 Branch.open(repos_url+"/trunk").revision_history())
488
489     def test_complex_rename(self):
490         repos_url = self.make_client("a", "dc")
491         bzrwt = BzrDir.create_standalone_workingtree("c", 
492             format=format.get_rich_root_format())
493         self.build_tree({'c/registry/generic.c': "Tour"})
494         bzrwt.add("registry")
495         bzrwt.add("registry/generic.c")
496         revid1 = bzrwt.commit("Add initial directory + file")
497         bzrwt.rename_one("registry", "registry.moved")
498         os.unlink("c/registry.moved/generic.c")
499         bzrwt.remove("registry.moved/generic.c")
500         self.build_tree({'c/registry/generic.c': "bla"})
501         bzrwt.add("registry")
502         bzrwt.add("registry/generic.c")
503         revid2 = bzrwt.commit("Do some funky things")
504         newdir = BzrDir.open(repos_url+"/trunk")
505         newbranch = newdir.import_branch(bzrwt.branch)
506         self.assertEquals(revid2, newbranch.last_revision())
507         self.assertEquals([revid1, revid2], newbranch.revision_history())
508         tree = newbranch.repository.revision_tree(revid2)
509         mutter("inventory: %r" % tree.inventory.entries())
510         delta = tree.changes_from(bzrwt)
511         self.assertFalse(delta.has_changed())
512         self.assertTrue(tree.inventory.has_filename("registry"))
513         self.assertTrue(tree.inventory.has_filename("registry.moved"))
514         self.assertTrue(tree.inventory.has_filename("registry/generic.c"))
515         self.assertFalse(tree.inventory.has_filename("registry.moved/generic.c"))
516         os.mkdir("n")
517         BzrDir.open(repos_url+"/trunk").sprout("n")
518     
519     def test_push_non_lhs_parent(self):        
520         repos_url = self.make_client("a", "dc")
521         bzrwt = BzrDir.create_standalone_workingtree("c", 
522             format=format.get_rich_root_format())
523         self.build_tree({'c/registry/generic.c': "Tour"})
524         bzrwt.add("registry")
525         bzrwt.add("registry/generic.c")
526         revid1 = bzrwt.commit("Add initial directory + file", 
527                               rev_id="initialrevid")
528
529         # Push first branch into Subversion
530         newdir = BzrDir.open(repos_url+"/trunk")
531         newbranch = newdir.import_branch(bzrwt.branch)
532
533         # Should create dc/trunk
534         self.client_update("dc")
535
536         self.build_tree({'dc/branches': None})
537         self.client_add("dc/branches")
538         self.client_copy("dc/trunk", "dc/branches/foo")
539         self.client_commit("dc", "Copy branches")
540         self.client_update("dc")
541
542         self.build_tree({'dc/branches/foo/registry/generic.c': "France"})
543         merge_revno = self.client_commit("dc", "Change copied branch")[0]
544         merge_revid = newdir.find_repository().generate_revision_id(merge_revno, "branches/foo", "trunk0")
545
546         self.build_tree({'c/registry/generic.c': "de"})
547         revid2 = bzrwt.commit("Change something", rev_id="changerevid")
548
549         # Merge 
550         self.build_tree({'c/registry/generic.c': "France"})
551         bzrwt.add_pending_merge(merge_revid)
552         revid3 = bzrwt.commit("Merge something", rev_id="mergerevid")
553
554         trunk = Branch.open(repos_url + "/branches/foo")
555         trunk.pull(bzrwt.branch)
556
557         self.assertEquals([revid1, revid2, revid3], trunk.revision_history())
558         self.client_update("dc")
559         self.assertEquals(
560                 '1 initialrevid\n2 changerevid\n3 mergerevid\n',
561                 self.client_get_prop("dc/branches/foo", SVN_PROP_BZR_REVISION_ID+"trunk0"))
562
563     def test_complex_replace_dir(self):
564         repos_url = self.make_client("a", "dc")
565         bzrwt = BzrDir.create_standalone_workingtree("c", 
566             format=format.get_rich_root_format())
567         self.build_tree({'c/registry/generic.c': "Tour"})
568         bzrwt.add(["registry"], ["origdir"])
569         bzrwt.add(["registry/generic.c"], ["file"])
570         revid1 = bzrwt.commit("Add initial directory + file")
571
572         bzrwt.remove('registry/generic.c')
573         bzrwt.remove('registry')
574         bzrwt.add(["registry"], ["newdir"])
575         bzrwt.add(["registry/generic.c"], ["file"])
576         revid2 = bzrwt.commit("Do some funky things")
577
578         newdir = BzrDir.open(repos_url+"/trunk")
579         newbranch = newdir.import_branch(bzrwt.branch)
580         self.assertEquals(revid2, newbranch.last_revision())
581         self.assertEquals([revid1, revid2], newbranch.revision_history())
582
583         os.mkdir("n")
584         BzrDir.open(repos_url+"/trunk").sprout("n")
585
586     def test_push_unnecessary_merge(self):        
587         from bzrlib.debug import debug_flags
588         debug_flags.add('transport')
589         debug_flags.add('commit')
590         repos_url = self.make_client("a", "dc")
591         bzrwt = BzrDir.create_standalone_workingtree("c", 
592             format=format.get_rich_root_format())
593         self.build_tree({'c/registry/generic.c': "Tour"})
594         bzrwt.add("registry")
595         bzrwt.add("registry/generic.c")
596         revid1 = bzrwt.commit("Add initial directory + file", 
597                               rev_id="initialrevid")
598
599         # Push first branch into Subversion
600         newdir = BzrDir.open(repos_url+"/trunk")
601         newbranch = newdir.import_branch(bzrwt.branch)
602
603         # Should create dc/trunk
604         self.client_update("dc")
605
606         self.assertTrue(os.path.exists("dc/trunk/registry/generic.c"))
607         sleep(1) # Subversion relies on timestamps to detect 
608                  # changed files...
609         self.build_tree({'dc/trunk/registry/generic.c': "BLA"})
610         self.client_commit("dc/trunk", "Change copied branch")
611         self.client_update("dc")
612         merge_revid = newdir.find_repository().generate_revision_id(2, "trunk", "trunk0")
613
614         # Merge 
615         self.build_tree({'c/registry/generic.c': "DE"})
616         bzrwt.add_pending_merge(merge_revid)
617         revid2 = bzrwt.commit("Merge something", rev_id="mergerevid")
618
619         trunk = Branch.open(repos_url + "/trunk")
620         trunk.pull(bzrwt.branch)
621
622         self.assertEquals([revid1, revid2], trunk.revision_history())
623         self.client_update("dc")
624         self.assertEquals(
625                 '1 initialrevid\n2 mergerevid\n',
626                 self.client_get_prop("dc/trunk", SVN_PROP_BZR_REVISION_ID+"trunk0"))
627
628