/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_workingtree/test_workingtree.py

Merge tree reference fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
 
22
22
from ... import (
23
 
    branch,
 
23
    branch as _mod_branch,
24
24
    config,
25
25
    controldir,
26
26
    errors,
 
27
    merge,
27
28
    osutils,
28
29
    revision as _mod_revision,
29
30
    tests,
79
80
    def test_branch_builder(self):
80
81
        # Just a smoke test that we get a branch at the specified relpath
81
82
        builder = self.make_branch_builder('foobar')
82
 
        br = branch.Branch.open(self.get_url('foobar'))
 
83
        br = _mod_branch.Branch.open(self.get_url('foobar'))
83
84
 
84
85
    def test_list_files(self):
85
86
        tree = self.make_branch_and_tree('.')
299
300
    def test_initialize(self):
300
301
        # initialize should create a working tree and branch in an existing dir
301
302
        t = self.make_branch_and_tree('.')
302
 
        b = branch.Branch.open('.')
 
303
        b = _mod_branch.Branch.open('.')
303
304
        self.assertEqual(t.branch.base, b.base)
304
305
        t2 = WorkingTree.open('.')
305
306
        self.assertEqual(t.basedir, t2.basedir)
1329
1330
        self.assertSubset(
1330
1331
            [self.workingtree_format.supports_store_uncommitted],
1331
1332
            (True, False))
 
1333
 
 
1334
 
 
1335
class TestReferenceLocation(TestCaseWithWorkingTree):
 
1336
 
 
1337
    def test_reference_parent(self):
 
1338
        tree = self.make_branch_and_tree('tree')
 
1339
        subtree = self.make_branch_and_tree('tree/subtree')
 
1340
        subtree.commit('a change')
 
1341
        try:
 
1342
            tree.add_reference(subtree)
 
1343
        except errors.UnsupportedOperation:
 
1344
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
1345
        if not getattr(tree.branch._format, 'supports_reference_locations', False):
 
1346
            raise tests.TestNotApplicable('Branch cannot hold reference locations.')
 
1347
        tree.commit('Add reference.')
 
1348
        reference_parent = tree.reference_parent(
 
1349
            urlutils.relative_url(
 
1350
                urlutils.strip_segment_parameters(tree.branch.user_url),
 
1351
                urlutils.strip_segment_parameters(subtree.branch.user_url)))
 
1352
        self.assertEqual(subtree.branch.user_url, reference_parent.user_url)
 
1353
 
 
1354
    def test_reference_parent_accepts_possible_transports(self):
 
1355
        tree = self.make_branch_and_tree('tree')
 
1356
        subtree = self.make_branch_and_tree('tree/subtree')
 
1357
        subtree.commit('a change')
 
1358
        try:
 
1359
            tree.add_reference(subtree)
 
1360
        except errors.UnsupportedOperation:
 
1361
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
1362
        if not getattr(tree.branch._format, 'supports_reference_locations', False):
 
1363
            raise tests.TestNotApplicable('Branch cannot hold reference locations.')
 
1364
        tree.commit('Add reference')
 
1365
        reference_parent = tree.reference_parent(
 
1366
            urlutils.relative_url(
 
1367
                urlutils.strip_segment_parameters(tree.branch.user_url),
 
1368
                urlutils.strip_segment_parameters(subtree.branch.user_url)),
 
1369
            possible_transports=[subtree.controldir.root_transport])
 
1370
 
 
1371
    def test_get_reference_info(self):
 
1372
        tree = self.make_branch_and_tree('branch')
 
1373
        try:
 
1374
            loc = tree.get_reference_info('file')
 
1375
        except errors.UnsupportedOperation:
 
1376
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
1377
        self.assertIs(None, loc)
 
1378
 
 
1379
    def test_set_reference_info(self):
 
1380
        self.make_tree_with_reference('branch', 'path/to/location')
 
1381
 
 
1382
    def test_set_get_reference_info(self):
 
1383
        tree = self.make_tree_with_reference('branch', 'path/to/location')
 
1384
        # Create a new instance to ensure storage is permanent
 
1385
        tree = WorkingTree.open('branch')
 
1386
        branch_location = tree.get_reference_info('path/to/file')
 
1387
        self.assertEqual(
 
1388
            urlutils.local_path_to_url('branch/path/to/location'),
 
1389
            urlutils.join(tree.branch.user_url, branch_location))
 
1390
 
 
1391
    def test_set_null_reference_info(self):
 
1392
        tree = self.make_branch_and_tree('branch')
 
1393
        self.build_tree(['branch/file'])
 
1394
        tree.add(['file'])
 
1395
        try:
 
1396
            tree.set_reference_info('file', 'path/to/location')
 
1397
        except errors.UnsupportedOperation:
 
1398
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
1399
        tree.set_reference_info('file', None)
 
1400
        branch_location = tree.get_reference_info('file')
 
1401
        self.assertIs(None, branch_location)
 
1402
 
 
1403
    def test_set_null_reference_info_when_null(self):
 
1404
        tree = self.make_branch_and_tree('branch')
 
1405
        try:
 
1406
            branch_location = tree.get_reference_info('file')
 
1407
        except errors.UnsupportedOperation:
 
1408
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
1409
        self.assertIs(None, branch_location)
 
1410
        self.build_tree(['branch/file'])
 
1411
        tree.add(['file'])
 
1412
        try:
 
1413
            tree.set_reference_info('file', None)
 
1414
        except errors.UnsupportedOperation:
 
1415
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
1416
 
 
1417
    def make_tree_with_reference(self, location, reference_location):
 
1418
        tree = self.make_branch_and_tree(location)
 
1419
        self.build_tree(
 
1420
            [os.path.join(location, name)
 
1421
             for name in ['path/', 'path/to/', 'path/to/file']])
 
1422
        tree.add(['path', 'path/to', 'path/to/file'])
 
1423
        try:
 
1424
            tree.set_reference_info('path/to/file', reference_location)
 
1425
        except errors.UnsupportedOperation:
 
1426
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
1427
        tree.commit('commit reference')
 
1428
        return tree
 
1429
 
 
1430
    def test_reference_parent_from_reference_info_(self):
 
1431
        referenced_branch = self.make_branch('reference_branch')
 
1432
        tree = self.make_tree_with_reference('branch', referenced_branch.base)
 
1433
        parent = tree.reference_parent('path/to/file')
 
1434
        self.assertEqual(parent.base, referenced_branch.base)
 
1435
 
 
1436
    def test_branch_relative_reference_location(self):
 
1437
        tree = self.make_tree_with_reference('branch', '../reference_branch')
 
1438
        referenced_branch = self.make_branch('reference_branch')
 
1439
        parent = tree.reference_parent('path/to/file')
 
1440
        self.assertEqual(parent.base, referenced_branch.base)
 
1441
 
 
1442
    def test_sprout_copies_reference_location(self):
 
1443
        tree = self.make_tree_with_reference('branch', '../reference')
 
1444
        new_tree = tree.branch.controldir.sprout('new-branch').open_workingtree()
 
1445
        self.assertEqual(
 
1446
            urlutils.local_path_to_url('reference'),
 
1447
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
 
1448
                          new_tree.get_reference_info('path/to/file')))
 
