1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#!/usr/bin/python
import os
import bzrlib.tests
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
ORIGINAL = '\n\nhello test world\n\n'
MODIFIED = '\n\ngoodbye test world\n\n'
DIFF_HEADER = "=== modified file 'a/test_file'\n"
DIFF_1 = """--- a/test_file\t
+++ b/test_file\t
@@ -1,4 +1,4 @@
-hello test world
+goodbye test world
"""
DIFF_2 = """--- a/test_file\t
+++ b/test_file\t
@@ -1,4 +1,4 @@
-goodbye test world
+hello test world
"""
def test_shelf(self):
from bzrlib.bzrdir import BzrDir
tree = BzrDir.create_standalone_workingtree('.')
# Create a test file and commit it
file('test_file', 'w').write(self.ORIGINAL)
tree.add('test_file')
tree.commit(message='add test_file')
# Modify the test file
file('test_file', 'w').write(self.MODIFIED)
# Check the diff is right
self.assertEqualDiff(self.capture('diff', retcode=1),
self.DIFF_HEADER + self.DIFF_1 + '\n')
# Shelve the changes
self.run_bzr('shelve', '--all', retcode=1)
# Make sure there is no diff anymore
self.assertEqual(self.capture('diff'), '')
# Make sure the file is actually back the way it was
self.assertEqualDiff(file('test_file').read(), self.ORIGINAL)
# Check the shelf is right
shelf = file('.bzr-shelf').read()
self.assertEqual(shelf, self.DIFF_1)
# Unshelve
self.run_bzr('unshelve', retcode=1)
# Check the diff is right again
self.assertEqual(self.capture('diff', retcode=1),
self.DIFF_HEADER + self.DIFF_1 + '\n')
# Make sure the file is back the way it should be
self.assertEqual(file('test_file').read(), self.MODIFIED)
def test_shelf_nothing_to_shelve(self):
import os.path
from bzrlib.bzrdir import BzrDir
tree = BzrDir.create_standalone_workingtree('.')
# Create a test file and commit it
file('test_file', 'w').write(self.ORIGINAL)
tree.add('test_file')
tree.commit(message='add test_file')
# Shelve the changes
self.run_bzr('shelve', '--all')
if os.path.exists('.bzr-shelf'):
self.fail("Shelf exists, but it shouldn't")
def test_shelf_with_revision(self):
from bzrlib.bzrdir import BzrDir
tree = BzrDir.create_standalone_workingtree('.')
# Create a test file and commit it
file('test_file', 'w').write(self.ORIGINAL)
tree.add('test_file')
tree.commit(message='add test_file')
# Modify the test file and commit it
file('test_file', 'w').write(self.MODIFIED)
tree.commit(message='update test_file')
# Shelve the changes
self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
# Check the diff is right
self.assertEqual(self.capture('diff', retcode=1),
self.DIFF_HEADER + self.DIFF_2 + '\n')
# Make sure the file is the way it should be
self.assertEqual(file('test_file').read(), self.ORIGINAL)
# Unshelve
self.run_bzr('unshelve', retcode=1)
# Make sure the file is back the way it should be
self.assertEqual(file('test_file').read(), self.MODIFIED)
def test_shelf_with_two_revisions(self):
from bzrlib.bzrdir import BzrDir
tree = BzrDir.create_standalone_workingtree('.')
cmd = 'shelve -r 1..2'
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=3)
self.assertEqual(stderr.split('\n')[0],
'bzr: ERROR: shelve only accepts a single revision parameter.')
def test_shelf_with_whitespace(self):
"""Shows that bzr doesn't handle whitespace well"""
self.run_bzr('init')
file('file name', 'wb').write('hello')
self.run_bzr('add')
self.run_bzr('commit', '-m', 'added')
file('file name', 'wb').write('goodbye')
self.run_bzr('shelve', '--all', 'file name', retcode=1)
def test_whitespace_branches(self):
os.mkdir('name with space')
os.chdir('name with space')
self.run_bzr('init')
file('filename', 'wb').write('hello')
self.run_bzr('add')
self.run_bzr('commit', '-m', 'added')
file('filename', 'wb').write('goodbye')
self.run_bzr('shelve', '--all', 'filename', retcode=1)
os.chdir('..')
def test_long_filename(self):
"""Regression test for diffstat with long filenames.
Create a branch with two files, one of which has a long name. Commit.
Modify both files. Shelve the file with the short name. If diffstat
has regressed, it will generate a diffstat of the file with the long
name, and break.
"""
self.run_bzr('init')
filename = 'a' * 80
file(filename, 'wb').write('hello')
file('foo', 'wb').write('bar')
self.run_bzr('add')
self.run_bzr('commit', '-m', 'added')
file(filename, 'wb').write('goodbye')
file('foo', 'wb').write('baz')
self.run_bzr('shelve', '--all', 'foo', retcode=1)
|