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