1329
1330
self.assertSubset(
1330
1331
[self.workingtree_format.supports_store_uncommitted],
1335
class TestReferenceLocation(TestCaseWithWorkingTree):
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')
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)
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')
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])
1371
def test_get_reference_info(self):
1372
tree = self.make_branch_and_tree('branch')
1374
loc = tree.get_reference_info('file')
1375
except errors.UnsupportedOperation:
1376
raise tests.TestNotApplicable('Branch cannot hold references.')
1377
self.assertIs(None, loc)
1379
def test_set_reference_info(self):
1380
self.make_tree_with_reference('branch', 'path/to/location')
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')
1388
urlutils.local_path_to_url('branch/path/to/location'),
1389
urlutils.join(tree.branch.user_url, branch_location))
1391
def test_set_null_reference_info(self):
1392
tree = self.make_branch_and_tree('branch')
1393
self.build_tree(['branch/file'])
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)
1403
def test_set_null_reference_info_when_null(self):
1404
tree = self.make_branch_and_tree('branch')
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'])
1413
tree.set_reference_info('file', None)
1414
except errors.UnsupportedOperation:
1415
raise tests.TestNotApplicable('Branch cannot hold references.')
1417
def make_tree_with_reference(self, location, reference_location):
1418
tree = self.make_branch_and_tree(location)
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'])
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')
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)
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)
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()
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')))
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()
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')))
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()
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')))
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)
1473
urlutils.local_path_to_url('branch/reference'),
1475
urlutils.strip_segment_parameters(tree.branch.user_url),
1476
tree.get_reference_info('path/to/file')))
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)
1484
urlutils.local_path_to_url('branch/reference'),
1486
urlutils.strip_segment_parameters(tree.branch.user_url),
1487
tree.get_reference_info('path/to/file')))
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'])
1495
new_tree.set_reference_info('foo', '../foo')
1496
new_tree.branch.update_references(tree.branch)
1498
urlutils.local_path_to_url('branch/reference'),
1500
urlutils.strip_segment_parameters(tree.branch.user_url),
1501
tree.get_reference_info('path/to/file')))
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'])
1509
new_tree.set_reference_info('foo', '../foo')
1510
new_tree.commit('set reference')
1511
tree.pull(new_tree.branch)
1513
urlutils.local_path_to_url('branch/foo'),
1514
urlutils.join(tree.branch.user_url, tree.get_reference_info('foo')))
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)
1527
urlutils.local_path_to_url('branch/foo'),
1528
urlutils.join(tree.branch.user_url, tree.get_reference_info('foo')))
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()
1534
orig_tree.pull(tree.branch)
1535
checkout = orig_tree.branch.create_checkout('checkout', lightweight=True)
1536
checkout.commit('bar')
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
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')))