30
from bzrlib.selftest import InTempDir, BzrTestBase
33
class ExternalBase(InTempDir):
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
37
class ExternalBase(TestCaseInTempDir):
35
38
def runbzr(self, args, retcode=0,backtick=False):
38
from subprocess import call
39
except ImportError, e:
43
39
if isinstance(args, basestring):
44
40
args = args.split()
178
173
self.log(tmp_output)
179
174
self.assertEquals(output, tmp_output)
176
def example_branch(test):
178
file('hello', 'wt').write('foo')
179
test.runbzr('add hello')
180
test.runbzr('commit -m setup hello')
181
file('goodbye', 'wt').write('baz')
182
test.runbzr('add goodbye')
183
test.runbzr('commit -m setup goodbye')
185
def test_revert(self):
186
self.example_branch()
187
file('hello', 'wt').write('bar')
188
file('goodbye', 'wt').write('qux')
189
self.runbzr('revert hello')
190
self.check_file_contents('hello', 'foo')
191
self.check_file_contents('goodbye', 'qux')
192
self.runbzr('revert')
193
self.check_file_contents('goodbye', 'baz')
195
def test_merge(self):
196
from bzrlib.branch import Branch
201
self.example_branch()
203
self.runbzr('branch a b')
205
file('goodbye', 'wt').write('quux')
206
self.runbzr(['commit', '-m', "more u's are always good"])
209
file('hello', 'wt').write('quuux')
210
# We can't merge when there are in-tree changes
211
self.runbzr('merge ../b', retcode=1)
212
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
213
self.runbzr('merge ../b')
214
self.check_file_contents('goodbye', 'quux')
215
# Merging a branch pulls its revision into the tree
218
a.get_revision_xml(b.last_patch())
220
self.log('pending merges: %s', a.pending_merges())
221
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
# % (a.pending_merges(), b.last_patch())
225
"""Pull changes from one branch to another."""
229
self.example_branch()
231
self.runbzr('branch a b')
233
self.runbzr('commit -m blah --unchanged')
237
assert a.revision_history() == b.revision_history()[:-1]
238
self.runbzr('pull ../b')
239
assert a.revision_history() == b.revision_history()
240
self.runbzr('commit -m blah2 --unchanged')
242
self.runbzr('commit -m blah3 --unchanged')
243
self.runbzr('pull ../a', retcode=1)
245
self.runbzr('merge ../b')
246
self.runbzr('commit -m blah4 --unchanged')
248
self.runbzr('pull ../a')
249
assert a.revision_history()[-1] == b.revision_history()[-1]
252
def test_add_reports(self):
253
"""add command prints the names of added files."""
254
b = Branch('.', init=True)
255
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
257
from cStringIO import StringIO
260
ret = self.apply_redirected(None, out, None,
263
self.assertEquals(ret, 0)
265
# the ordering is not defined at the moment
266
results = sorted(out.getvalue().rstrip('\n').split('\n'))
267
self.assertEquals(['added dir',
181
273
class OldTests(ExternalBase):
182
# old tests moved from ./testbzr
274
"""old tests moved from ./testbzr."""
183
276
def test_bzr(self):
184
277
from os import chdir, mkdir
185
278
from os.path import exists
188
280
runbzr = self.runbzr
189
281
backtick = self.backtick