1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
66
62
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
69
class ShelfTestCase(tests.TestCaseWithTransport):
65
class TestShelver(tests.TestCaseWithTransport):
71
67
def create_shelvable_tree(self):
72
68
tree = self.make_branch_and_tree('tree')
76
72
self.build_tree_contents([('tree/foo', LINES_ZY)])
80
class TestShelver(ShelfTestCase):
82
75
def test_unexpected_prompt_failure(self):
83
76
tree = self.create_shelvable_tree()
84
77
tree.lock_tree_write()
196
189
shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
197
190
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
199
self.assertPathDoesNotExist('tree/foo')
192
self.failIfExists('tree/foo')
201
194
def test_shelve_kind_change(self):
202
195
tree = self.create_shelvable_tree()
211
204
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
213
206
def test_shelve_modify_target(self):
214
self.requireFeature(features.SymlinkFeature)
207
self.requireFeature(tests.SymlinkFeature)
215
208
tree = self.create_shelvable_tree()
216
209
os.symlink('bar', 'tree/baz')
217
210
tree.add('baz', 'baz-id')
308
def test_shelve_old_root_preserved(self):
301
def test_shelve_old_root_deleted(self):
309
302
tree1 = self.make_branch_and_tree('tree1')
310
303
tree1.commit('add root')
311
tree1_root_id = tree1.get_root_id()
312
304
tree2 = self.make_branch_and_tree('tree2')
313
305
rev2 = tree2.commit('add root')
314
self.assertNotEquals(tree1_root_id, tree2.get_root_id())
315
306
tree1.merge_from_branch(tree2.branch,
316
307
from_revision=revision.NULL_REVISION)
317
tree1.commit('merging in tree2')
318
self.assertEquals(tree1_root_id, tree1.get_root_id())
308
tree1.commit('Replaced root entry')
319
309
# This is essentially assertNotRaises(InconsistentDelta)
320
# With testtools 0.9.9, it can be rewritten as:
321
# with ExpectedException(AssertionError,
322
# 'InconsistentDelta not raised'):
323
# with ExpectedException(errors.InconsistentDelta, ''):
324
# self.shelve_all(tree1, rev2)
325
e = self.assertRaises(AssertionError, self.assertRaises,
326
errors.InconsistentDelta, self.shelve_all, tree1,
328
self.assertContainsRe('InconsistentDelta not raised', str(e))
310
self.expectFailure('Cannot shelve replacing a root entry',
311
self.assertRaises, AssertionError,
312
self.assertRaises, errors.InconsistentDelta,
313
self.shelve_all, tree1, rev2)
330
315
def test_shelve_split(self):
331
316
outer_tree = self.make_branch_and_tree('outer')
436
421
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
437
422
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
439
self.assertPathDoesNotExist('tree/foo')
424
self.failIfExists('tree/foo')
441
426
def test_shelve_kind_change(self):
442
427
tree = self.create_shelvable_tree()
451
436
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
453
438
def test_shelve_modify_target(self):
454
self.requireFeature(features.SymlinkFeature)
439
self.requireFeature(tests.SymlinkFeature)
455
440
tree = self.create_shelvable_tree()
456
441
os.symlink('bar', 'tree/baz')
457
442
tree.add('baz', 'baz-id')
519
504
self.assertFileEqual(LINES_AJ, 'tree/foo')
520
505
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
522
def test_unshelve_args_preview(self):
523
tree = self.create_tree_with_shelf()
524
write_diff_to = StringIO()
525
unshelver = shelf_ui.Unshelver.from_args(
526
directory='tree', action='preview', write_diff_to=write_diff_to)
530
unshelver.tree.unlock()
531
# The changes were not unshelved.
532
self.assertFileEqual(LINES_AJ, 'tree/foo')
533
self.assertEqual(1, tree.get_shelf_manager().last_shelf())
535
# But the diff was written to write_diff_to.
536
diff = write_diff_to.getvalue()
537
expected = dedent("""\
552
self.assertEqualDiff(expected, diff[-len(expected):])
554
507
def test_unshelve_args_delete_only(self):
555
508
tree = self.make_branch_and_tree('tree')
556
509
manager = tree.get_shelf_manager()