~ubuntu-branches/ubuntu/raring/bzr-svn/raring

« back to all changes in this revision

Viewing changes to tests/test_branch.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-30 23:14:36 UTC
  • mfrom: (1.1.28 upstream) (3.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100730231436-po8j0ibgjn2d6hy0
Tags: 1.0.3-1
* New upstream release.
 + Provides BranchConfig._get_change_editor. Closes: #572109
 + Supports more trunk layout levels. Closes: #573988
* Bump standards version to 3.9.1.
* Mark as supporting bzr 2.2.
* Suggest bzr-rewrite rather than bzr-rebase. LP: #481730

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib import urlutils
23
23
from bzrlib.branch import (
24
24
    Branch,
 
25
    InterBranch,
25
26
    )
26
27
from bzrlib.bzrdir import (
27
28
    BzrDir,
52
53
        repos_url = self.make_repository("a")
53
54
        branch = Branch.open(repos_url)
54
55
        branch.revision_history()
55
 
        self.assertEqual(branch.generate_revision_id(0), branch.last_revision())
 
56
        self.assertEqual(branch.generate_revision_id(0),
 
57
                         branch.last_revision())
56
58
 
57
59
    def test_get_branch_path_root(self):
58
60
        repos_url = self.make_repository("a")
111
113
        b.tags.set_tag(u"mytag",
112
114
            b.repository.generate_revision_id(1, "trunk", b.repository.get_mapping()))
113
115
 
114
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
116
        self.assertEquals(subvertpy.NODE_DIR,
115
117
                b.repository.transport.check_path("tags/mytag", 3))
116
118
 
117
119
    def test_tag_set_dupe(self):
131
133
        target = b.repository.generate_revision_id(1, "trunk", b.repository.get_mapping())
132
134
        b.tags.set_tag(u"mytag", b.repository.generate_revision_id(1, "trunk", b.repository.get_mapping()))
133
135
 
134
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
136
        self.assertEquals(subvertpy.NODE_DIR,
135
137
                b.repository.transport.check_path("tags/mytag", 3))
136
138
        self.assertEquals(3, b.repository.get_latest_revnum())
137
139
 
157
159
        b = Branch.open(repos_url + "/trunk")
158
160
        b.tags.set_tag(u"mytag", b.repository.generate_revision_id(1, "trunk", b.repository.get_mapping()))
159
161
 
160
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
162
        self.assertEquals(subvertpy.NODE_DIR,
161
163
                b.repository.transport.check_path("tags/mytag", 3))
162
164
        self.assertEquals(3, b.repository.get_latest_revnum())
163
165
 
168
170
        newtagrevid = b.repository.generate_revision_id(2, "trunk", b.repository.get_mapping())
169
171
        b.tags.set_tag(u"mytag", newtagrevid)
170
172
 
171
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
173
        self.assertEquals(subvertpy.NODE_DIR,
172
174
                b.repository.transport.check_path("tags/mytag", 4))
173
175
        self.assertEquals(4, b.repository.get_latest_revnum())
174
176
        b = Branch.open(repos_url + "/trunk")
175
177
        log = self.client_log(repos_url, 4, 0)
176
178
        self.assertEquals(log[0][0], None)
177
 
        self.assertEquals(log[1][0], {'/tags': ('A', None, -1), 
 
179
        self.assertEquals(log[1][0], {'/tags': ('A', None, -1),
178
180
                                      '/trunk': ('A', None, -1)})
179
181
        self.assertEquals(log[2][0], {'/trunk/bla': ('A', None, -1)})
180
182
        self.assertEquals(log[3][0], {'/tags/mytag': ('A', '/trunk', 1)})
184
186
 
185
187
    def test_tags_delete(self):
186
188
        repos_url = self.make_repository("a")
187
 
       
 
189
 
188
190
        dc = self.get_commit_editor(repos_url)
189
191
        tags = dc.add_dir("tags")
190
192
        tags.add_dir("tags/foo")
197
199
        b = Branch.open(repos_url + "/trunk")
198
200
        self.assertEquals([], b.tags.get_tag_dict().keys())
199
201
 
200
 
    def test_tag_set_no_parent_Dir(self):
 
202
    def test_tag_set_no_parent_dir(self):
201
203
        repos_url = self.make_repository('a')
202
204
 
203
205
        dc = self.get_commit_editor(repos_url)
211
213
 
212
214
        b = Branch.open(repos_url + "/trunk")
213
215
        b.tags.set_tag(u"mytag",
214
 
            b.repository.generate_revision_id(1, "trunk", b.repository.get_mapping()))
 
216
            b.repository.generate_revision_id(1, "trunk",
 
217
                b.repository.get_mapping()))
215
218
 
216
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
219
        self.assertEquals(subvertpy.NODE_DIR,
217
220
                b.repository.transport.check_path("tags", 3))
218
221
 
219
 
        self.assertEquals(subvertpy.NODE_DIR, 
 
222
        self.assertEquals(subvertpy.NODE_DIR,
220
223
                b.repository.transport.check_path("tags/mytag", 4))
221
224
        self.assertEquals(4, b.repository.get_latest_revnum())
222
225
 
230
233
 
231
234
        b = Branch.open(repos_url + "/trunk/gui")
232
235
        self.assertRaises(TagsNotSupported,
233
 
                b.tags.set_tag, u"mytag", 
234
 
                b.repository.generate_revision_id(1, "trunk/gui", b.repository.get_mapping()))
 
236
            b.tags.set_tag, u"mytag",
 
237
            b.repository.generate_revision_id(1, "trunk/gui",
 
238
                b.repository.get_mapping()))
235
239
 
236
240
    def test_tag_lookup(self):
237
241
        repos_url = self.make_repository("a")
238
 
       
 
242
 
239
243
        dc = self.get_commit_editor(repos_url)
240
244
        tags = dc.add_dir("tags")
241
245
        tags.add_dir("tags/foo")
244
248
 
245
249
        b = Branch.open(repos_url + "/trunk")
246
250
        self.assertEquals("", b.project)
247
 
        self.assertEquals(b.repository.generate_revision_id(1, "tags/foo", b.repository.get_mapping()), b.tags.lookup_tag("foo"))
 
251
        self.assertEquals(
 
252
            b.repository.generate_revision_id(1, "tags/foo",
 
253
                b.repository.get_mapping()),
 
254
            b.tags.lookup_tag("foo"))
248
255
 
249
256
    def test_tag_lookup_nonexistant(self):
250
257
        repos_url = self.make_repository("a")
252
259
        dc = self.get_commit_editor(repos_url)
253
260
        dc.add_dir("trunk")
254
261
        dc.close()
255
 
       
 
262
 
256
263
        b = Branch.open(repos_url + "/trunk")
257
264
        self.assertRaises(NoSuchTag, b.tags.lookup_tag, "foo")
258
265
 
262
269
        dc = self.get_commit_editor(repos_url)
263
270
        dc.add_dir("trunk")
264
271
        dc.close()
265
 
       
 
272
 
266
273
        b = Branch.open(repos_url + "/trunk")
267
274
        self.assertRaises(NoSuchTag, b.tags.delete_tag, u"foo")
268
275
 
305
312
        self.assertEquals(result.source_branch, otherbranch)
306
313
        self.assertEquals(result.target_branch, branch)
307
314
 
 
315
    def make_tworev_branch(self):
 
316
        repos_url = self.make_repository("a")
 
317
 
 
318
        dc = self.get_commit_editor(repos_url)
 
319
        dc.add_file('foo')
 
320
        dc.close()
 
321
 
 
322
        b = Branch.open(repos_url)
 
323
        mapping = b.repository.get_mapping()
 
324
        uuid = b.repository.uuid
 
325
        revid1 = mapping.revision_id_foreign_to_bzr((uuid, '', 0))
 
326
        revid2 = mapping.revision_id_foreign_to_bzr((uuid, '', 1))
 
327
        return b, (revid1, revid2)
 
328
 
 
329
    def make_branch(self, relpath):
 
330
        # The inherited make_branch is broken, thanks to the make_repository
 
331
        # from subvertpy.
 
332
        bzrdir = self.make_bzrdir(relpath)
 
333
        bzrdir._find_or_create_repository(True)
 
334
        return bzrdir.create_branch()
 
335
 
 
336
    def test_interbranch_pull(self):
 
337
        svn_branch, (revid1, revid2) = self.make_tworev_branch()
 
338
        new_branch = self.make_branch("b")
 
339
        inter_branch = InterBranch.get(svn_branch, new_branch)
 
340
        inter_branch.pull()
 
341
        self.assertEquals(revid2, new_branch.last_revision())
 
342
 
 
343
    def test_interbranch_pull_noop(self):
 
344
        svn_branch, (revid1, revid2) = self.make_tworev_branch()
 
345
        new_branch = self.make_branch("b")
 
346
        inter_branch = InterBranch.get(svn_branch, new_branch)
 
347
        inter_branch.pull()
 
348
        # This is basically "assertNotRaises"
 
349
        inter_branch.pull()
 
350
        self.assertEquals(revid2, new_branch.last_revision())
 
351
 
 
352
    def test_interbranch_pull_stop_revision(self):
 
353
        svn_branch, (revid1, revid2) = self.make_tworev_branch()
 
354
        new_branch = self.make_branch("b")
 
355
        inter_branch = InterBranch.get(svn_branch, new_branch)
 
356
        inter_branch.pull(stop_revision=revid1)
 
357
        self.assertEquals(revid1, new_branch.last_revision())
 
358
 
 
359
    def test_interbranch_limited_pull(self):
 
360
        svn_branch, (revid1, revid2) = self.make_tworev_branch()
 
361
        new_branch = self.make_branch("b")
 
362
        inter_branch = InterBranch.get(svn_branch, new_branch)
 
363
        inter_branch.pull(limit=1)
 
364
        self.assertEquals(revid1, new_branch.last_revision())
 
365
        inter_branch.pull(limit=1)
 
366
        self.assertEquals(revid2, new_branch.last_revision())
 
367
 
 
368
    def test_interbranch_limited_overwrite(self):
 
369
        svn_branch, (revid1, revid2) = self.make_tworev_branch()
 
370
        new_branch = self.make_branch("b")
 
371
        inter_branch = InterBranch.get(svn_branch, new_branch)
 
372
        inter_branch.pull(limit=2)
 
373
        self.assertEquals(revid2, new_branch.last_revision())
 
374
        inter_branch.pull(limit=1, stop_revision=revid1)
 
375
        self.assertEquals(revid2, new_branch.last_revision())
 
376
        inter_branch.pull(limit=1, overwrite=True, stop_revision=revid1)
 
377
        self.assertEquals(revid1, new_branch.last_revision())
 
378
 
308
379
    def test_get_branch_path_subdir(self):
309
380
        repos_url = self.make_repository("a")
310
381
 
315
386
        branch = Branch.open(repos_url+"/trunk")
316
387
        self.assertEqual("trunk", branch.get_branch_path())
317
388
 
 
389
    def test_tag_added_later(self):
 
390
        repos_url = self.make_repository("a")
 
391
 
 
392
        dc = self.get_commit_editor(repos_url)
 
393
        dc.add_dir("trunk")
 
394
        dc.close()
 
395
 
 
396
        olddir = BzrDir.open(repos_url+"/trunk")
 
397
        oldbranch = olddir.open_branch()
 
398
        newdir = olddir.sprout("mycopy")
 
399
        newbranch = newdir.open_branch()
 
400
        self.assertEquals({}, newbranch.tags.get_tag_dict())
 
401
 
 
402
        dc = self.get_commit_editor(repos_url)
 
403
        tags = dc.add_dir("tags")
 
404
        new_tag = tags.add_dir("tags/newtag", "trunk")
 
405
        dc.close()
 
406
 
 
407
        self.assertEquals(1, oldbranch.get_revnum())
 
408
        newbranch.pull(oldbranch, stop_revision=oldbranch.last_revision())
 
409
 
 
410
        self.assertEquals(["newtag"], newbranch.tags.get_tag_dict().keys())
 
411
 
318
412
    def test_open_nonexistant(self):
319
413
        repos_url = self.make_repository("a")
320
414
        self.assertRaises(NotBranchError, Branch.open, repos_url + "/trunk")
331
425
    def test_lookup_revision_id_unknown(self):
332
426
        repos_url = self.make_repository("a")
333
427
        branch = Branch.open(repos_url)
334
 
        self.assertRaises(NoSuchRevision, 
 
428
        self.assertRaises(NoSuchRevision,
335
429
                lambda: branch.lookup_bzr_revision_id("bla"))
336
430
 
337
431
    def test_lookup_revision_id(self):
338
432
        repos_url = self.make_repository("a")
339
433
        branch = Branch.open(repos_url)
340
 
        self.assertEquals(0, 
 
434
        self.assertEquals(0,
341
435
                branch.lookup_bzr_revision_id(branch.last_revision()))
342
436
 
343
437
    def test_set_parent(self):
355
449
        dc = self.get_commit_editor(repos_url)
356
450
        dc.add_file("foo").modify()
357
451
        dc.close()
358
 
        
 
452
 
359
453
        bzrdir = BzrDir.open(repos_url)
360
454
        branch = bzrdir.open_branch()
361
455
        repos = bzrdir.find_repository()
362
 
        
 
456
 
363
457
        mapping = repos.get_mapping()
364
458
 
365
 
        self.assertEqual(repos.generate_revision_id(1, "", mapping), 
 
459
        self.assertEqual(repos.generate_revision_id(1, "", mapping),
366
460
                branch.last_revision())
367
461
 
368
462
        dc = self.get_commit_editor(repos_url)
458
552
        repos_url = self.make_repository('a')
459
553
        branch = Branch.open(repos_url)
460
554
        self.assertRaises(NoSuchRevision, branch.revision_id_to_revno, "bla")
461
 
    
 
555
 
462
556
    def test_get_nick_none(self):
463
557
        repos_url = self.make_repository('a')
464
558
 
486
580
 
487
581
        dc = self.get_commit_editor(repos_url)
488
582
        dc.add_file("foo").modify()
489
 
        dc.change_prop("bzr:revision-info", 
 
583
        dc.change_prop("bzr:revision-info",
490
584
                "properties: \n\tbranch-nick: mybranch\n")
491
585
        dc.close()
492
586
 
734
828
 
735
829
        host_fileid = tree.inventory.path2id("hosts")
736
830
 
737
 
        self.assertVersionsPresentEquals(newbranch.repository.texts, 
 
831
        self.assertVersionsPresentEquals(newbranch.repository.texts,
738
832
                                        host_fileid, [
739
833
            oldbranch.generate_revision_id(6),
740
834
            oldbranch.generate_revision_id(7)])
741
835
        newbranch.unlock()
742
 
 
 
836
 
743
837
 
744
838
    def test_fetch_odd(self):
745
839
        repos_url = self.make_repository('d')
807
901
        self.make_repository('d')
808
902
        branch = Branch.open('d')
809
903
        result = branch.check()
810
 
        self.assertEqual(branch, result.branch) 
811
 
 
 
904
        self.assertEqual(branch, result.branch)
 
905
 
812
906
    def test_generate_revision_id(self):
813
907
        repos_url = self.make_repository('d')
814
908
 
887
981
        olddir = BzrDir.open("sc")
888
982
 
889
983
        os.mkdir("dc")
890
 
        
 
984
 
891
985
        newdir = olddir.sprout('dc')
892
986
 
893
987
        self.assertEqual(
913
1007
        olddir = BzrDir.open("sc/branches/abranch")
914
1008
 
915
1009
        os.mkdir("dc")
916
 
        
 
1010
 
917
1011
        newdir = olddir.sprout('dc')
918
1012
 
919
1013
        self.assertEqual(
939
1033
        olddir = BzrDir.open("sc/trunk")
940
1034
 
941
1035
        os.mkdir("dc")
942
 
        
 
1036
 
943
1037
        newdir = olddir.sprout('dc')
944
1038
 
945
1039
        self.assertEqual(
949
1043
 
950
1044
 
951
1045
    def test_ghost_workingtree(self):
952
 
        # Looks like bazaar has trouble creating a working tree of a 
 
1046
        # Looks like bazaar has trouble creating a working tree of a
953
1047
        # revision that has ghost parents
954
1048
        repos_url = self.make_client('d', 'sc')
955
1049
 
962
1056
        olddir = BzrDir.open("sc")
963
1057
 
964
1058
        os.mkdir("dc")
965
 
        
 
1059
 
966
1060
        newdir = olddir.sprout('dc')
967
1061
        newdir.find_repository().get_revision(
968
1062
                newdir.open_branch().last_revision())
969
 
        newdir.find_repository().get_revision_inventory(
 
1063
        newdir.find_repository().get_inventory(
970
1064
                newdir.open_branch().last_revision())
971
1065
 
972
1066
 
980
1074
        self.assertRaises(NotImplementedError, self.format.initialize, None)
981
1075
 
982
1076
    def test_get_format_string(self):
983
 
        self.assertEqual("Subversion Smart Server", 
 
1077
        self.assertEqual("Subversion Smart Server",
984
1078
                         self.format.get_format_string())
985
1079
 
986
1080
    def test_get_format_description(self):
987
 
        self.assertEqual("Subversion Smart Server", 
 
1081
        self.assertEqual("Subversion Smart Server",
988
1082
                         self.format.get_format_description())
989
1083
 
990
1084
 
991
1085
class ForeignTestsBranchFactory(object):
992
1086
 
993
1087
    def make_empty_branch(self, transport):
994
 
        raise TestSkipped
 
1088
        raise TestSkipped()
995
1089
 
996
1090
    def make_branch(self, transport):
997
1091
        subvertpy.repos.create(transport.local_abspath("."))