27
27
def test_shelf(self):
30
def test_shelf_multi(self):
33
def __test_loop(self, count):
28
34
from bzrlib.branch import Branch
29
35
b = Branch.initialize('.')
31
37
# Create a test file and commit it
32
38
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', retcode=1),
41
self.DIFF_HEADER + self.DIFF_1 + '\n')
44
self.run_bzr('shelve', '--all', retcode=1)
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')
59
# Check the diff is right again
60
self.assertEqual(self.capture('diff', retcode=1),
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)
39
b.working_tree().add('test_file')
40
b.working_tree().commit(message='add test_file')
45
# Modify the test file
46
file('test_file', 'w').write(self.MODIFIED)
48
# Check the diff is right
49
self.assertEqual(self.capture('diff', retcode=1),
50
self.DIFF_HEADER + self.DIFF_1 + '\n')
53
self.run_bzr('shelve', retcode=True)
55
# Make sure there is no diff anymore
56
self.assertEqual(self.capture('diff', retcode=0), '')
58
# Make sure the file is actually back the way it was
59
self.assertEqual(file('test_file').read(), self.ORIGINAL)
61
# Check the shelf is right
62
shelf = b._transport.get('.bzr/x-shelf/default/00').read()
63
self.assertEqual(shelf, self.DIFF_1)
66
self.run_bzr('unshelve', retcode=True)
68
# Check the diff is right again
69
self.assertEqual(self.capture('diff', retcode=1),
70
self.DIFF_HEADER + self.DIFF_1 + '\n')
72
# Make sure the file is back the way it should be
73
self.assertEqual(file('test_file').read(), self.MODIFIED)
66
75
def test_shelf_nothing_to_shelve(self):
71
80
# Create a test file and commit it
72
81
file('test_file', 'w').write(self.ORIGINAL)
74
b.commit(message='add test_file')
82
b.working_tree().add('test_file')
83
b.working_tree().commit(message='add test_file')
76
85
# Shelve the changes
77
self.run_bzr('shelve', '--all')
86
self.run_bzr('shelve', retcode=True)
79
if os.path.exists('.bzr-shelf'):
88
if b._transport.has('.bzr/x-shelf/default/00'):
80
89
self.fail("Shelf exists, but it shouldn't")
82
91
def test_shelf_with_revision(self):
86
95
# Create a test file and commit it
87
96
file('test_file', 'w').write(self.ORIGINAL)
89
b.commit(message='add test_file')
97
b.working_tree().add('test_file')
98
b.working_tree().commit(message='add test_file')
91
100
# Modify the test file and commit it
92
101
file('test_file', 'w').write(self.MODIFIED)
93
b.commit(message='update test_file')
102
b.working_tree().commit(message='update test_file')
95
104
# Shelve the changes
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
105
self.run_bzr('shelve', '-r', '1', retcode=True)
98
107
# Check the diff is right
99
108
self.assertEqual(self.capture('diff', retcode=1),
116
125
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
118
127
self.assertEqual(stderr.split('\n')[0],
119
'bzr: ERROR: shelve only accepts a single revision parameter.')
121
def disabled_test_shelf_with_whitespace(self):
122
"""Shows that bzr doesn't handle whitespace well"""
124
file('file\t name', 'wb').write('hello')
126
self.run_bzr('commit', '-m', 'added')
127
file('file\t name', 'wb').write('goodbye')
128
self.run_bzr('shelve', '--all', 'file name')
130
def test_whitespace_branches(self):
131
os.mkdir('name with space')
132
os.chdir('name with space')
134
file('filename', 'wb').write('hello')
136
self.run_bzr('commit', '-m', 'added')
137
file('filename', 'wb').write('goodbye')
138
self.run_bzr('shelve', '--all', 'filename', retcode=1)
128
'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only ' \
129
'accepts a single revision parameter.')