69
74
def test_unexpected_prompt_failure(self):
70
75
tree = self.create_shelvable_tree()
76
tree.lock_tree_write()
77
self.addCleanup(tree.unlock)
71
78
shelver = ExpectShelver(tree, tree.basis_tree())
72
79
e = self.assertRaises(AssertionError, shelver.run)
73
80
self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
75
82
def test_wrong_prompt_failure(self):
76
83
tree = self.create_shelvable_tree()
84
tree.lock_tree_write()
85
self.addCleanup(tree.unlock)
77
86
shelver = ExpectShelver(tree, tree.basis_tree())
78
87
shelver.expect('foo', 'y')
79
88
e = self.assertRaises(AssertionError, shelver.run)
82
91
def test_shelve_not_diff(self):
83
92
tree = self.create_shelvable_tree()
93
tree.lock_tree_write()
94
self.addCleanup(tree.unlock)
84
95
shelver = ExpectShelver(tree, tree.basis_tree())
85
96
shelver.expect('Shelve? [yNfq?]', 'n')
86
97
shelver.expect('Shelve? [yNfq?]', 'n')
91
102
def test_shelve_diff_no(self):
92
103
tree = self.create_shelvable_tree()
104
tree.lock_tree_write()
105
self.addCleanup(tree.unlock)
93
106
shelver = ExpectShelver(tree, tree.basis_tree())
94
107
shelver.expect('Shelve? [yNfq?]', 'y')
95
108
shelver.expect('Shelve? [yNfq?]', 'y')
100
113
def test_shelve_diff(self):
101
114
tree = self.create_shelvable_tree()
115
tree.lock_tree_write()
116
self.addCleanup(tree.unlock)
102
117
shelver = ExpectShelver(tree, tree.basis_tree())
103
118
shelver.expect('Shelve? [yNfq?]', 'y')
104
119
shelver.expect('Shelve? [yNfq?]', 'y')
109
124
def test_shelve_one_diff(self):
110
125
tree = self.create_shelvable_tree()
126
tree.lock_tree_write()
127
self.addCleanup(tree.unlock)
111
128
shelver = ExpectShelver(tree, tree.basis_tree())
112
129
shelver.expect('Shelve? [yNfq?]', 'y')
113
130
shelver.expect('Shelve? [yNfq?]', 'n')
118
135
def test_shelve_binary_change(self):
119
136
tree = self.create_shelvable_tree()
120
137
self.build_tree_contents([('tree/foo', '\x00')])
138
tree.lock_tree_write()
139
self.addCleanup(tree.unlock)
121
140
shelver = ExpectShelver(tree, tree.basis_tree())
122
141
shelver.expect('Shelve binary changes? [yNfq?]', 'y')
123
142
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
127
146
def test_shelve_rename(self):
128
147
tree = self.create_shelvable_tree()
129
148
tree.rename_one('foo', 'bar')
149
tree.lock_tree_write()
150
self.addCleanup(tree.unlock)
130
151
shelver = ExpectShelver(tree, tree.basis_tree())
131
152
shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
132
153
shelver.expect('Shelve? [yNfq?]', 'y')
138
159
def test_shelve_deletion(self):
139
160
tree = self.create_shelvable_tree()
140
161
os.unlink('tree/foo')
162
tree.lock_tree_write()
163
self.addCleanup(tree.unlock)
141
164
shelver = ExpectShelver(tree, tree.basis_tree())
142
165
shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
143
166
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
149
172
tree.commit('add tree root')
150
173
self.build_tree(['tree/foo'])
175
tree.lock_tree_write()
176
self.addCleanup(tree.unlock)
152
177
shelver = ExpectShelver(tree, tree.basis_tree())
153
178
shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
154
179
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
182
211
def test_shelve_finish(self):
183
212
tree = self.create_shelvable_tree()
213
tree.lock_tree_write()
214
self.addCleanup(tree.unlock)
184
215
shelver = ExpectShelver(tree, tree.basis_tree())
185
216
shelver.expect('Shelve? [yNfq?]', 'f')
186
217
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
190
221
def test_shelve_quit(self):
191
222
tree = self.create_shelvable_tree()
223
tree.lock_tree_write()
224
self.addCleanup(tree.unlock)
192
225
shelver = ExpectShelver(tree, tree.basis_tree())
193
226
shelver.expect('Shelve? [yNfq?]', 'q')
194
227
self.assertRaises(errors.UserAbort, shelver.run)
197
230
def test_shelve_all(self):
198
231
tree = self.create_shelvable_tree()
199
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
232
shelver = ExpectShelver.from_args(sys.stdout, all=True,
237
shelver.work_tree.unlock()
200
238
self.assertFileEqual(LINES_AJ, 'tree/foo')
202
240
def test_shelve_filename(self):
203
241
tree = self.create_shelvable_tree()
204
242
self.build_tree(['tree/bar'])
244
tree.lock_tree_write()
245
self.addCleanup(tree.unlock)
206
246
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
207
247
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
208
248
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
211
251
def test_shelve_help(self):
212
252
tree = self.create_shelvable_tree()
253
tree.lock_tree_write()
254
self.addCleanup(tree.unlock)
213
255
shelver = ExpectShelver(tree, tree.basis_tree())
214
256
shelver.expect('Shelve? [yNfq?]', '?')
215
257
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
220
262
tree = self.create_shelvable_tree()
221
263
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
222
264
directory='tree', destroy=True)
268
shelver.work_tree.unlock()
224
269
self.assertIs(None, tree.get_shelf_manager().last_shelf())
225
270
self.assertFileEqual(LINES_AJ, 'tree/foo')
273
def shelve_all(tree, target_revision_id):
276
target = tree.branch.repository.revision_tree(target_revision_id)
277
shelver = shelf_ui.Shelver(tree, target, auto=True,
283
def test_shelve_old_root_deleted(self):
284
tree1 = self.make_branch_and_tree('tree1')
285
tree1.commit('add root')
286
tree2 = self.make_branch_and_tree('tree2')
287
rev2 = tree2.commit('add root')
288
tree1.merge_from_branch(tree2.branch,
289
from_revision=revision.NULL_REVISION)
290
tree1.commit('Replaced root entry')
291
# This is essentially assertNotRaises(InconsistentDelta)
292
self.expectFailure('Cannot shelve replacing a root entry',
293
self.assertRaises, AssertionError,
294
self.assertRaises, errors.InconsistentDelta,
295
self.shelve_all, tree1, rev2)
297
def test_shelve_split(self):
298
outer_tree = self.make_branch_and_tree('outer')
299
outer_tree.commit('Add root')
300
inner_tree = self.make_branch_and_tree('outer/inner')
301
rev2 = inner_tree.commit('Add root')
302
outer_tree.subsume(inner_tree)
303
# This is essentially assertNotRaises(ValueError).
304
# The ValueError is 'None is not a valid file id'.
305
self.expectFailure('Cannot shelve a join back to the inner tree.',
306
self.assertRaises, AssertionError,
307
self.assertRaises, ValueError, self.shelve_all,
228
311
class TestApplyReporter(TestShelver):
230
313
def test_shelve_not_diff(self):
231
314
tree = self.create_shelvable_tree()
315
tree.lock_tree_write()
316
self.addCleanup(tree.unlock)
232
317
shelver = ExpectShelver(tree, tree.basis_tree(),
233
318
reporter=shelf_ui.ApplyReporter())
234
319
shelver.expect('Apply change? [yNfq?]', 'n')
240
325
def test_shelve_diff_no(self):
241
326
tree = self.create_shelvable_tree()
327
tree.lock_tree_write()
328
self.addCleanup(tree.unlock)
242
329
shelver = ExpectShelver(tree, tree.basis_tree(),
243
330
reporter=shelf_ui.ApplyReporter())
244
331
shelver.expect('Apply change? [yNfq?]', 'y')
250
337
def test_shelve_diff(self):
251
338
tree = self.create_shelvable_tree()
339
tree.lock_tree_write()
340
self.addCleanup(tree.unlock)
252
341
shelver = ExpectShelver(tree, tree.basis_tree(),
253
342
reporter=shelf_ui.ApplyReporter())
254
343
shelver.expect('Apply change? [yNfq?]', 'y')
260
349
def test_shelve_binary_change(self):
261
350
tree = self.create_shelvable_tree()
262
351
self.build_tree_contents([('tree/foo', '\x00')])
352
tree.lock_tree_write()
353
self.addCleanup(tree.unlock)
263
354
shelver = ExpectShelver(tree, tree.basis_tree(),
264
355
reporter=shelf_ui.ApplyReporter())
265
356
shelver.expect('Apply binary changes? [yNfq?]', 'y')
270
361
def test_shelve_rename(self):
271
362
tree = self.create_shelvable_tree()
272
363
tree.rename_one('foo', 'bar')
364
tree.lock_tree_write()
365
self.addCleanup(tree.unlock)
273
366
shelver = ExpectShelver(tree, tree.basis_tree(),
274
367
reporter=shelf_ui.ApplyReporter())
275
368
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
282
375
def test_shelve_deletion(self):
283
376
tree = self.create_shelvable_tree()
284
377
os.unlink('tree/foo')
378
tree.lock_tree_write()
379
self.addCleanup(tree.unlock)
285
380
shelver = ExpectShelver(tree, tree.basis_tree(),
286
381
reporter=shelf_ui.ApplyReporter())
287
382
shelver.expect('Add file "foo"? [yNfq?]', 'y')
294
389
tree.commit('add tree root')
295
390
self.build_tree(['tree/foo'])
392
tree.lock_tree_write()
393
self.addCleanup(tree.unlock)
297
394
shelver = ExpectShelver(tree, tree.basis_tree(),
298
395
reporter=shelf_ui.ApplyReporter())
299
396
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
318
417
tree.commit("Add symlink")
319
418
os.unlink('tree/baz')
320
419
os.symlink('vax', 'tree/baz')
420
tree.lock_tree_write()
421
self.addCleanup(tree.unlock)
321
422
shelver = ExpectShelver(tree, tree.basis_tree(),
322
423
reporter=shelf_ui.ApplyReporter())
323
424
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
332
433
def create_tree_with_shelf(self):
333
434
tree = self.make_branch_and_tree('tree')
334
self.build_tree_contents([('tree/foo', LINES_AJ)])
335
tree.add('foo', 'foo-id')
336
tree.commit('added foo')
337
self.build_tree_contents([('tree/foo', LINES_ZY)])
338
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
437
self.build_tree_contents([('tree/foo', LINES_AJ)])
438
tree.add('foo', 'foo-id')
439
tree.commit('added foo')
440
self.build_tree_contents([('tree/foo', LINES_ZY)])
441
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
342
447
def test_unshelve(self):
350
455
def test_unshelve_args(self):
351
456
tree = self.create_tree_with_shelf()
352
shelf_ui.Unshelver.from_args(directory='tree').run()
457
unshelver = shelf_ui.Unshelver.from_args(directory='tree')
461
unshelver.tree.unlock()
353
462
self.assertFileEqual(LINES_ZY, 'tree/foo')
354
463
self.assertIs(None, tree.get_shelf_manager().last_shelf())
356
465
def test_unshelve_args_dry_run(self):
357
466
tree = self.create_tree_with_shelf()
358
shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
467
unshelver = shelf_ui.Unshelver.from_args(directory='tree',
472
unshelver.tree.unlock()
359
473
self.assertFileEqual(LINES_AJ, 'tree/foo')
360
474
self.assertEqual(1, tree.get_shelf_manager().last_shelf())