476
476
tree.branch.unlock()
479
class TestSmartServerBranchRequestSetLastRevisionInfo(tests.TestCaseWithTransport):
481
def lock_branch(self, branch):
482
branch_token = branch.lock_write()
483
repo_token = branch.repository.lock_write()
484
branch.repository.unlock()
485
self.addCleanup(branch.unlock)
486
return branch_token, repo_token
488
def make_locked_branch(self, format=None):
489
branch = self.make_branch('.', format=format)
490
branch_token, repo_token = self.lock_branch(branch)
491
return branch, branch_token, repo_token
493
def test_empty(self):
494
"""An empty branch can have its last revision set to 'null:'."""
495
b, branch_token, repo_token = self.make_locked_branch()
496
backing = self.get_transport()
497
request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
499
response = request.execute('', branch_token, repo_token, '0', 'null:')
500
self.assertEqual(SmartServerResponse(('ok',)), response)
502
def assertBranchLastRevisionInfo(self, expected_info, branch_relpath):
503
branch = bzrdir.BzrDir.open(branch_relpath).open_branch()
504
self.assertEqual(expected_info, branch.last_revision_info())
506
def test_branch_revision_info_is_updated(self):
507
"""This method really does update the branch last revision info."""
508
tree = self.make_branch_and_memory_tree('.')
511
tree.commit('First commit', rev_id='revision-1')
512
tree.commit('Second commit', rev_id='revision-2')
516
branch_token, repo_token = self.lock_branch(branch)
517
backing = self.get_transport()
518
request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
520
self.assertBranchLastRevisionInfo((2, 'revision-2'), '.')
521
response = request.execute(
522
'', branch_token, repo_token, '1', 'revision-1')
523
self.assertEqual(SmartServerResponse(('ok',)), response)
524
self.assertBranchLastRevisionInfo((1, 'revision-1'), '.')
526
def test_not_present_revid(self):
527
"""Some branch formats will check that the revision is present in the
528
repository. When that check fails, a NoSuchRevision error is returned
531
# Make a knit format branch, because that format checks the values
532
# given to set_last_revision_info.
533
b, branch_token, repo_token = self.make_locked_branch(format='knit')
534
backing = self.get_transport()
535
request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
537
response = request.execute(
538
'', branch_token, repo_token, '1', 'not-present')
540
SmartServerResponse(('NoSuchRevision', 'not-present')), response)
479
543
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):