949
953
os.link = real_os_link
956
class TestWorkingTreeUpdate(TestCaseWithWorkingTree):
958
def make_diverged_master_branch(self):
960
B: wt.branch.last_revision()
961
M: wt.branch.get_master_branch().last_revision()
962
W: wt.last_revision()
973
builder = branchbuilder.BranchBuilder(
974
self.get_transport(),
975
format=self.workingtree_format._matchingbzrdir)
976
builder.start_series()
978
builder.build_snapshot(
980
[('add', ('', 'root-id', 'directory', '')),
981
('add', ('file1', 'file1-id', 'file', 'file1 content\n'))])
983
builder.build_snapshot('2', ['1'], [])
984
builder.build_snapshot(
986
[('add', ('file4', 'file4-id', 'file', 'file4 content\n'))])
988
builder.build_snapshot('3', ['1'], [])
989
builder.build_snapshot(
991
[('add', ('file5', 'file5-id', 'file', 'file5 content\n'))])
992
builder.finish_series()
993
return builder, builder._branch.last_revision()
995
def make_checkout_and_master(self, builder, wt_path, master_path, wt_revid,
996
master_revid=None, branch_revid=None):
997
"""Build a lightweight checkout and its master branch."""
998
if master_revid is None:
999
master_revid = wt_revid
1000
if branch_revid is None:
1001
branch_revid = master_revid
1002
final_branch = builder.get_branch()
1004
master = final_branch.bzrdir.sprout(master_path,
1005
master_revid).open_branch()
1007
wt = self.make_branch_and_tree(wt_path)
1008
wt.pull(final_branch, stop_revision=wt_revid)
1009
wt.branch.pull(final_branch, stop_revision=branch_revid, overwrite=True)
1011
wt.branch.bind(master)
1012
except errors.UpgradeRequired:
1013
raise TestNotApplicable(
1014
"Can't bind %s" % wt.branch._format.__class__)
1017
def test_update_remove_commit(self):
1018
"""Update should remove revisions when the branch has removed
1021
We want to revert 4, so that strating with the
1022
make_diverged_master_branch() graph the final result should be
1033
And the changes in 4 have been removed from the WT.
1035
builder, tip = self.make_diverged_master_branch()
1036
wt, master = self.make_checkout_and_master(
1037
builder, 'checkout', 'master', '4',
1038
master_revid=tip, branch_revid='2')
1039
# First update the branch
1040
old_tip = wt.branch.update()
1041
self.assertEqual('2', old_tip)
1042
# No conflicts should occur
1043
self.assertEqual(0, wt.update(old_tip=old_tip))
1044
# We are in sync with the master
1045
self.assertEqual(tip, wt.branch.last_revision())
1046
# We have the right parents ready to be committed
1047
self.assertEqual(['5', '2'], wt.get_parent_ids())
1049
def test_update_revision(self):
1050
builder, tip = self.make_diverged_master_branch()
1051
wt, master = self.make_checkout_and_master(
1052
builder, 'checkout', 'master', '4',
1053
master_revid=tip, branch_revid='2')
1054
self.assertEqual(0, wt.update(revision='1'))
1055
self.assertEqual('1', wt.last_revision())
1056
self.assertEqual(tip, wt.branch.last_revision())
1057
self.failUnlessExists('checkout/file1')
1058
self.failIfExists('checkout/file4')
1059
self.failIfExists('checkout/file5')
952
1062
class TestIllegalPaths(TestCaseWithWorkingTree):
954
1064
def test_bad_fs_path(self):