5
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
6
ORIGINAL = '\n\nhello test world\n\n'
7
MODIFIED = '\n\ngoodbye test world\n\n'
8
DIFF_HEADER = "=== modified file 'test_file'\n"
9
DIFF_1 = """--- test_file\t
18
DIFF_2 = """--- test_file\t
28
from bzrlib.branch import Branch
29
b = Branch.initialize('.')
31
# Create a test file and commit it
32
file('test_file', 'w').write(self.ORIGINAL)
33
b.working_tree().add('test_file')
34
b.working_tree().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', retcode=1)
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)
66
def test_shelf_nothing_to_shelve(self):
68
from bzrlib.branch import Branch
69
b = Branch.initialize('.')
71
# Create a test file and commit it
72
file('test_file', 'w').write(self.ORIGINAL)
73
b.working_tree().add('test_file')
74
b.working_tree().commit(message='add test_file')
77
self.run_bzr('shelve', '--all')
79
if os.path.exists('.bzr-shelf'):
80
self.fail("Shelf exists, but it shouldn't")
82
def test_shelf_with_revision(self):
83
from bzrlib.branch import Branch
84
b = Branch.initialize('.')
86
# Create a test file and commit it
87
file('test_file', 'w').write(self.ORIGINAL)
88
b.working_tree().add('test_file')
89
b.working_tree().commit(message='add test_file')
91
# Modify the test file and commit it
92
file('test_file', 'w').write(self.MODIFIED)
93
b.working_tree().commit(message='update test_file')
96
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
98
# Check the diff is right
99
self.assertEqual(self.capture('diff', retcode=1),
100
self.DIFF_HEADER + self.DIFF_2 + '\n')
102
# Make sure the file is the way it should be
103
self.assertEqual(file('test_file').read(), self.ORIGINAL)
106
self.run_bzr('unshelve', retcode=1)
108
# Make sure the file is back the way it should be
109
self.assertEqual(file('test_file').read(), self.MODIFIED)
111
def test_shelf_with_two_revisions(self):
112
from bzrlib.branch import Branch
113
b = Branch.initialize('.')
115
cmd = 'shelve -r 1..2'
116
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
118
self.assertEqual(stderr.split('\n')[0],
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)