30
27
def test_shelf(self):
31
28
from bzrlib.branch import Branch
32
from bzrlib.workingtree import WorkingTree
33
29
b = Branch.initialize('.')
34
tree = WorkingTree(b.base, b)
36
31
# Create a test file and commit it
37
32
file('test_file', 'w').write(self.ORIGINAL)
39
tree.commit(message='add test_file')
34
b.commit(message='add test_file')
41
36
# Modify the test file
42
37
file('test_file', 'w').write(self.MODIFIED)
44
39
# Check the diff is right
45
self.assertEqual(self.capture('diff', retcode=1),
40
self.assertEqual(self.capture('diff'),
46
41
self.DIFF_HEADER + self.DIFF_1 + '\n')
48
43
# Shelve the changes
49
self.run_bzr('shelve', '--all', retcode=1)
44
self.run_bzr('shelve', '--all', retcode=True)
51
46
# Make sure there is no diff anymore
52
47
self.assertEqual(self.capture('diff'), '')
59
54
self.assertEqual(shelf, self.DIFF_1)
62
self.run_bzr('unshelve', retcode=1)
57
self.run_bzr('unshelve', retcode=True)
64
59
# Check the diff is right again
65
self.assertEqual(self.capture('diff', retcode=1),
60
self.assertEqual(self.capture('diff'),
66
61
self.DIFF_HEADER + self.DIFF_1 + '\n')
68
63
# Make sure the file is back the way it should be
69
64
self.assertEqual(file('test_file').read(), self.MODIFIED)
71
66
def test_shelf_nothing_to_shelve(self):
72
68
from bzrlib.branch import Branch
73
from bzrlib.workingtree import WorkingTree
74
69
b = Branch.initialize('.')
75
tree = WorkingTree(b.base, b)
77
71
# Create a test file and commit it
78
72
file('test_file', 'w').write(self.ORIGINAL)
80
tree.commit(message='add test_file')
74
b.commit(message='add test_file')
82
76
# Shelve the changes
83
self.run_bzr('shelve', '--all')
77
self.run_bzr('shelve', '--all', retcode=True)
85
79
if os.path.exists('.bzr-shelf'):
86
80
self.fail("Shelf exists, but it shouldn't")
88
82
def test_shelf_with_revision(self):
89
83
from bzrlib.branch import Branch
90
from bzrlib.workingtree import WorkingTree
91
84
b = Branch.initialize('.')
92
tree = WorkingTree(b.base, b)
94
86
# Create a test file and commit it
95
87
file('test_file', 'w').write(self.ORIGINAL)
97
tree.commit(message='add test_file')
89
b.commit(message='add test_file')
99
91
# Modify the test file and commit it
100
92
file('test_file', 'w').write(self.MODIFIED)
101
tree.commit(message='update test_file')
93
b.commit(message='update test_file')
103
95
# Shelve the changes
104
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=True)
106
98
# Check the diff is right
107
self.assertEqual(self.capture('diff', retcode=1),
99
self.assertEqual(self.capture('diff'),
108
100
self.DIFF_HEADER + self.DIFF_2 + '\n')
110
102
# Make sure the file is the way it should be
111
103
self.assertEqual(file('test_file').read(), self.ORIGINAL)
114
self.run_bzr('unshelve', retcode=1)
106
self.run_bzr('unshelve', retcode=True)
116
108
# Make sure the file is back the way it should be
117
109
self.assertEqual(file('test_file').read(), self.MODIFIED)
124
116
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
126
118
self.assertEqual(stderr.split('\n')[0],
127
'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only accepts a single revision parameter.')
129
def test_shelf_with_whitespace(self):
130
"""Shows that bzr doesn't handle whitespace well"""
132
file('file name', 'wb').write('hello')
134
self.run_bzr('commit', '-m', 'added')
135
file('file name', 'wb').write('goodbye')
136
self.run_bzr('shelve', '--all', 'file name', retcode=1)
138
def test_whitespace_branches(self):
139
os.mkdir('name with space')
140
os.chdir('name with space')
142
file('filename', 'wb').write('hello')
144
self.run_bzr('commit', '-m', 'added')
145
file('filename', 'wb').write('goodbye')
146
self.run_bzr('shelve', '--all', 'filename', retcode=1)
119
'bzr: ERROR: shelve only accepts a single revision parameter.')