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