39
39
self.assertEqual(len(wt.inventory), 2)
40
40
wt.flush() # workaround revert doing wt._write_inventory for now.
43
43
self.assertEqual(len(wt.inventory), 1)
46
class TestSnapshot(TestCaseWithWorkingTree):
49
# for full testing we'll need a branch
50
# with a subdir to test parent changes.
51
# and a file, link and dir under that.
52
# but right now I only need one attribute
53
# to change, and then test merge patterns
54
# with fake parent entries.
55
super(TestSnapshot, self).setUp()
56
self.wt = self.make_branch_and_tree('.')
57
self.branch = self.wt.branch
58
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
59
self.wt.add(['subdir', 'subdir/file'],
61
self.wt.commit('message_1', rev_id = '1')
62
self.tree_1 = self.branch.repository.revision_tree('1')
63
self.inv_1 = self.branch.repository.get_inventory('1')
64
self.file_1 = self.inv_1['fileid']
66
self.addCleanup(self.wt.unlock)
67
self.file_active = self.wt.inventory['fileid']
68
self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
70
def test_snapshot_new_revision(self):
71
# This tests that a simple commit with no parents makes a new
72
# revision value in the inventory entry
73
self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
74
# expected outcome - file_1 has a revision id of '2', and we can get
75
# its text of 'file contents' out of the weave.
76
self.assertEqual(self.file_1.revision, '1')
77
self.assertEqual(self.file_active.revision, '2')
78
# this should be a separate test probably, but lets check it once..
79
lines = self.branch.repository.weave_store.get_weave(
81
self.branch.repository.get_transaction()).get_lines('2')
82
self.assertEqual(lines, ['contents of subdir/file\n'])
83
self.wt.branch.repository.commit_write_group()
85
def test_snapshot_unchanged(self):
86
#This tests that a simple commit does not make a new entry for
87
# an unchanged inventory entry
88
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
89
self.wt, self.builder)
90
self.assertEqual(self.file_1.revision, '1')
91
self.assertEqual(self.file_active.revision, '1')
92
vf = self.branch.repository.weave_store.get_weave(
94
self.branch.repository.get_transaction())
95
self.assertRaises(errors.RevisionNotPresent,
98
self.wt.branch.repository.commit_write_group()
100
def test_snapshot_merge_identical_different_revid(self):
101
# This tests that a commit with two identical parents, one of which has
102
# a different revision id, results in a new revision id in the entry.
103
# 1->other, commit a merge of other against 1, results in 2.
104
other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
105
other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
106
other_ie.revision = '1'
107
other_ie.text_sha1 = self.file_1.text_sha1
108
other_ie.text_size = self.file_1.text_size
109
self.assertEqual(self.file_1, other_ie)
110
other_ie.revision = 'other'
111
self.assertNotEqual(self.file_1, other_ie)
112
versionfile = self.branch.repository.weave_store.get_weave(
113
'fileid', self.branch.repository.get_transaction())
114
versionfile.clone_text('other', '1', ['1'])
115
self.file_active.snapshot('2', 'subdir/file',
116
{'1':self.file_1, 'other':other_ie},
117
self.wt, self.builder)
118
self.assertEqual(self.file_active.revision, '2')
119
self.wt.branch.repository.commit_write_group()
121
def test_snapshot_changed(self):
122
# This tests that a commit with one different parent results in a new
123
# revision id in the entry.
124
self.wt.rename_one('subdir/file', 'subdir/newname')
125
self.file_active = self.wt.inventory['fileid']
126
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
127
self.wt, self.builder)
128
# expected outcome - file_1 has a revision id of '2'
129
self.assertEqual(self.file_active.revision, '2')
130
self.wt.branch.repository.commit_write_group()
133
46
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
135
48
def test_add(self):
154
67
('foo/bar', None, 'bar-id', None)])
155
68
self.assertIs(None, wt.path2id('foo'))
70
def test_rename_dir_with_children(self):
71
wt = self.make_branch_and_tree('.')
73
root_id = wt.get_root_id()
74
self.addCleanup(wt.unlock)
75
self.build_tree(['foo/', 'foo/bar'])
76
wt.add(['foo', 'foo/bar'],
78
wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
79
inventory.InventoryDirectory('foo-id', 'baz', root_id))])
80
# foo/bar should have been followed the rename of its parent to baz/bar
81
self.assertEqual('baz/bar', wt.id2path('bar-id'))
83
def test_rename_dir_with_children_with_children(self):
84
wt = self.make_branch_and_tree('.')
86
root_id = wt.get_root_id()
87
self.addCleanup(wt.unlock)
88
self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
89
wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
90
['foo-id', 'bar-id', 'baz-id'])
91
wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
92
inventory.InventoryDirectory('foo-id', 'quux', root_id))])
93
# foo/bar/baz should have been followed the rename of its parent's
94
# parent to quux/bar/baz
95
self.assertEqual('quux/bar/baz', wt.id2path('baz-id'))
157
97
def test_rename_file(self):
158
98
wt = self.make_branch_and_tree('.')
160
root_id = wt.get_root_id()
161
100
self.addCleanup(wt.unlock)
162
101
self.build_tree(['foo/', 'foo/bar', 'baz/'])
163
102
wt.add(['foo', 'foo/bar', 'baz'],