36
37
class ExternalBase(TestCaseInTempDir):
37
def runbzr(self, args, retcode=0,backtick=False):
38
def runbzr(self, args, retcode=0, backtick=False):
38
39
if isinstance(args, basestring):
39
40
args = args.split()
42
return self.backtick(['python', self.BZRPATH,] + args,
43
return self.run_bzr_captured(args, retcode=retcode)[0]
45
return self.runcmd(['python', self.BZRPATH,] + args,
45
return self.run_bzr_captured(args, retcode=retcode)
49
48
class TestCommands(ExternalBase):
92
91
def test_ignore_patterns(self):
93
92
from bzrlib.branch import Branch
95
b = Branch('.', init=True)
94
b = Branch.initialize('.')
96
95
self.assertEquals(list(b.unknowns()), [])
98
97
file('foo.tmp', 'wt').write('tmp files are ignored')
99
98
self.assertEquals(list(b.unknowns()), [])
100
assert self.backtick('bzr unknowns') == ''
99
assert self.capture('unknowns') == ''
102
101
file('foo.c', 'wt').write('int main() {}')
103
102
self.assertEquals(list(b.unknowns()), ['foo.c'])
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
103
assert self.capture('unknowns') == 'foo.c\n'
106
105
self.runbzr(['add', 'foo.c'])
107
assert self.backtick('bzr unknowns') == ''
106
assert self.capture('unknowns') == ''
109
108
# 'ignore' works when creating the .bzignore file
110
109
file('foo.blah', 'wt').write('blah')
116
115
# 'ignore' works when then .bzrignore file already exists
117
116
file('garh', 'wt').write('garh')
118
117
self.assertEquals(list(b.unknowns()), ['garh'])
119
assert self.backtick('bzr unknowns') == 'garh\n'
118
assert self.capture('unknowns') == 'garh\n'
120
119
self.runbzr('ignore garh')
121
120
self.assertEquals(list(b.unknowns()), [])
122
121
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
124
123
def test_revert(self):
126
124
self.runbzr('init')
128
126
file('hello', 'wt').write('foo')
147
145
os.rmdir('revertdir')
148
146
self.runbzr('revert')
150
def skipped_test_mv_modes(self):
148
def test_mv_modes(self):
151
149
"""Test two modes of operation for mv"""
152
150
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
151
b = Branch.initialize('.')
154
152
self.build_tree(['a', 'c', 'subdir/'])
153
self.run_bzr('add', self.test_dir)
155
154
self.run_bzr('mv', 'a', 'b')
156
155
self.run_bzr('mv', 'b', 'subdir')
157
156
self.run_bzr('mv', 'subdir/b', 'a')
158
self.run_bzr('mv', 'a', 'b', 'subdir')
157
self.run_bzr('mv', 'a', 'c', 'subdir')
159
158
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
161
161
def test_main_version(self):
162
162
"""Check output from version command and master option is reasonable"""
163
163
# output is intentionally passed through to stdout so that we
214
212
self.runbzr('merge ../b')
215
213
self.check_file_contents('goodbye', 'quux')
216
214
# Merging a branch pulls its revision into the tree
216
b = Branch.open('../b')
219
217
a.get_revision_xml(b.last_patch())
221
218
self.log('pending merges: %s', a.pending_merges())
222
219
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
220
# % (a.pending_merges(), b.last_patch())
223
"""Pull changes from one branch to another."""
227
self.example_branch()
228
self.runbzr('pull', retcode=1)
229
self.runbzr('missing', retcode=1)
230
self.runbzr('missing .')
231
self.runbzr('missing')
233
self.runbzr('pull /', retcode=1)
237
self.runbzr('branch a b')
240
self.runbzr('commit -m blah --unchanged')
243
b = Branch.open('../b')
244
assert a.revision_history() == b.revision_history()[:-1]
245
self.runbzr('pull ../b')
246
assert a.revision_history() == b.revision_history()
247
self.runbzr('commit -m blah2 --unchanged')
249
self.runbzr('commit -m blah3 --unchanged')
250
self.runbzr('pull ../a', retcode=1)
252
self.runbzr('merge ../b')
253
self.runbzr('commit -m blah4 --unchanged')
255
self.runbzr('pull ../a')
256
assert a.revision_history()[-1] == b.revision_history()[-1]
226
259
def test_add_reports(self):
227
260
"""add command prints the names of added files."""
228
b = Branch('.', init=True)
261
b = Branch.initialize('.')
229
262
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
264
from cStringIO import StringIO
243
276
'added top.txt',],
279
def test_unknown_command(self):
280
"""Handling of unknown command."""
281
out, err = self.run_bzr_captured(['fluffy-badger'],
283
self.assertEquals(out, '')
284
err.index('unknown command')
247
288
class OldTests(ExternalBase):
248
289
"""old tests moved from ./testbzr."""
264
self.assertEquals(backtick('bzr root').rstrip(),
304
self.assertEquals(capture('root').rstrip(),
265
305
os.path.join(self.test_dir, 'branch1'))
267
307
progress("status of new file")
270
310
f.write('hello world!\n')
273
out = backtick("bzr unknowns")
274
self.assertEquals(out, 'test.txt\n')
313
self.assertEquals(capture('unknowns'), 'test.txt\n')
276
out = backtick("bzr status")
315
out = capture("status")
277
316
assert out == 'unknown:\n test.txt\n'
279
out = backtick("bzr status --all")
318
out = capture("status --all")
280
319
assert out == "unknown:\n test.txt\n"
282
out = backtick("bzr status test.txt --all")
321
out = capture("status test.txt --all")
283
322
assert out == "unknown:\n test.txt\n"
285
324
f = file('test2.txt', 'wt')
286
325
f.write('goodbye cruel world...\n')
289
out = backtick("bzr status test.txt")
328
out = capture("status test.txt")
290
329
assert out == "unknown:\n test.txt\n"
292
out = backtick("bzr status")
331
out = capture("status")
293
332
assert out == ("unknown:\n"
297
336
os.unlink('test2.txt')
299
338
progress("command aliases")
300
out = backtick("bzr st --all")
339
out = capture("st --all")
301
340
assert out == ("unknown:\n"
304
out = backtick("bzr stat")
343
out = capture("stat")
305
344
assert out == ("unknown:\n"
320
359
progress("adding a file")
322
361
runbzr("add test.txt")
323
assert backtick("bzr unknowns") == ''
324
assert backtick("bzr status --all") == ("added:\n"
362
assert capture("unknowns") == ''
363
assert capture("status --all") == ("added:\n"
327
366
progress("rename newly-added file")
329
368
assert os.path.exists("hello.txt")
330
369
assert not os.path.exists("test.txt")
332
assert backtick("bzr revno") == '0\n'
371
assert capture("revno") == '0\n'
334
373
progress("add first revision")
335
374
runbzr(['commit', '-m', 'add first revision'])
343
382
runbzr("add sub1")
344
383
runbzr("rename sub1 sub2")
345
384
runbzr("move hello.txt sub2")
346
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
385
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
348
387
assert exists("sub2")
349
388
assert exists("sub2/hello.txt")
364
403
runbzr(['commit', '-m', 'rename nested subdirectories'])
366
405
chdir('sub1/sub2')
367
self.assertEquals(backtick('bzr root')[:-1],
406
self.assertEquals(capture('root')[:-1],
368
407
os.path.join(self.test_dir, 'branch1'))
369
408
runbzr('move ../hello.txt .')
370
409
assert exists('./hello.txt')
371
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
372
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
410
self.assertEquals(capture('relpath hello.txt'),
411
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
412
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
373
413
runbzr(['commit', '-m', 'move to parent directory'])
375
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
415
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
377
417
runbzr('move sub2/hello.txt .')
378
418
assert exists('hello.txt')
388
428
runbzr('commit -F msg.tmp')
390
assert backtick('bzr revno') == '5\n'
430
assert capture('revno') == '5\n'
391
431
runbzr('export -r 5 export-5.tmp')
392
432
runbzr('export export.tmp')
396
436
runbzr('log -v --forward')
397
437
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
438
log_out = capture('log -m commit')
399
439
assert "this is my new commit" in log_out
400
440
assert "rename nested" not in log_out
401
441
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
442
assert 'revision-id' in capture('log --show-ids -m commit')
405
445
progress("file with spaces in name")