32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
37
class ExternalBase(TestCaseInTempDir):
30
from bzrlib.selftest import InTempDir, BzrTestBase
32
class ExternalBase(InTempDir):
38
34
def runbzr(self, args, retcode=0,backtick=False):
37
from subprocess import call
38
except ImportError, e:
39
42
if isinstance(args, basestring):
40
43
args = args.split()
147
152
os.rmdir('revertdir')
148
153
self.runbzr('revert')
150
def test_mv_modes(self):
156
def skipped_test_mv_modes(self):
151
157
"""Test two modes of operation for mv"""
152
158
from bzrlib.branch import Branch
153
159
b = Branch('.', init=True)
154
160
self.build_tree(['a', 'c', 'subdir/'])
155
self.run_bzr('add', self.test_dir)
156
161
self.run_bzr('mv', 'a', 'b')
157
162
self.run_bzr('mv', 'b', 'subdir')
158
163
self.run_bzr('mv', 'subdir/b', 'a')
159
self.run_bzr('mv', 'a', 'c', 'subdir')
164
self.run_bzr('mv', 'a', 'b', 'subdir')
160
165
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
163
167
def test_main_version(self):
164
168
"""Check output from version command and master option is reasonable"""
165
169
# output is intentionally passed through to stdout so that we
175
179
self.log(tmp_output)
176
180
self.assertEquals(output, tmp_output)
178
def example_branch(test):
180
file('hello', 'wt').write('foo')
181
test.runbzr('add hello')
182
test.runbzr('commit -m setup hello')
183
file('goodbye', 'wt').write('baz')
184
test.runbzr('add goodbye')
185
test.runbzr('commit -m setup goodbye')
187
def test_revert(self):
188
self.example_branch()
189
file('hello', 'wt').write('bar')
190
file('goodbye', 'wt').write('qux')
191
self.runbzr('revert hello')
192
self.check_file_contents('hello', 'foo')
193
self.check_file_contents('goodbye', 'qux')
194
self.runbzr('revert')
195
self.check_file_contents('goodbye', 'baz')
197
def test_merge(self):
198
from bzrlib.branch import Branch
202
self.example_branch()
204
self.runbzr('branch a b')
206
file('goodbye', 'wt').write('quux')
207
self.runbzr(['commit', '-m', "more u's are always good"])
210
file('hello', 'wt').write('quuux')
211
# We can't merge when there are in-tree changes
212
self.runbzr('merge ../b', retcode=1)
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
214
self.runbzr('merge ../b')
215
self.check_file_contents('goodbye', 'quux')
216
# Merging a branch pulls its revision into the tree
219
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()
230
self.runbzr('pull', retcode=1)
231
self.runbzr('missing', retcode=1)
232
self.runbzr('missing .')
233
self.runbzr('missing')
235
self.runbzr('pull /', retcode=1)
239
self.runbzr('branch a b')
242
self.runbzr('commit -m blah --unchanged')
246
assert a.revision_history() == b.revision_history()[:-1]
247
self.runbzr('pull ../b')
248
assert a.revision_history() == b.revision_history()
249
self.runbzr('commit -m blah2 --unchanged')
251
self.runbzr('commit -m blah3 --unchanged')
252
self.runbzr('pull ../a', retcode=1)
254
self.runbzr('merge ../b')
255
self.runbzr('commit -m blah4 --unchanged')
257
self.runbzr('pull ../a')
258
assert a.revision_history()[-1] == b.revision_history()[-1]
261
def test_add_reports(self):
262
"""add command prints the names of added files."""
263
b = Branch('.', init=True)
264
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
266
from cStringIO import StringIO
269
ret = self.apply_redirected(None, out, None,
272
self.assertEquals(ret, 0)
274
# the ordering is not defined at the moment
275
results = sorted(out.getvalue().rstrip('\n').split('\n'))
276
self.assertEquals(['added dir',
282
182
class OldTests(ExternalBase):
283
"""old tests moved from ./testbzr."""
183
# old tests moved from ./testbzr
285
184
def test_bzr(self):
286
185
from os import chdir, mkdir
287
186
from os.path import exists
289
189
runbzr = self.runbzr
290
190
backtick = self.backtick
354
def example_branch(test):
357
file('hello', 'wt').write('foo')
358
test.runbzr('add hello')
359
test.runbzr('commit -m setup hello')
361
file('goodbye', 'wt').write('baz')
362
test.runbzr('add goodbye')
363
test.runbzr('commit -m setup goodbye')
366
class RevertCommand(ExternalBase):
369
file('hello', 'wt').write('bar')
370
file('goodbye', 'wt').write('qux')
371
self.runbzr('revert hello')
372
self.check_file_contents('hello', 'foo')
373
self.check_file_contents('goodbye', 'qux')
374
self.runbzr('revert')
375
self.check_file_contents('goodbye', 'baz')
378
class MergeCommand(ExternalBase):
380
from bzrlib.branch import Branch
381
from bzrlib.commands import run_bzr
389
self.runbzr('branch a b')
391
file('goodbye', 'wt').write('quux')
392
self.runbzr(['commit', '-m', "more u's are always good"])
395
file('hello', 'wt').write('quuux')
396
# We can't merge when there are in-tree changes
397
self.runbzr('merge ../b', retcode=1)
398
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
399
self.runbzr('merge ../b')
400
self.check_file_contents('goodbye', 'quux')
401
# Merging a branch pulls its revision into the tree
404
a.get_revision_xml(b.last_patch())
406
self.log('pending merges: %s', a.pending_merges())
407
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
408
# % (a.pending_merges(), b.last_patch())