31
32
self.__test_loop(10)
33
34
def __test_loop(self, count):
34
from bzrlib.branch import Branch
35
b = Branch.initialize('.')
37
# Create a test file and commit it
38
file('test_file', 'w').write(self.ORIGINAL)
39
b.working_tree().add('test_file')
40
b.working_tree().commit(message='add test_file')
35
tree = self.make_branch_and_tree('.')
36
self.__create_and_add_test_file(tree)
59
55
self.assertEqual(file('test_file').read(), self.ORIGINAL)
61
57
# Check the shelf is right
62
shelf = b._transport.get('.bzr/x-shelf/default/00').read()
58
shelf = open(os.path.join(tree.branch.base,
59
'.shelf/shelves/default/00')).read()
60
shelf = shelf[shelf.index('\n') + 1:] # skip the message
63
61
self.assertEqual(shelf, self.DIFF_1)
75
73
def test_shelf_nothing_to_shelve(self):
77
from bzrlib.branch import Branch
78
b = Branch.initialize('.')
80
# Create a test file and commit it
81
file('test_file', 'w').write(self.ORIGINAL)
82
b.working_tree().add('test_file')
83
b.working_tree().commit(message='add test_file')
75
tree = self.make_branch_and_tree('.')
76
self.__create_and_add_test_file(tree)
85
78
# Shelve the changes
86
79
self.run_bzr('shelve', retcode=3)
88
if b._transport.has('.bzr/x-shelf/default/00'):
81
if os.path.exists(os.path.join(tree.branch.base,
82
'.shelf/shelves/default/00')):
89
83
self.fail("Shelf exists, but it shouldn't")
85
def __create_and_add_test_file(self, tree):
86
self.build_tree_contents([('test_file', self.ORIGINAL)])
88
tree.commit(message='add test_file')
91
90
def test_shelf_with_revision(self):
92
from bzrlib.branch import Branch
93
b = Branch.initialize('.')
91
tree = self.make_branch_and_tree('.')
95
# Create a test file and commit it
96
file('test_file', 'w').write(self.ORIGINAL)
97
b.working_tree().add('test_file')
98
b.working_tree().commit(message='add test_file')
93
self.__create_and_add_test_file(tree)
100
95
# Modify the test file and commit it
101
file('test_file', 'w').write(self.MODIFIED)
102
b.working_tree().commit(message='update test_file')
96
self.build_tree_contents([('test_file', self.MODIFIED)])
97
tree.commit(message='update test_file')
104
99
# Shelve the changes
105
100
self.run_bzr('shelve', '-r', '1', retcode=0)
118
113
self.assertEqual(file('test_file').read(), self.MODIFIED)
120
115
def test_shelf_with_two_revisions(self):
121
from bzrlib.branch import Branch
122
b = Branch.initialize('.')
116
tree = self.make_branch_and_tree('.')
124
118
cmd = 'shelve -r 1..2'
125
119
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
145
139
file('foo', 'wb').write('baz')
146
140
self.run_bzr('shelve', 'foo', retcode=0)
142
def test_shelf_show_basic(self):
143
tree = self.make_branch_and_tree('.')
144
self.__create_and_add_test_file(tree)
145
self.__test_show(tree, '00')
147
def __test_show(self, tree, patch):
148
# Modify the test file
149
self.build_tree_contents([('test_file', 'patch %s\n' % patch)])
152
self.run_bzr('shelve', retcode=0)
154
# Make sure there is no diff anymore
155
self.assertEqual(self.capture('diff', retcode=0), '')
157
# Check the shelf is right
158
shelf = open(os.path.join(tree.branch.base,
159
'.shelf/shelves/default', patch)).read()
160
self.assertTrue('patch %s' % patch in shelf)
162
# Check the shown output is right
163
shown = self.capture('shelf show %s' % patch, retcode=0)
164
self.assertEqual(shown, shelf)
166
def test_shelf_show_multi(self):
167
tree = self.make_branch_and_tree('.')
168
self.__create_and_add_test_file(tree)
169
self.__test_show(tree, '00')
170
self.__test_show(tree, '01')
171
self.__test_show(tree, '02')
173
# Now check we can show a previously shelved patch
174
shelf = open(os.path.join(tree.branch.base,
175
'.shelf/shelves/default/00')).read()
176
self.assertTrue('patch 00' in shelf)
178
# Check the shown output is right
179
shown = self.capture('shelf show 00', retcode=0)
180
self.assertEqual(shown, shelf)
182
def test_shelf_show_with_no_patch(self):
183
tree = self.make_branch_and_tree('.')
184
stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
185
self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)