5
class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
6
ORIGINAL = '\n\nhello test world\n\n'
7
MODIFIED = '\n\ngoodbye test world\n\n'
8
DIFF_HEADER = "=== modified file 'test_file'\n"
9
DIFF_1 = """--- test_file
18
DIFF_2 = """--- test_file
28
from bzrlib.branch import Branch
29
b = Branch.initialize('.')
31
# Create a test file and commit it
32
file('test_file', 'w').write(self.ORIGINAL)
34
b.commit(message='add test_file')
36
# Modify the test file
37
file('test_file', 'w').write(self.MODIFIED)
39
# Check the diff is right
40
self.assertEqual(self.capture('diff'),
41
self.DIFF_HEADER + self.DIFF_1 + '\n')
44
self.run_bzr('shelve', '--all', retcode=True)
46
# Make sure there is no diff anymore
47
self.assertEqual(self.capture('diff'), '')
49
# Make sure the file is actually back the way it was
50
self.assertEqual(file('test_file').read(), self.ORIGINAL)
52
# Check the shelf is right
53
shelf = file('.bzr-shelf').read()
54
self.assertEqual(shelf, self.DIFF_1)
57
self.run_bzr('unshelve', retcode=True)
59
# Check the diff is right again
60
self.assertEqual(self.capture('diff'),
61
self.DIFF_HEADER + self.DIFF_1 + '\n')
63
# Make sure the file is back the way it should be
64
self.assertEqual(file('test_file').read(), self.MODIFIED)
66
def test_shelf_nothing_to_shelve(self):
68
from bzrlib.branch import Branch
69
b = Branch.initialize('.')
71
# Create a test file and commit it
72
file('test_file', 'w').write(self.ORIGINAL)
74
b.commit(message='add test_file')
77
self.run_bzr('shelve', '--all', retcode=True)
79
if os.path.exists('.bzr-shelf'):
80
self.fail("Shelf exists, but it shouldn't")
82
def test_shelf_with_revision(self):
83
from bzrlib.branch import Branch
84
b = Branch.initialize('.')
86
# Create a test file and commit it
87
file('test_file', 'w').write(self.ORIGINAL)
89
b.commit(message='add test_file')
91
# Modify the test file and commit it
92
file('test_file', 'w').write(self.MODIFIED)
93
b.commit(message='update test_file')
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=True)
98
# Check the diff is right
99
self.assertEqual(self.capture('diff'),
100
self.DIFF_HEADER + self.DIFF_2 + '\n')
102
# Make sure the file is the way it should be
103
self.assertEqual(file('test_file').read(), self.ORIGINAL)
106
self.run_bzr('unshelve', retcode=True)
108
# Make sure the file is back the way it should be
109
self.assertEqual(file('test_file').read(), self.MODIFIED)
111
def test_shelf_with_two_revisions(self):
112
from bzrlib.branch import Branch
113
b = Branch.initialize('.')
115
cmd = 'shelve -r 1..2'
116
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
118
self.assertEqual(stderr.split('\n')[0],
119
'bzr: ERROR: shelve only accepts a single revision parameter.')