5
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
5
class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
6
6
ORIGINAL = '\n\nhello test world\n\n'
7
7
MODIFIED = '\n\ngoodbye test world\n\n'
8
8
DIFF_HEADER = "=== modified file 'test_file'\n"
9
DIFF_1 = """--- test_file\t
9
DIFF_1 = """--- test_file
31
31
# Create a test file and commit it
32
32
file('test_file', 'w').write(self.ORIGINAL)
33
b.working_tree().add('test_file')
34
b.working_tree().commit(message='add test_file')
34
b.commit(message='add test_file')
36
36
# Modify the test file
37
37
file('test_file', 'w').write(self.MODIFIED)
41
41
self.DIFF_HEADER + self.DIFF_1 + '\n')
43
43
# Shelve the changes
44
self.run_bzr('shelve', '--all', retcode=1)
44
self.run_bzr('shelve', '--all', retcode=True)
46
46
# Make sure there is no diff anymore
47
47
self.assertEqual(self.capture('diff'), '')
54
54
self.assertEqual(shelf, self.DIFF_1)
57
self.run_bzr('unshelve', retcode=1)
57
self.run_bzr('unshelve', retcode=True)
59
59
# Check the diff is right again
60
60
self.assertEqual(self.capture('diff', retcode=1),
71
71
# Create a test file and commit it
72
72
file('test_file', 'w').write(self.ORIGINAL)
73
b.working_tree().add('test_file')
74
b.working_tree().commit(message='add test_file')
74
b.commit(message='add test_file')
76
76
# Shelve the changes
77
self.run_bzr('shelve', '--all')
77
self.run_bzr('shelve', '--all', retcode=True)
79
79
if os.path.exists('.bzr-shelf'):
80
80
self.fail("Shelf exists, but it shouldn't")
86
86
# Create a test file and commit it
87
87
file('test_file', 'w').write(self.ORIGINAL)
88
b.working_tree().add('test_file')
89
b.working_tree().commit(message='add test_file')
89
b.commit(message='add test_file')
91
91
# Modify the test file and commit it
92
92
file('test_file', 'w').write(self.MODIFIED)
93
b.working_tree().commit(message='update test_file')
93
b.commit(message='update test_file')
95
95
# Shelve the changes
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=True)
98
98
# Check the diff is right
99
99
self.assertEqual(self.capture('diff', retcode=1),
103
103
self.assertEqual(file('test_file').read(), self.ORIGINAL)
106
self.run_bzr('unshelve', retcode=1)
106
self.run_bzr('unshelve', retcode=True)
108
108
# Make sure the file is back the way it should be
109
109
self.assertEqual(file('test_file').read(), self.MODIFIED)
118
118
self.assertEqual(stderr.split('\n')[0],
119
119
'bzr: ERROR: shelve only accepts a single revision parameter.')
121
def test_shelf_with_whitespace(self):
122
"""Shows that bzr doesn't handle whitespace well"""
124
file('file name', 'wb').write('hello')
126
self.run_bzr('commit', '-m', 'added')
127
file('file name', 'wb').write('goodbye')
128
self.run_bzr('shelve', '--all', 'file name', retcode=1)
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)
141
def test_long_filename(self):
142
"""Regression test for diffstat with long filenames.
144
Create a branch with two files, one of which has a long name. Commit.
145
Modify both files. Shelve the file with the short name. If diffstat
146
has regressed, it will generate a diffstat of the file with the long
151
file(filename, 'wb').write('hello')
152
file('foo', 'wb').write('bar')
154
self.run_bzr('commit', '-m', 'added')
155
file(filename, 'wb').write('goodbye')
156
file('foo', 'wb').write('baz')
157
self.run_bzr('shelve', '--all', 'foo', retcode=1)