1449
 
 
1450
    def test_clone_copies_reference_location(self):
 
1451
        tree = self.make_tree_with_reference('branch', '../reference')
 
1452
        new_tree = tree.controldir.clone('new-branch').open_workingtree()
 
1453
        self.assertEqual(
 
1454
            urlutils.local_path_to_url('reference'),
 
1455
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
 
1456
                          new_tree.get_reference_info('path/to/file')))
 
1457
 
 
1458
    def test_copied_locations_are_rebased(self):
 
1459
        tree = self.make_tree_with_reference('branch', 'reference')
 
1460
        new_tree = tree.controldir.sprout(
 
1461
            'branch/new-branch').open_workingtree()
 
1462
        self.assertEqual(
 
1463
            urlutils.local_path_to_url('branch/reference'),
 
1464
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
 
1465
                          new_tree.get_reference_info('path/to/file')))
 
1466
 
 
1467
    def test_update_references_retains_old_references(self):
 
1468
        tree = self.make_tree_with_reference('branch', 'reference')
 
1469
        new_tree = self.make_tree_with_reference(
 
1470
            'new_branch', 'reference2')
 
1471
        new_tree.branch.update_references(tree.branch)
 
1472
        self.assertEqual(
 
1473
            urlutils.local_path_to_url('branch/reference'),
 
1474
            urlutils.join(
 
1475
                urlutils.strip_segment_parameters(tree.branch.user_url),
 
1476
                tree.get_reference_info('path/to/file')))
 
