50
60
self.assertEqual('bar', creator.shelf_transform.final_name(
53
def test_shelve_move(self):
63
def test_shelve_rename(self):
64
creator = self.prepare_shelve_rename()
65
creator.shelve_rename('foo-id')
66
self.check_shelve_rename(creator)
68
def test_shelve_change_handles_rename(self):
69
creator = self.prepare_shelve_rename()
70
creator.shelve_change(('rename', 'foo-id', 'foo', 'bar'))
71
self.check_shelve_rename(creator)
73
def prepare_shelve_move(self):
54
74
tree = self.make_branch_and_tree('.')
55
75
self.build_tree(['foo/', 'bar/', 'foo/baz'])
56
76
tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
72
94
creator.transform()
73
95
self.assertEqual('foo/baz', tree.id2path('baz-id'))
97
def test_shelve_move(self):
98
creator, tree = self.prepare_shelve_move()
99
creator.shelve_rename('baz-id')
100
self.check_shelve_move(creator, tree)
102
def test_shelve_change_handles_move(self):
103
creator, tree = self.prepare_shelve_move()
104
creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
105
self.check_shelve_move(creator, tree)
75
107
def assertShelvedFileEqual(self, expected_content, creator, file_id):
76
108
s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
77
109
shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
121
154
self.assertEqual('directory',
122
155
creator.shelf_transform.final_kind(s_bar_trans_id))
157
def test_shelve_creation(self):
158
creator, tree = self.prepare_shelve_creation()
159
creator.shelve_creation('foo-id')
160
creator.shelve_creation('bar-id')
162
self.check_shelve_creation(creator, tree)
164
def test_shelve_change_handles_creation(self):
165
creator, tree = self.prepare_shelve_creation()
166
creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
167
creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
169
self.check_shelve_creation(creator, tree)
171
def _test_shelve_symlink_creation(self, link_name, link_target,
172
shelve_change=False):
173
self.requireFeature(tests.SymlinkFeature)
174
tree = self.make_branch_and_tree('.')
176
self.addCleanup(tree.unlock)
177
tree.commit('Empty tree')
178
os.symlink(link_target, link_name)
179
tree.add(link_name, 'foo-id')
180
creator = shelf.ShelfCreator(tree, tree.basis_tree())
181
self.addCleanup(creator.finalize)
182
self.assertEqual([('add file', 'foo-id', 'symlink', link_name)],
183
list(creator.iter_shelvable()))
185
creator.shelve_change(('add file', 'foo-id', 'symlink', link_name))
187
creator.shelve_creation('foo-id')
189
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
190
self.failIfExists(link_name)
191
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
192
self.assertEqual(link_target, osutils.readlink(limbo_name))
193
ptree = creator.shelf_transform.get_preview_tree()
194
self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
124
196
def test_shelve_symlink_creation(self):
197
self._test_shelve_symlink_creation('foo', 'bar')
199
def test_shelve_unicode_symlink_creation(self):
200
self.requireFeature(tests.UnicodeFilenameFeature)
201
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
204
def test_shelve_change_handles_symlink_creation(self):
205
self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
207
def _test_shelve_symlink_target_change(self, link_name,
208
old_target, new_target,
209
shelve_change=False):
125
210
self.requireFeature(tests.SymlinkFeature)
126
211
tree = self.make_branch_and_tree('.')
127
212
tree.lock_write()
128
213
self.addCleanup(tree.unlock)
129
tree.commit('Empty tree')
130
os.symlink('bar', 'foo')
131
tree.add('foo', 'foo-id')
214
os.symlink(old_target, link_name)
215
tree.add(link_name, 'foo-id')
216
tree.commit("commit symlink")
218
os.symlink(new_target, link_name)
132
219
creator = shelf.ShelfCreator(tree, tree.basis_tree())
133
220
self.addCleanup(creator.finalize)
134
self.assertEqual([('add file', 'foo-id', 'symlink', 'foo')],
221
self.assertEqual([('modify target', 'foo-id', link_name,
222
old_target, new_target)],
135
223
list(creator.iter_shelvable()))
136
creator.shelve_creation('foo-id')
225
creator.shelve_change(('modify target', 'foo-id', link_name,
226
old_target, new_target))
228
creator.shelve_modify_target('foo-id')
137
229
creator.transform()
230
self.assertEqual(old_target, osutils.readlink(link_name))
138
231
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
139
self.failIfExists('foo')
140
232
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
141
self.assertEqual('bar', os.readlink(limbo_name))
233
self.assertEqual(new_target, osutils.readlink(limbo_name))
234
ptree = creator.shelf_transform.get_preview_tree()
235
self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
237
def test_shelve_symlink_target_change(self):
238
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
240
def test_shelve_unicode_symlink_target_change(self):
241
self.requireFeature(tests.UnicodeFilenameFeature)
242
self._test_shelve_symlink_target_change(
243
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
245
def test_shelve_change_handles_symlink_target_change(self):
246
self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
143
249
def test_shelve_creation_no_contents(self):
144
250
tree = self.make_branch_and_tree('.')
177
283
self.assertEqual([('delete file', 'bar-id', 'file', 'foo/bar'),
178
284
('delete file', 'foo-id', 'directory', 'foo')],
179
285
sorted(list(creator.iter_shelvable())))
180
creator.shelve_deletion('foo-id')
181
creator.shelve_deletion('bar-id')
288
def check_shelve_deletion(self, tree):
183
289
self.assertTrue('foo-id' in tree)
184
290
self.assertTrue('bar-id' in tree)
185
291
self.assertFileEqual('baz', 'tree/foo/bar')
293
def test_shelve_deletion(self):
294
creator, tree = self.prepare_shelve_deletion()
295
creator.shelve_deletion('foo-id')
296
creator.shelve_deletion('bar-id')
298
self.check_shelve_deletion(tree)
300
def test_shelve_change_handles_deletion(self):
301
creator, tree = self.prepare_shelve_deletion()
302
creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
303
creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
305
self.check_shelve_deletion(tree)
187
307
def test_shelve_delete_contents(self):
188
308
tree = self.make_branch_and_tree('tree')
189
309
self.build_tree(['tree/foo',])
209
329
self.addCleanup(creator.finalize)
210
330
self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
211
331
'foo')], sorted(list(creator.iter_shelvable())))
334
def check_shelve_change_kind(self, creator):
335
self.assertFileEqual('bar', 'tree/foo')
336
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
337
self.assertEqual('directory',
338
creator.shelf_transform._new_contents[s_trans_id])
340
def test_shelve_change_kind(self):
341
creator = self.prepare_shelve_change_kind()
212
342
creator.shelve_content_change('foo-id')
213
343
creator.transform()
214
self.assertFileEqual('bar', 'tree/foo')
215
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
216
self.assertEqual('directory',
217
creator.shelf_transform._new_contents[s_trans_id])
344
self.check_shelve_change_kind(creator)
346
def test_shelve_change_handles_change_kind(self):
347
creator = self.prepare_shelve_change_kind()
348
creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
351
self.check_shelve_change_kind(creator)
353
def test_shelve_change_unknown_change(self):
354
tree = self.make_branch_and_tree('tree')
355
creator = shelf.ShelfCreator(tree, tree.basis_tree())
356
self.addCleanup(creator.finalize)
357
e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
358
self.assertEqual('Unknown change kind: "unknown"', str(e))
219
360
def test_shelve_unversion(self):
220
361
tree = self.make_branch_and_tree('tree')