67
75
def test_unexpected_prompt_failure(self):
68
76
tree = self.create_shelvable_tree()
77
tree.lock_tree_write()
78
self.addCleanup(tree.unlock)
69
79
shelver = ExpectShelver(tree, tree.basis_tree())
80
self.addCleanup(shelver.finalize)
70
81
e = self.assertRaises(AssertionError, shelver.run)
71
self.assertEqual('Unexpected prompt: Shelve? [yNfq]', str(e))
82
self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
73
84
def test_wrong_prompt_failure(self):
74
85
tree = self.create_shelvable_tree()
86
tree.lock_tree_write()
87
self.addCleanup(tree.unlock)
75
88
shelver = ExpectShelver(tree, tree.basis_tree())
89
self.addCleanup(shelver.finalize)
76
90
shelver.expect('foo', 'y')
77
91
e = self.assertRaises(AssertionError, shelver.run)
78
self.assertEqual('Wrong prompt: Shelve? [yNfq]', str(e))
92
self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
80
94
def test_shelve_not_diff(self):
81
95
tree = self.create_shelvable_tree()
96
tree.lock_tree_write()
97
self.addCleanup(tree.unlock)
82
98
shelver = ExpectShelver(tree, tree.basis_tree())
83
shelver.expect('Shelve? [yNfq]', 'n')
84
shelver.expect('Shelve? [yNfq]', 'n')
99
self.addCleanup(shelver.finalize)
100
shelver.expect('Shelve? [yNfq?]', 'n')
101
shelver.expect('Shelve? [yNfq?]', 'n')
85
102
# No final shelving prompt because no changes were selected
87
104
self.assertFileEqual(LINES_ZY, 'tree/foo')
89
106
def test_shelve_diff_no(self):
90
107
tree = self.create_shelvable_tree()
108
tree.lock_tree_write()
109
self.addCleanup(tree.unlock)
91
110
shelver = ExpectShelver(tree, tree.basis_tree())
92
shelver.expect('Shelve? [yNfq]', 'y')
93
shelver.expect('Shelve? [yNfq]', 'y')
94
shelver.expect('Shelve 2 change(s)? [yNfq]', 'n')
111
self.addCleanup(shelver.finalize)
112
shelver.expect('Shelve? [yNfq?]', 'y')
113
shelver.expect('Shelve? [yNfq?]', 'y')
114
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
96
116
self.assertFileEqual(LINES_ZY, 'tree/foo')
98
118
def test_shelve_diff(self):
99
119
tree = self.create_shelvable_tree()
120
tree.lock_tree_write()
121
self.addCleanup(tree.unlock)
100
122
shelver = ExpectShelver(tree, tree.basis_tree())
101
shelver.expect('Shelve? [yNfq]', 'y')
102
shelver.expect('Shelve? [yNfq]', 'y')
103
shelver.expect('Shelve 2 change(s)? [yNfq]', 'y')
123
self.addCleanup(shelver.finalize)
124
shelver.expect('Shelve? [yNfq?]', 'y')
125
shelver.expect('Shelve? [yNfq?]', 'y')
126
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
105
128
self.assertFileEqual(LINES_AJ, 'tree/foo')
107
130
def test_shelve_one_diff(self):
108
131
tree = self.create_shelvable_tree()
132
tree.lock_tree_write()
133
self.addCleanup(tree.unlock)
109
134
shelver = ExpectShelver(tree, tree.basis_tree())
110
shelver.expect('Shelve? [yNfq]', 'y')
111
shelver.expect('Shelve? [yNfq]', 'n')
112
shelver.expect('Shelve 1 change(s)? [yNfq]', 'y')
135
self.addCleanup(shelver.finalize)
136
shelver.expect('Shelve? [yNfq?]', 'y')
137
shelver.expect('Shelve? [yNfq?]', 'n')
138
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
114
140
self.assertFileEqual(LINES_AY, 'tree/foo')
116
142
def test_shelve_binary_change(self):
117
143
tree = self.create_shelvable_tree()
118
144
self.build_tree_contents([('tree/foo', '\x00')])
145
tree.lock_tree_write()
146
self.addCleanup(tree.unlock)
119
147
shelver = ExpectShelver(tree, tree.basis_tree())
120
shelver.expect('Shelve binary changes? [yNfq]', 'y')
121
shelver.expect('Shelve 1 change(s)? [yNfq]', 'y')
148
self.addCleanup(shelver.finalize)
149
shelver.expect('Shelve binary changes? [yNfq?]', 'y')
150
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
123
152
self.assertFileEqual(LINES_AJ, 'tree/foo')
125
154
def test_shelve_rename(self):
126
155
tree = self.create_shelvable_tree()
127
156
tree.rename_one('foo', 'bar')
157
tree.lock_tree_write()
158
self.addCleanup(tree.unlock)
128
159
shelver = ExpectShelver(tree, tree.basis_tree())
129
shelver.expect('Shelve renaming "foo" => "bar"? [yNfq]', 'y')
130
shelver.expect('Shelve? [yNfq]', 'y')
131
shelver.expect('Shelve? [yNfq]', 'y')
132
shelver.expect('Shelve 3 change(s)? [yNfq]', 'y')
160
self.addCleanup(shelver.finalize)
161
shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
162
shelver.expect('Shelve? [yNfq?]', 'y')
163
shelver.expect('Shelve? [yNfq?]', 'y')
164
shelver.expect('Shelve 3 change(s)? [yNfq?]', 'y')
134
166
self.assertFileEqual(LINES_AJ, 'tree/foo')
136
168
def test_shelve_deletion(self):
137
169
tree = self.create_shelvable_tree()
138
170
os.unlink('tree/foo')
171
tree.lock_tree_write()
172
self.addCleanup(tree.unlock)
139
173
shelver = ExpectShelver(tree, tree.basis_tree())
140
shelver.expect('Shelve removing file "foo"? [yNfq]', 'y')
141
shelver.expect('Shelve 1 change(s)? [yNfq]', 'y')
174
self.addCleanup(shelver.finalize)
175
shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
176
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
143
178
self.assertFileEqual(LINES_AJ, 'tree/foo')
157
195
tree = self.create_shelvable_tree()
158
196
os.unlink('tree/foo')
159
197
os.mkdir('tree/foo')
198
tree.lock_tree_write()
199
self.addCleanup(tree.unlock)
160
200
shelver = ExpectShelver(tree, tree.basis_tree())
161
shelver.expect('Shelve changing "foo" from file to directory? [yNfq]',
201
self.addCleanup(shelver.finalize)
202
shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
163
shelver.expect('Shelve 1 change(s)? [yNfq]', 'y')
204
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
206
def test_shelve_modify_target(self):
207
self.requireFeature(tests.SymlinkFeature)
208
tree = self.create_shelvable_tree()
209
os.symlink('bar', 'tree/baz')
210
tree.add('baz', 'baz-id')
211
tree.commit("Add symlink")
212
os.unlink('tree/baz')
213
os.symlink('vax', 'tree/baz')
214
tree.lock_tree_write()
215
self.addCleanup(tree.unlock)
216
shelver = ExpectShelver(tree, tree.basis_tree())
217
self.addCleanup(shelver.finalize)
218
shelver.expect('Shelve changing target of "baz" from "bar" to '
219
'"vax"? [yNfq?]', 'y')
220
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
222
self.assertEqual('bar', os.readlink('tree/baz'))
165
224
def test_shelve_finish(self):
166
225
tree = self.create_shelvable_tree()
226
tree.lock_tree_write()
227
self.addCleanup(tree.unlock)
167
228
shelver = ExpectShelver(tree, tree.basis_tree())
168
shelver.expect('Shelve? [yNfq]', 'f')
169
shelver.expect('Shelve 2 change(s)? [yNfq]', 'y')
229
self.addCleanup(shelver.finalize)
230
shelver.expect('Shelve? [yNfq?]', 'f')
231
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
171
233
self.assertFileEqual(LINES_AJ, 'tree/foo')
173
235
def test_shelve_quit(self):
174
236
tree = self.create_shelvable_tree()
237
tree.lock_tree_write()
238
self.addCleanup(tree.unlock)
175
239
shelver = ExpectShelver(tree, tree.basis_tree())
176
shelver.expect('Shelve? [yNfq]', 'q')
240
self.addCleanup(shelver.finalize)
241
shelver.expect('Shelve? [yNfq?]', 'q')
177
242
self.assertRaises(errors.UserAbort, shelver.run)
178
243
self.assertFileEqual(LINES_ZY, 'tree/foo')
180
245
def test_shelve_all(self):
181
246
tree = self.create_shelvable_tree()
182
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
247
shelver = ExpectShelver.from_args(sys.stdout, all=True,
183
253
self.assertFileEqual(LINES_AJ, 'tree/foo')
185
255
def test_shelve_filename(self):
186
256
tree = self.create_shelvable_tree()
187
257
self.build_tree(['tree/bar'])
259
tree.lock_tree_write()
260
self.addCleanup(tree.unlock)
189
261
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
190
shelver.expect('Shelve adding file "bar"? [yNfq]', 'y')
191
shelver.expect('Shelve 1 change(s)? [yNfq]', 'y')
262
self.addCleanup(shelver.finalize)
263
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
264
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
267
def test_shelve_help(self):
268
tree = self.create_shelvable_tree()
269
tree.lock_tree_write()
270
self.addCleanup(tree.unlock)
271
shelver = ExpectShelver(tree, tree.basis_tree())
272
self.addCleanup(shelver.finalize)
273
shelver.expect('Shelve? [yNfq?]', '?')
274
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
275
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
278
def test_shelve_destroy(self):
279
tree = self.create_shelvable_tree()
280
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
281
directory='tree', destroy=True)
282
self.addCleanup(shelver.finalize)
284
self.assertIs(None, tree.get_shelf_manager().last_shelf())
285
self.assertFileEqual(LINES_AJ, 'tree/foo')
288
def shelve_all(tree, target_revision_id):
291
target = tree.branch.repository.revision_tree(target_revision_id)
292
shelver = shelf_ui.Shelver(tree, target, auto=True,
301
def test_shelve_old_root_deleted(self):
302
tree1 = self.make_branch_and_tree('tree1')
303
tree1.commit('add root')
304
tree2 = self.make_branch_and_tree('tree2')
305
rev2 = tree2.commit('add root')
306
tree1.merge_from_branch(tree2.branch,
307
from_revision=revision.NULL_REVISION)
308
tree1.commit('Replaced root entry')
309
# This is essentially assertNotRaises(InconsistentDelta)
310
self.expectFailure('Cannot shelve replacing a root entry',
311
self.assertRaises, AssertionError,
312
self.assertRaises, errors.InconsistentDelta,
313
self.shelve_all, tree1, rev2)
315
def test_shelve_split(self):
316
outer_tree = self.make_branch_and_tree('outer')
317
outer_tree.commit('Add root')
318
inner_tree = self.make_branch_and_tree('outer/inner')
319
rev2 = inner_tree.commit('Add root')
320
outer_tree.subsume(inner_tree)
321
# This is essentially assertNotRaises(ValueError).
322
# The ValueError is 'None is not a valid file id'.
323
self.expectFailure('Cannot shelve a join back to the inner tree.',
324
self.assertRaises, AssertionError,
325
self.assertRaises, ValueError, self.shelve_all,
329
class TestApplyReporter(TestShelver):
331
def test_shelve_not_diff(self):
332
tree = self.create_shelvable_tree()
333
tree.lock_tree_write()
334
self.addCleanup(tree.unlock)
335
shelver = ExpectShelver(tree, tree.basis_tree(),
336
reporter=shelf_ui.ApplyReporter())
337
self.addCleanup(shelver.finalize)
338
shelver.expect('Apply change? [yNfq?]', 'n')
339
shelver.expect('Apply change? [yNfq?]', 'n')
340
# No final shelving prompt because no changes were selected
342
self.assertFileEqual(LINES_ZY, 'tree/foo')
344
def test_shelve_diff_no(self):
345
tree = self.create_shelvable_tree()
346
tree.lock_tree_write()
347
self.addCleanup(tree.unlock)
348
shelver = ExpectShelver(tree, tree.basis_tree(),
349
reporter=shelf_ui.ApplyReporter())
350
self.addCleanup(shelver.finalize)
351
shelver.expect('Apply change? [yNfq?]', 'y')
352
shelver.expect('Apply change? [yNfq?]', 'y')
353
shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
355
self.assertFileEqual(LINES_ZY, 'tree/foo')
357
def test_shelve_diff(self):
358
tree = self.create_shelvable_tree()
359
tree.lock_tree_write()
360
self.addCleanup(tree.unlock)
361
shelver = ExpectShelver(tree, tree.basis_tree(),
362
reporter=shelf_ui.ApplyReporter())
363
self.addCleanup(shelver.finalize)
364
shelver.expect('Apply change? [yNfq?]', 'y')
365
shelver.expect('Apply change? [yNfq?]', 'y')
366
shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
368
self.assertFileEqual(LINES_AJ, 'tree/foo')
370
def test_shelve_binary_change(self):
371
tree = self.create_shelvable_tree()
372
self.build_tree_contents([('tree/foo', '\x00')])
373
tree.lock_tree_write()
374
self.addCleanup(tree.unlock)
375
shelver = ExpectShelver(tree, tree.basis_tree(),
376
reporter=shelf_ui.ApplyReporter())
377
self.addCleanup(shelver.finalize)
378
shelver.expect('Apply binary changes? [yNfq?]', 'y')
379
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
381
self.assertFileEqual(LINES_AJ, 'tree/foo')
383
def test_shelve_rename(self):
384
tree = self.create_shelvable_tree()
385
tree.rename_one('foo', 'bar')
386
tree.lock_tree_write()
387
self.addCleanup(tree.unlock)
388
shelver = ExpectShelver(tree, tree.basis_tree(),
389
reporter=shelf_ui.ApplyReporter())
390
self.addCleanup(shelver.finalize)
391
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
392
shelver.expect('Apply change? [yNfq?]', 'y')
393
shelver.expect('Apply change? [yNfq?]', 'y')
394
shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
396
self.assertFileEqual(LINES_AJ, 'tree/foo')
398
def test_shelve_deletion(self):
399
tree = self.create_shelvable_tree()
400
os.unlink('tree/foo')
401
tree.lock_tree_write()
402
self.addCleanup(tree.unlock)
403
shelver = ExpectShelver(tree, tree.basis_tree(),
404
reporter=shelf_ui.ApplyReporter())
405
self.addCleanup(shelver.finalize)
406
shelver.expect('Add file "foo"? [yNfq?]', 'y')
407
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
409
self.assertFileEqual(LINES_AJ, 'tree/foo')
411
def test_shelve_creation(self):
412
tree = self.make_branch_and_tree('tree')
413
tree.commit('add tree root')
414
self.build_tree(['tree/foo'])
416
tree.lock_tree_write()
417
self.addCleanup(tree.unlock)
418
shelver = ExpectShelver(tree, tree.basis_tree(),
419
reporter=shelf_ui.ApplyReporter())
420
self.addCleanup(shelver.finalize)
421
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
422
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
424
self.failIfExists('tree/foo')
426
def test_shelve_kind_change(self):
427
tree = self.create_shelvable_tree()
428
os.unlink('tree/foo')
430
tree.lock_tree_write()
431
self.addCleanup(tree.unlock)
432
shelver = ExpectShelver(tree, tree.basis_tree(),
433
reporter=shelf_ui.ApplyReporter())
434
self.addCleanup(shelver.finalize)
435
shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
436
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
438
def test_shelve_modify_target(self):
439
self.requireFeature(tests.SymlinkFeature)
440
tree = self.create_shelvable_tree()
441
os.symlink('bar', 'tree/baz')
442
tree.add('baz', 'baz-id')
443
tree.commit("Add symlink")
444
os.unlink('tree/baz')
445
os.symlink('vax', 'tree/baz')
446
tree.lock_tree_write()
447
self.addCleanup(tree.unlock)
448
shelver = ExpectShelver(tree, tree.basis_tree(),
449
reporter=shelf_ui.ApplyReporter())
450
self.addCleanup(shelver.finalize)
451
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
453
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
455
self.assertEqual('bar', os.readlink('tree/baz'))
195
458
class TestUnshelver(tests.TestCaseWithTransport):
197
460
def create_tree_with_shelf(self):
198
461
tree = self.make_branch_and_tree('tree')
199
self.build_tree_contents([('tree/foo', LINES_AJ)])
200
tree.add('foo', 'foo-id')
201
tree.commit('added foo')
202
self.build_tree_contents([('tree/foo', LINES_ZY)])
203
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
464
self.build_tree_contents([('tree/foo', LINES_AJ)])
465
tree.add('foo', 'foo-id')
466
tree.commit('added foo')
467
self.build_tree_contents([('tree/foo', LINES_ZY)])
468
shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
469
auto_apply=True, auto=True)
207
478
def test_unshelve(self):