8
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
9
ORIGINAL = '\n\nhello test world\n\n'
10
MODIFIED = '\n\ngoodbye test world\n\n'
11
DIFF_HEADER = "=== modified file 'a/test_file'\n"
12
DIFF_1 = """--- a/test_file\t
21
DIFF_2 = """--- a/test_file\t
31
from bzrlib.bzrdir import BzrDir
32
tree = BzrDir.create_standalone_workingtree('.')
34
# Create a test file and commit it
35
file('test_file', 'w').write(self.ORIGINAL)
37
tree.commit(message='add test_file')
39
# Modify the test file
40
file('test_file', 'w').write(self.MODIFIED)
42
# Check the diff is right
43
self.assertEqualDiff(self.capture('diff', retcode=1),
44
self.DIFF_HEADER + self.DIFF_1 + '\n')
47
self.run_bzr('shelve', '--all', retcode=1)
49
# Make sure there is no diff anymore
50
self.assertEqual(self.capture('diff'), '')
52
# Make sure the file is actually back the way it was
53
self.assertEqualDiff(file('test_file').read(), self.ORIGINAL)
55
# Check the shelf is right
56
shelf = file('.bzr-shelf').read()
57
self.assertEqual(shelf, self.DIFF_1)
60
self.run_bzr('unshelve', retcode=1)
62
# Check the diff is right again
63
self.assertEqual(self.capture('diff', retcode=1),
64
self.DIFF_HEADER + self.DIFF_1 + '\n')
66
# Make sure the file is back the way it should be
67
self.assertEqual(file('test_file').read(), self.MODIFIED)
69
def test_shelf_nothing_to_shelve(self):
71
from bzrlib.bzrdir import BzrDir
72
tree = BzrDir.create_standalone_workingtree('.')
74
# Create a test file and commit it
75
file('test_file', 'w').write(self.ORIGINAL)
77
tree.commit(message='add test_file')
80
self.run_bzr('shelve', '--all')
82
if os.path.exists('.bzr-shelf'):
83
self.fail("Shelf exists, but it shouldn't")
85
def test_shelf_with_revision(self):
86
from bzrlib.bzrdir import BzrDir
87
tree = BzrDir.create_standalone_workingtree('.')
89
# Create a test file and commit it
90
file('test_file', 'w').write(self.ORIGINAL)
92
tree.commit(message='add test_file')
94
# Modify the test file and commit it
95
file('test_file', 'w').write(self.MODIFIED)
96
tree.commit(message='update test_file')
99
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
101
# Check the diff is right
102
self.assertEqual(self.capture('diff', retcode=1),
103
self.DIFF_HEADER + self.DIFF_2 + '\n')
105
# Make sure the file is the way it should be
106
self.assertEqual(file('test_file').read(), self.ORIGINAL)
109
self.run_bzr('unshelve', retcode=1)
111
# Make sure the file is back the way it should be
112
self.assertEqual(file('test_file').read(), self.MODIFIED)
114
def test_shelf_with_two_revisions(self):
115
from bzrlib.bzrdir import BzrDir
116
tree = BzrDir.create_standalone_workingtree('.')
118
cmd = 'shelve -r 1..2'
119
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=3)
121
self.assertEqual(stderr.split('\n')[0],
122
'bzr: ERROR: shelve only accepts a single revision parameter.')
124
def test_shelf_with_whitespace(self):
125
"""Shows that bzr doesn't handle whitespace well"""
127
file('file name', 'wb').write('hello')
129
self.run_bzr('commit', '-m', 'added')
130
file('file name', 'wb').write('goodbye')
131
self.run_bzr('shelve', '--all', 'file name', retcode=1)
133
def test_whitespace_branches(self):
134
os.mkdir('name with space')
135
os.chdir('name with space')
137
file('filename', 'wb').write('hello')
139
self.run_bzr('commit', '-m', 'added')
140
file('filename', 'wb').write('goodbye')
141
self.run_bzr('shelve', '--all', 'filename', retcode=1)
144
def test_long_filename(self):
145
"""Regression test for diffstat with long filenames.
147
Create a branch with two files, one of which has a long name. Commit.
148
Modify both files. Shelve the file with the short name. If diffstat
149
has regressed, it will generate a diffstat of the file with the long
154
file(filename, 'wb').write('hello')
155
file('foo', 'wb').write('bar')
157
self.run_bzr('commit', '-m', 'added')
158
file(filename, 'wb').write('goodbye')
159
file('foo', 'wb').write('baz')
160
self.run_bzr('shelve', '--all', 'foo', retcode=1)