62
62
def capture_pre_commit_hook(self, local, master, old_revno, old_revid,
63
63
new_revno, new_revid, affected, tree):
64
# replacing ids with paths
65
# notice that we leave deleted ids in tact
66
for change, ids in affected.iteritems():
67
if change == 'deleted':
69
for i, id in enumerate(ids):
70
ids[i] = tree.id2path(id)
71
64
self.hook_calls.append(('pre_commit', old_revno, old_revid,
72
65
new_revno, new_revid, affected))
172
def test_pre_commit_paths(self):
173
tree = self.make_branch_and_memory_tree('branch')
165
def test_pre_commit_ids(self):
166
self.build_tree(['rootfile', 'dir/', 'dir/subfile'])
167
tree = self.make_branch_and_tree('.')
174
168
tree.lock_write()
176
tree.add('file', 'bang')
177
tree.put_file_bytes_non_atomic('bang', 'die')
178
tree.mkdir('dir', 'dirid')
179
tree.add('dir/file', 'swoosh')
180
tree.put_file_bytes_non_atomic('swoosh', 'swaash')
169
tree.set_root_id('root_id')
170
tree.add('rootfile', 'rootfile_id')
171
tree.put_file_bytes_non_atomic('rootfile_id', 'abc')
172
tree.add('dir', 'dir_id')
173
tree.add('dir/subfile', 'dir_subfile_id')
174
tree.put_file_bytes_non_atomic('dir_subfile_id', 'def')
181
175
Branch.hooks.install_hook("pre_commit", self.capture_pre_commit_hook)
182
176
rev1 = tree.commit('first revision')
183
tree.unversion(['dirid'])
177
tree.unversion(['dir_id'])
184
178
rev2 = tree.commit('second revision')
179
tree.put_file_bytes_non_atomic('rootfile_id', 'ghi')
180
rev3 = tree.commit('third revision')
183
tree.rename_one('rootfile', 'renamed')
184
rev4 = tree.commit('fourth revision')
187
tree.put_file_bytes_non_atomic('rootfile_id', 'jkl')
188
tree.rename_one('renamed', 'rootfile')
189
rev5 = tree.commit('fifth revision')
185
191
self.assertEqual([
186
192
('pre_commit', 0, NULL_REVISION, 1, rev1,
187
{'added': ['dir', 'dir/file', 'file']} ),
193
{'added': ['dir_id', 'dir_subfile_id', 'rootfile_id']} ),
188
194
('pre_commit', 1, rev1, 2, rev2,
189
{'deleted': ['dirid', 'swoosh']} )
195
{'deleted': ['dir_id', 'dir_subfile_id']} ),
196
('pre_commit', 2, rev2, 3, rev3,
197
{'modified': ['rootfile_id']} ),
198
('pre_commit', 3, rev3, 4, rev4,
199
{'renamed': ['rootfile_id']} ),
200
('pre_commit', 4, rev4, 5, rev5,
201
{'modified and renamed': ['rootfile_id']} )