Raise error when trying to change repository root, add test for bug 118787.
[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         merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
348         merge.merge_type = Merge3Merger
349         merge.do_merge()
350         self.assertEquals(base_revid, merge.base_rev_id)
351         merge.set_pending()
352         self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
353         wt.commit("merge", rev_id="mymerge")
354         self.assertTrue(os.path.exists("bzrco/baz.txt"))
355         raise KnownFailure("can't work for repository root")
356         wt.branch.push(Branch.open(repos_url))
357
358     def test_push_replace_existing_branch(self):
359         repos_url = self.make_client("test", "svnco")
360         self.build_tree({'svnco/trunk/foo.txt': 'foo'})
361         self.client_add("svnco/trunk")
362         self.client_commit("svnco", "add file") #1
363         self.client_update("svnco")
364
365         os.mkdir('bzrco')
366         dir = BzrDir.open(repos_url+"/trunk").sprout("bzrco")
367         wt = dir.open_workingtree()
368         self.build_tree({'bzrco/bar.txt': 'bar'})
369         wt.add("bar.txt")
370         base_revid = wt.commit("add another file", rev_id="mybase")
371         wt.branch.push(Branch.open(repos_url+"/trunk"))
372
373         self.build_tree({"svnco/trunk/baz.txt": "baz"})
374         self.client_add("svnco/trunk/baz.txt")
375         self.assertEquals(3, 
376                 self.client_commit("svnco", "add yet another file")[0])
377         self.client_update("svnco")
378
379         self.build_tree({"bzrco/qux.txt": "qux"})
380         wt.add("qux.txt")
381         wt.commit("add still more files", rev_id="mydiver")
382
383         repos = Repository.open(repos_url)
384         wt.branch.repository.fetch(repos)
385         other_rev = repos.generate_revision_id(3, "trunk", "trunk0")
386         merge = Merger.from_revision_ids(DummyProgress(), wt, other=other_rev)
387         merge.merge_type = Merge3Merger
388         merge.do_merge()
389         self.assertEquals(base_revid, merge.base_rev_id)
390         merge.set_pending()
391         self.assertEquals([wt.last_revision(), other_rev], wt.get_parent_ids())
392         wt.commit("merge", rev_id="mymerge")
393         self.assertTrue(os.path.exists("bzrco/baz.txt"))
394         wt.branch.push(Branch.open(repos_url+"/trunk"))
395
396
397
398     def test_repeat(self):
399         repos_url = self.make_client("a", "dc")
400         bzrwt = BzrDir.create_standalone_workingtree("c", 
401             format=format.get_rich_root_format())
402         self.build_tree({'c/test': "Tour"})
403         bzrwt.add("test")
404         revid = bzrwt.commit("Do a commit")
405         newdir = BzrDir.open(repos_url+"/trunk")
406         newbranch = newdir.import_branch(bzrwt.branch)
407         self.assertEquals(revid, newbranch.last_revision())
408         self.assertEquals([revid], newbranch.revision_history())
409         self.build_tree({'c/test': "Tour de France"})
410         bzrwt.commit("Do a commit")
411         newdir = BzrDir.open(repos_url+"/trunk")
412         self.assertRaises(AlreadyBranchError, newdir.import_branch, 
413                           bzrwt.branch)
414
415     def test_multiple(self):
416         repos_url = self.make_client("a", "dc")
417         bzrwt = BzrDir.create_standalone_workingtree("c", 
418             format=format.get_rich_root_format())
419         self.build_tree({'c/test': "Tour"})
420         bzrwt.add("test")
421         revid1 = bzrwt.commit("Do a commit")
422         self.build_tree({'c/test': "Tour de France"})
423         revid2 = bzrwt.commit("Do a commit")
424         newdir = BzrDir.open(repos_url+"/trunk")
425         newbranch = newdir.import_branch(bzrwt.branch)
426         self.assertEquals(revid2, newbranch.last_revision())
427         self.assertEquals([revid1, revid2], newbranch.revision_history())
428
429     def test_multiple_part_exists(self):
430         repos_url = self.make_client("a", "dc")
431         self.build_tree({'dc/trunk/myfile': "data", 'dc/branches': None})
432         self.client_add('dc/trunk')
433         self.client_add('dc/branches')
434         self.client_commit("dc", "Message")
435         svnrepos = Repository.open(repos_url)
436         os.mkdir("c")
437         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("c")
438         bzrwt = bzrdir.open_workingtree()
439         self.build_tree({'c/myfile': "Tour"})
440         revid1 = bzrwt.commit("Do a commit")
441         self.build_tree({'c/myfile': "Tour de France"})
442         revid2 = bzrwt.commit("Do a commit")
443         newdir = BzrDir.open(repos_url+"/branches/mybranch")
444         newbranch = newdir.import_branch(bzrwt.branch)
445         self.assertEquals(revid2, newbranch.last_revision())
446         self.assertEquals([
447             svnrepos.generate_revision_id(1, "trunk", "trunk0") 
448             , revid1, revid2], newbranch.revision_history())
449
450     def test_push_overwrite(self):
451         repos_url = self.make_client("a", "dc")
452         self.build_tree({'dc/trunk/bloe': "text"})
453         self.client_add("dc/trunk")
454         self.client_commit("dc", "initial")
455
456         os.mkdir("d1")
457         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d1")
458         bzrwt1 = bzrdir.open_workingtree()
459
460         os.mkdir("d2")
461         bzrdir = BzrDir.open(repos_url+"/trunk").sprout("d2")
462         bzrwt2 = bzrdir.open_workingtree()
463
464         self.build_tree({'d1/myfile': "Tour"})
465         bzrwt1.add("myfile")
466         revid1 = bzrwt1.commit("Do a commit")
467
468         self.build_tree({'d2/myfile': "France"})
469         bzrwt2.add("myfile")
470         revid2 = bzrwt1.commit("Do a commit")
471
472         bzrwt1.branch.push(Branch.open(repos_url+"/trunk"))
473
474         raise KnownFailure("push --overwrite not supported yet")
475
476         bzrwt2.branch.push(Branch.open(repos_url+"/trunk"), overwrite=True)
477
478         self.assertEquals([revid2], 
479                 Branch.open(repos_url+"/trunk").revision_history())
480
481     def test_complex_rename(self):
482         repos_url = self.make_client("a", "dc")
483         bzrwt = BzrDir.create_standalone_workingtree("c", 
484             format=format.get_rich_root_format())
485         self.build_tree({'c/registry/generic.c': "Tour"})
486         bzrwt.add("registry")
487         bzrwt.add("registry/generic.c")
488         revid1 = bzrwt.commit("Add initial directory + file")
489         bzrwt.rename_one("registry", "registry.moved")
490         os.unlink("c/registry.moved/generic.c")
491         bzrwt.remove("registry.moved/generic.c")
492         self.build_tree({'c/registry/generic.c': "bla"})
493         bzrwt.add("registry")
494         bzrwt.add("registry/generic.c")
495         revid2 = bzrwt.commit("Do some funky things")
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())
500         tree = newbranch.repository.revision_tree(revid2)
501         mutter("inventory: %r" % tree.inventory.entries())
502         delta = tree.changes_from(bzrwt)
503         self.assertFalse(delta.has_changed())
504         self.assertTrue(tree.inventory.has_filename("registry"))
505         self.assertTrue(tree.inventory.has_filename("registry.moved"))
506         self.assertTrue(tree.inventory.has_filename("registry/generic.c"))
507         self.assertFalse(tree.inventory.has_filename("registry.moved/generic.c"))
508         os.mkdir("n")
509         BzrDir.open(repos_url+"/trunk").sprout("n")
510     
511     def test_push_non_lhs_parent(self):        
512         repos_url = self.make_client("a", "dc")
513         bzrwt = BzrDir.create_standalone_workingtree("c", 
514             format=format.get_rich_root_format())
515         self.build_tree({'c/registry/generic.c': "Tour"})
516         bzrwt.add("registry")
517         bzrwt.add("registry/generic.c")
518         revid1 = bzrwt.commit("Add initial directory + file", 
519                               rev_id="initialrevid")
520
521         # Push first branch into Subversion
522         newdir = BzrDir.open(repos_url+"/trunk")
523         newbranch = newdir.import_branch(bzrwt.branch)
524
525         # Should create dc/trunk
526         self.client_update("dc")
527
528         self.build_tree({'dc/branches': None})
529         self.client_add("dc/branches")
530         self.client_copy("dc/trunk", "dc/branches/foo")
531         self.client_commit("dc", "Copy branches")
532         self.client_update("dc")
533
534         self.build_tree({'dc/branches/foo/registry/generic.c': "France"})
535         merge_revno = self.client_commit("dc", "Change copied branch")[0]
536         merge_revid = newdir.find_repository().generate_revision_id(merge_revno, "branches/foo", "trunk0")
537
538         self.build_tree({'c/registry/generic.c': "de"})
539         revid2 = bzrwt.commit("Change something", rev_id="changerevid")
540
541         # Merge 
542         self.build_tree({'c/registry/generic.c': "France"})
543         bzrwt.add_pending_merge(merge_revid)
544         revid3 = bzrwt.commit("Merge something", rev_id="mergerevid")
545
546         trunk = Branch.open(repos_url + "/branches/foo")
547         trunk.pull(bzrwt.branch)
548
549         self.assertEquals([revid1, revid2, revid3], trunk.revision_history())
550         self.client_update("dc")
551         self.assertEquals(
552                 '1 initialrevid\n2 changerevid\n3 mergerevid\n',
553                 self.client_get_prop("dc/branches/foo", SVN_PROP_BZR_REVISION_ID+"trunk0"))
554
555     def test_complex_replace_dir(self):
556         repos_url = self.make_client("a", "dc")
557         bzrwt = BzrDir.create_standalone_workingtree("c", 
558             format=format.get_rich_root_format())
559         self.build_tree({'c/registry/generic.c': "Tour"})
560         bzrwt.add(["registry"], ["origdir"])
561         bzrwt.add(["registry/generic.c"], ["file"])
562         revid1 = bzrwt.commit("Add initial directory + file")
563
564         bzrwt.remove('registry/generic.c')
565         bzrwt.remove('registry')
566         bzrwt.add(["registry"], ["newdir"])
567         bzrwt.add(["registry/generic.c"], ["file"])
568         revid2 = bzrwt.commit("Do some funky things")
569
570         newdir = BzrDir.open(repos_url+"/trunk")
571         newbranch = newdir.import_branch(bzrwt.branch)
572         self.assertEquals(revid2, newbranch.last_revision())
573         self.assertEquals([revid1, revid2], newbranch.revision_history())
574
575         os.mkdir("n")
576         BzrDir.open(repos_url+"/trunk").sprout("n")
577
578     def test_push_unnecessary_merge(self):        
579         from bzrlib.debug import debug_flags
580         debug_flags.add('transport')
581         debug_flags.add('commit')
582         repos_url = self.make_client("a", "dc")
583         bzrwt = BzrDir.create_standalone_workingtree("c", 
584             format=format.get_rich_root_format())
585         self.build_tree({'c/registry/generic.c': "Tour"})
586         bzrwt.add("registry")
587         bzrwt.add("registry/generic.c")
588         revid1 = bzrwt.commit("Add initial directory + file", 
589                               rev_id="initialrevid")
590
591         # Push first branch into Subversion
592         newdir = BzrDir.open(repos_url+"/trunk")
593         newbranch = newdir.import_branch(bzrwt.branch)
594
595         # Should create dc/trunk
596         self.client_update("dc")
597
598         self.assertTrue(os.path.exists("dc/trunk/registry/generic.c"))
599         sleep(1) # Subversion relies on timestamps to detect 
600                  # changed files...
601         self.build_tree({'dc/trunk/registry/generic.c': "BLA"})
602         self.client_commit("dc/trunk", "Change copied branch")
603         self.client_update("dc")
604         merge_revid = newdir.find_repository().generate_revision_id(2, "trunk", "trunk0")
605
606         # Merge 
607         self.build_tree({'c/registry/generic.c': "DE"})
608         bzrwt.add_pending_merge(merge_revid)
609         revid2 = bzrwt.commit("Merge something", rev_id="mergerevid")
610
611         trunk = Branch.open(repos_url + "/trunk")
612         trunk.pull(bzrwt.branch)
613
614         self.assertEquals([revid1, revid2], trunk.revision_history())
615         self.client_update("dc")
616         self.assertEquals(
617                 '1 initialrevid\n2 mergerevid\n',
618                 self.client_get_prop("dc/trunk", SVN_PROP_BZR_REVISION_ID+"trunk0"))
619
620