1477
 
 
1478
    def test_update_references_retains_known_references(self):
 
1479
        tree = self.make_tree_with_reference('branch', 'reference')
 
1480
        new_tree = self.make_tree_with_reference(
 
1481
            'new_branch', 'reference2')
 
1482
        new_tree.branch.update_references(tree.branch)
 
1483
        self.assertEqual(
 
1484
            urlutils.local_path_to_url('branch/reference'),
 
1485
            urlutils.join(
 
1486
                urlutils.strip_segment_parameters(tree.branch.user_url),
 
1487
                tree.get_reference_info('path/to/file')))
 
1488
 
 
1489
    def test_update_references_skips_known_references(self):
 
1490
        tree = self.make_tree_with_reference('branch', 'reference')
 
1491
        new_tree = tree.controldir.sprout(
 
1492
            'branch/new-branch').open_workingtree()
 
1493
        self.build_tree(['branch/new-branch/foo'])
 
1494
        new_tree.add('foo')
 
1495
        new_tree.set_reference_info('foo', '../foo')
 
1496
        new_tree.branch.update_references(tree.branch)
 
1497
        self.assertEqual(
 
1498
            urlutils.local_path_to_url('branch/reference'),
 
1499
            urlutils.join(
 
1500
                urlutils.strip_segment_parameters(tree.branch.user_url),
 
1501
                tree.get_reference_info('path/to/file')))
 
1502
 
 
1503
    def test_pull_updates_references(self):
 
1504
        tree = self.make_tree_with_reference('branch', 'reference')
 
1505
        new_tree = tree.controldir.sprout(
 
1506
            'branch/new-branch').open_workingtree()
 
1507
        self.build_tree(['branch/new-branch/foo'])
 
1508
        new_tree.add('foo')
 
1509
        new_tree.set_reference_info('foo', '../foo')
 
1510
        new_tree.commit('set reference')
 
1511
        tree.pull(new_tree.branch)
 
1512
        self.assertEqual(
 
1513
            urlutils.local_path_to_url('branch/foo'),
 
1514
            urlutils.join(tree.branch.user_url, tree.get_reference_info('foo')))
 
1515
 
 
1516
    def test_push_updates_references(self):
 
1517
        tree = self.make_tree_with_reference('branch', 'reference')
 
1518
        new_tree = tree.controldir.sprout(
 
1519
            'branch/new-branch').open_workingtree()
 
1520
        self.build_tree(['branch/new-branch/foo'])
 
1521
        new_tree.add(['foo'])
 
1522
        new_tree.set_reference_info('foo', '../foo')
 
1523
        new_tree.commit('add reference')
 
1524
        tree.pull(new_tree.branch)
 
1525
        tree.update()
 
1526
        self.assertEqual(
 
1527
            urlutils.local_path_to_url('branch/foo'),
 
1528
            urlutils.join(tree.branch.user_url, tree.get_reference_info('foo')))
 
1529
 
 
1530
    def test_merge_updates_references(self):
 
1531
        orig_tree = self.make_tree_with_reference('branch', 'reference')
 
1532
        tree = orig_tree.controldir.sprout('tree').open_workingtree()
 
1533
        tree.commit('foo')
 
1534
        orig_tree.pull(tree.branch)
 
1535
        checkout = orig_tree.branch.create_checkout('checkout', lightweight=True)
 
1536
        checkout.commit('bar')
 
1537
        tree.lock_write()
 
1538
        self.addCleanup(tree.unlock)
 
1539
        merger = merge.Merger.from_revision_ids(tree,
 
1540
                                                orig_tree.branch.last_revision(),
 
1541
                                                other_branch=orig_tree.branch)
 
1542
        merger.merge_type = merge.Merge3Merger
 
1543
        merger.do_merge()
 
1544
        self.assertEqual(
 
1545
            urlutils.local_path_to_url('branch/reference'),
 
1546
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), tree.get_reference_info('path/to/file')))