15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# Mr. Smoketoomuch: I'm sorry?
19
# Mr. Bounder: You'd better cut down a little then.
20
# Mr. Smoketoomuch: Oh, I see! Smoke too much so I'd better cut down a little
23
19
"""Black-box tests for bzr.
25
21
These check that it behaves properly when it's invoked through the regular
26
command-line interface. This doesn't actually run a new interpreter but
27
rather starts again from the run_bzr function.
22
command-line interface.
24
This always reinvokes bzr through a new Python interpreter, which is a
25
bit inefficient but arguably tests in a way more representative of how
26
it's normally invoked.
31
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
# Note: Please don't add new tests here, it's too big and bulky. Instead add
33
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
# UI command/aspect that is being tested.
37
from cStringIO import StringIO
43
from bzrlib.branch import Branch
44
from bzrlib.errors import BzrCommandError
45
from bzrlib.osutils import has_symlinks, pathjoin
46
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
47
from bzrlib.tests.blackbox import ExternalBase
49
class TestCommands(ExternalBase):
51
def test_help_commands(self):
31
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
35
class ExternalBase(InTempDir):
36
def runbzr(self, args, retcode=0):
39
from subprocess import call
40
except ImportError, e:
44
if isinstance(args, basestring):
47
return self.runcmd(['python', self.BZRPATH,] + args,
52
class MvCommand(BzrTestBase):
54
"""Test two modes of operation for mv"""
55
b = Branch('.', init=True)
56
self.build_tree(['a', 'c', 'subdir/'])
57
self.run_bzr('mv', 'a', 'b')
58
self.run_bzr('mv', 'b', 'subdir')
59
self.run_bzr('mv', 'subdir/b', 'a')
60
self.run_bzr('mv', 'a', 'b', 'subdir')
61
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
65
class TestVersion(BzrTestBase):
66
"""Check output from version command and master option is reasonable"""
68
# output is intentionally passed through to stdout so that we
69
# can see the version being tested
70
from cStringIO import StringIO
73
sys.stdout = tmp_out = StringIO()
75
self.run_bzr('version')
79
output = tmp_out.getvalue()
80
self.log('bzr version output:')
83
self.assert_(output.startswith('bzr (bazaar-ng) '))
84
self.assertNotEqual(output.index('Canonical'), -1)
86
# make sure --version is consistent
88
sys.stdout = tmp_out = StringIO()
90
self.run_bzr('--version')
94
self.log('bzr --version output:')
95
self.log(tmp_out.getvalue())
97
self.assertEquals(output, tmp_out.getvalue())
103
class HelpCommands(ExternalBase):
52
105
self.runbzr('--help')
53
106
self.runbzr('help')
54
107
self.runbzr('help commands')
55
108
self.runbzr('help help')
56
109
self.runbzr('commit -h')
58
def test_init_branch(self):
112
class InitBranch(ExternalBase):
59
115
self.runbzr(['init'])
61
# Can it handle subdirectories as well?
62
self.runbzr('init subdir1')
63
self.assert_(os.path.exists('subdir1'))
64
self.assert_(os.path.exists('subdir1/.bzr'))
66
self.runbzr('init subdir2/nothere', retcode=3)
69
self.runbzr('init subdir2')
70
self.runbzr('init subdir2', retcode=3)
72
self.runbzr('init subdir2/subsubdir1')
73
self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
75
def test_whoami(self):
119
class UserIdentity(ExternalBase):
76
121
# this should always identify something, if only "john@localhost"
77
122
self.runbzr("whoami")
78
123
self.runbzr("whoami --email")
80
self.assertEquals(self.runbzr("whoami --email",
81
backtick=True).count('@'), 1)
83
def test_whoami_branch(self):
84
"""branch specific user identity works."""
86
f = file('.bzr/email', 'wt')
87
f.write('Branch Identity <branch@identi.ty>')
89
bzr_email = os.environ.get('BZREMAIL')
90
if bzr_email is not None:
91
del os.environ['BZREMAIL']
92
whoami = self.runbzr("whoami",backtick=True)
93
whoami_email = self.runbzr("whoami --email",backtick=True)
94
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
95
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
96
# Verify that the environment variable overrides the value
98
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
99
whoami = self.runbzr("whoami",backtick=True)
100
whoami_email = self.runbzr("whoami --email",backtick=True)
101
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
102
self.assertTrue(whoami_email.startswith('other@environ.ment'))
103
if bzr_email is not None:
104
os.environ['BZREMAIL'] = bzr_email
106
def test_nick_command(self):
107
"""bzr nick for viewing, setting nicknames"""
111
nick = self.runbzr("nick",backtick=True)
112
self.assertEqual(nick, 'me.dev\n')
113
nick = self.runbzr("nick moo")
114
nick = self.runbzr("nick",backtick=True)
115
self.assertEqual(nick, 'moo\n')
118
def test_invalid_commands(self):
119
self.runbzr("pants", retcode=3)
120
self.runbzr("--pants off", retcode=3)
121
self.runbzr("diff --message foo", retcode=3)
123
def test_empty_commit(self):
124
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
128
class InvalidCommands(ExternalBase):
130
self.runbzr("pants", retcode=1)
131
self.runbzr("--pants off", retcode=1)
132
self.runbzr("diff --message foo", retcode=1)
136
class EmptyCommit(ExternalBase):
124
138
self.runbzr("init")
125
139
self.build_tree(['hello.txt'])
126
self.runbzr("commit -m empty", retcode=3)
140
self.runbzr("commit -m empty", retcode=1)
127
141
self.runbzr("add hello.txt")
128
self.runbzr("commit -m added")
130
def test_empty_commit_message(self):
132
file('foo.c', 'wt').write('int main() {}')
133
self.runbzr(['add', 'foo.c'])
134
self.runbzr(["commit", "-m", ""] , retcode=3)
136
def test_remove_deleted(self):
138
self.build_tree(['a'])
139
self.runbzr(['add', 'a'])
140
self.runbzr(['commit', '-m', 'added a'])
142
self.runbzr(['remove', 'a'])
144
def test_other_branch_commit(self):
145
# this branch is to ensure consistent behaviour, whether we're run
146
# inside a branch, or not.
147
os.mkdir('empty_branch')
148
os.chdir('empty_branch')
153
file('foo.c', 'wt').write('int main() {}')
154
file('bar.c', 'wt').write('int main() {}')
156
self.runbzr(['add', 'branch/foo.c'])
157
self.runbzr(['add', 'branch'])
158
# can't commit files in different trees; sane error
159
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
160
self.runbzr('commit -m newstuff branch/foo.c')
161
self.runbzr('commit -m newstuff branch')
162
self.runbzr('commit -m newstuff branch', retcode=3)
164
def test_ignore_patterns(self):
142
self.runbzr("commit -m added")
146
class IgnorePatterns(ExternalBase):
165
148
from bzrlib.branch import Branch
166
Branch.initialize('.')
167
self.assertEquals(self.capture('unknowns'), '')
150
b = Branch('.', init=True)
151
self.assertEquals(list(b.unknowns()), [])
169
153
file('foo.tmp', 'wt').write('tmp files are ignored')
170
self.assertEquals(self.capture('unknowns'), '')
154
self.assertEquals(list(b.unknowns()), [])
155
assert self.backtick('bzr unknowns') == ''
172
157
file('foo.c', 'wt').write('int main() {}')
173
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
158
self.assertEquals(list(b.unknowns()), ['foo.c'])
159
assert self.backtick('bzr unknowns') == 'foo.c\n'
175
161
self.runbzr(['add', 'foo.c'])
176
self.assertEquals(self.capture('unknowns'), '')
162
assert self.backtick('bzr unknowns') == ''
178
164
# 'ignore' works when creating the .bzignore file
179
165
file('foo.blah', 'wt').write('blah')
180
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
166
self.assertEquals(list(b.unknowns()), ['foo.blah'])
181
167
self.runbzr('ignore *.blah')
182
self.assertEquals(self.capture('unknowns'), '')
183
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
168
self.assertEquals(list(b.unknowns()), [])
169
assert file('.bzrignore', 'rb').read() == '*.blah\n'
185
171
# 'ignore' works when then .bzrignore file already exists
186
172
file('garh', 'wt').write('garh')
187
self.assertEquals(self.capture('unknowns'), 'garh\n')
173
self.assertEquals(list(b.unknowns()), ['garh'])
174
assert self.backtick('bzr unknowns') == 'garh\n'
188
175
self.runbzr('ignore garh')
189
self.assertEquals(self.capture('unknowns'), '')
190
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
192
def test_revert(self):
195
file('hello', 'wt').write('foo')
196
self.runbzr('add hello')
197
self.runbzr('commit -m setup hello')
199
file('goodbye', 'wt').write('baz')
200
self.runbzr('add goodbye')
201
self.runbzr('commit -m setup goodbye')
203
file('hello', 'wt').write('bar')
204
file('goodbye', 'wt').write('qux')
205
self.runbzr('revert hello')
206
self.check_file_contents('hello', 'foo')
207
self.check_file_contents('goodbye', 'qux')
208
self.runbzr('revert')
209
self.check_file_contents('goodbye', 'baz')
211
os.mkdir('revertdir')
212
self.runbzr('add revertdir')
213
self.runbzr('commit -m f')
214
os.rmdir('revertdir')
215
self.runbzr('revert')
218
os.symlink('/unlikely/to/exist', 'symlink')
219
self.runbzr('add symlink')
220
self.runbzr('commit -m f')
222
self.runbzr('revert')
223
self.failUnlessExists('symlink')
225
os.symlink('a-different-path', 'symlink')
226
self.runbzr('revert')
227
self.assertEqual('/unlikely/to/exist',
228
os.readlink('symlink'))
230
self.log("skipping revert symlink tests")
232
file('hello', 'wt').write('xyz')
233
self.runbzr('commit -m xyz hello')
234
self.runbzr('revert -r 1 hello')
235
self.check_file_contents('hello', 'foo')
236
self.runbzr('revert hello')
237
self.check_file_contents('hello', 'xyz')
238
os.chdir('revertdir')
239
self.runbzr('revert')
242
def test_status(self):
244
self.build_tree(['hello.txt'])
245
result = self.runbzr("status")
246
self.assert_("unknown:\n hello.txt\n" in result, result)
247
self.runbzr("add hello.txt")
248
result = self.runbzr("status")
249
self.assert_("added:\n hello.txt\n" in result, result)
250
self.runbzr("commit -m added")
251
result = self.runbzr("status -r 0..1")
252
self.assert_("added:\n hello.txt\n" in result, result)
253
self.build_tree(['world.txt'])
254
result = self.runbzr("status -r 0")
255
self.assert_("added:\n hello.txt\n" \
256
"unknown:\n world.txt\n" in result, result)
258
def test_mv_modes(self):
259
"""Test two modes of operation for mv"""
260
from bzrlib.branch import Branch
261
b = Branch.initialize('.')
262
self.build_tree(['a', 'c', 'subdir/'])
263
self.run_bzr_captured(['add', self.test_dir])
264
self.run_bzr_captured(['mv', 'a', 'b'])
265
self.run_bzr_captured(['mv', 'b', 'subdir'])
266
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
267
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
268
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
270
def test_main_version(self):
271
"""Check output from version command and master option is reasonable"""
272
# output is intentionally passed through to stdout so that we
273
# can see the version being tested
274
output = self.runbzr('version', backtick=1)
275
self.log('bzr version output:')
277
self.assert_(output.startswith('bzr (bazaar-ng) '))
278
self.assertNotEqual(output.index('Canonical'), -1)
279
# make sure --version is consistent
280
tmp_output = self.runbzr('--version', backtick=1)
281
self.log('bzr --version output:')
283
self.assertEquals(output, tmp_output)
285
def example_branch(test):
287
file('hello', 'wt').write('foo')
288
test.runbzr('add hello')
289
test.runbzr('commit -m setup hello')
290
file('goodbye', 'wt').write('baz')
291
test.runbzr('add goodbye')
292
test.runbzr('commit -m setup goodbye')
294
def test_export(self):
297
self.example_branch()
298
self.runbzr('export ../latest')
299
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
300
self.runbzr('export ../first -r 1')
301
self.assert_(not os.path.exists('../first/goodbye'))
302
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
303
self.runbzr('export ../first.gz -r 1')
304
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
305
self.runbzr('export ../first.bz2 -r 1')
306
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
308
from tarfile import TarFile
309
self.runbzr('export ../first.tar -r 1')
310
self.assert_(os.path.isfile('../first.tar'))
311
tf = TarFile('../first.tar')
312
self.assert_('first/hello' in tf.getnames(), tf.getnames())
313
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
314
self.runbzr('export ../first.tar.gz -r 1')
315
self.assert_(os.path.isfile('../first.tar.gz'))
316
self.runbzr('export ../first.tbz2 -r 1')
317
self.assert_(os.path.isfile('../first.tbz2'))
318
self.runbzr('export ../first.tar.bz2 -r 1')
319
self.assert_(os.path.isfile('../first.tar.bz2'))
320
self.runbzr('export ../first.tar.tbz2 -r 1')
321
self.assert_(os.path.isfile('../first.tar.tbz2'))
323
from bz2 import BZ2File
324
tf = TarFile('../first.tar.tbz2',
325
fileobj=BZ2File('../first.tar.tbz2', 'r'))
326
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
327
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
328
self.runbzr('export ../first2.tar -r 1 --root pizza')
329
tf = TarFile('../first2.tar')
330
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
332
from zipfile import ZipFile
333
self.runbzr('export ../first.zip -r 1')
334
self.failUnlessExists('../first.zip')
335
zf = ZipFile('../first.zip')
336
self.assert_('first/hello' in zf.namelist(), zf.namelist())
337
self.assertEqual(zf.read('first/hello'), 'foo')
339
self.runbzr('export ../first2.zip -r 1 --root pizza')
340
zf = ZipFile('../first2.zip')
341
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
343
self.runbzr('export ../first-zip --format=zip -r 1')
344
zf = ZipFile('../first-zip')
345
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
348
self.example_branch()
349
file('hello', 'wt').write('hello world!')
350
self.runbzr('commit -m fixing hello')
351
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
352
self.assert_('\n+hello world!' in output)
353
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
354
self.assert_('\n+baz' in output)
355
file('moo', 'wb').write('moo')
356
self.runbzr('add moo')
360
def test_diff_branches(self):
361
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
362
branch = Branch.initialize('branch1')
363
branch.working_tree().add(['file'])
364
branch.working_tree().commit('add file')
365
branch.clone('branch2')
366
print >> open('branch2/file', 'wb'), 'new content'
367
branch2 = Branch.open('branch2')
368
branch2.working_tree().commit('update file')
369
# should open branch1 and diff against branch2,
370
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
373
self.assertEquals(("=== modified file 'file'\n"
378
"+contents of branch1/file\n"
380
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
382
self.assertEqualDiff(("=== modified file 'file'\n"
387
"+contents of branch1/file\n"
391
def test_branch(self):
392
"""Branch from one branch to another."""
395
self.example_branch()
397
self.runbzr('branch a b')
398
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
399
self.runbzr('branch a c -r 1')
401
self.runbzr('commit -m foo --unchanged')
403
# naughty - abstraction violations RBC 20050928
404
print "test_branch used to delete the stores, how is this meant to work ?"
405
#shutil.rmtree('a/.bzr/revision-store')
406
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
407
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
408
self.runbzr('branch a d --basis b')
410
def test_merge(self):
411
from bzrlib.branch import Branch
415
self.example_branch()
417
self.runbzr('branch a b')
419
file('goodbye', 'wt').write('quux')
420
self.runbzr(['commit', '-m', "more u's are always good"])
423
file('hello', 'wt').write('quuux')
424
# We can't merge when there are in-tree changes
425
self.runbzr('merge ../b', retcode=3)
426
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
427
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
429
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
430
self.runbzr('revert --no-backup')
431
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
432
self.runbzr('revert --no-backup')
433
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
434
self.runbzr('revert --no-backup')
435
self.runbzr('merge ../b -r last:1')
436
self.check_file_contents('goodbye', 'quux')
437
# Merging a branch pulls its revision into the tree
439
b = Branch.open('../b')
440
a.repository.get_revision_xml(b.last_revision())
441
self.log('pending merges: %s', a.working_tree().pending_merges())
442
self.assertEquals(a.working_tree().pending_merges(),
444
self.runbzr('commit -m merged')
445
self.runbzr('merge ../b -r last:1')
446
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
448
def test_merge_with_missing_file(self):
449
"""Merge handles missing file conflicts"""
453
print >> file('sub/a.txt', 'wb'), "hello"
454
print >> file('b.txt', 'wb'), "hello"
455
print >> file('sub/c.txt', 'wb'), "hello"
458
self.runbzr(('commit', '-m', 'added a'))
459
self.runbzr('branch . ../b')
460
print >> file('sub/a.txt', 'ab'), "there"
461
print >> file('b.txt', 'ab'), "there"
462
print >> file('sub/c.txt', 'ab'), "there"
463
self.runbzr(('commit', '-m', 'Added there'))
464
os.unlink('sub/a.txt')
465
os.unlink('sub/c.txt')
468
self.runbzr(('commit', '-m', 'Removed a.txt'))
470
print >> file('sub/a.txt', 'ab'), "something"
471
print >> file('b.txt', 'ab'), "something"
472
print >> file('sub/c.txt', 'ab'), "something"
473
self.runbzr(('commit', '-m', 'Modified a.txt'))
474
self.runbzr('merge ../a/', retcode=1)
475
self.assert_(os.path.exists('sub/a.txt.THIS'))
476
self.assert_(os.path.exists('sub/a.txt.BASE'))
478
self.runbzr('merge ../b/', retcode=1)
479
self.assert_(os.path.exists('sub/a.txt.OTHER'))
480
self.assert_(os.path.exists('sub/a.txt.BASE'))
482
def test_inventory(self):
484
def output_equals(value, *args):
485
out = self.runbzr(['inventory'] + list(args), backtick=True)
486
self.assertEquals(out, value)
489
open('a', 'wb').write('hello\n')
495
output_equals('a\n', '--kind', 'file')
496
output_equals('b\n', '--kind', 'directory')
499
"""Test the abilities of 'bzr ls'"""
501
def bzrout(*args, **kwargs):
502
kwargs['backtick'] = True
503
return self.runbzr(*args, **kwargs)
505
def ls_equals(value, *args):
506
out = self.runbzr(['ls'] + list(args), backtick=True)
507
self.assertEquals(out, value)
510
open('a', 'wb').write('hello\n')
513
bzr('ls --verbose --null', retcode=3)
516
ls_equals('? a\n', '--verbose')
517
ls_equals('a\n', '--unknown')
518
ls_equals('', '--ignored')
519
ls_equals('', '--versioned')
520
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
521
ls_equals('', '--ignored', '--versioned')
522
ls_equals('a\0', '--null')
525
ls_equals('V a\n', '--verbose')
532
open('subdir/b', 'wb').write('b\n')
538
bzr('commit -m subdir')
546
, '--verbose', '--non-recursive')
548
# Check what happens in a sub-directory
560
, '--from-root', '--null')
563
, '--from-root', '--non-recursive')
567
# Check what happens when we supply a specific revision
568
ls_equals('a\n', '--revision', '1')
570
, '--verbose', '--revision', '1')
573
ls_equals('', '--revision', '1')
575
# Now try to do ignored files.
577
open('blah.py', 'wb').write('unknown\n')
578
open('blah.pyo', 'wb').write('ignored\n')
590
ls_equals('blah.pyo\n'
592
ls_equals('blah.py\n'
601
file("myfile", "wb").write("My contents\n")
603
self.runbzr('commit -m myfile')
604
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
606
def test_pull_verbose(self):
607
"""Pull changes from one branch to another and watch the output."""
613
self.example_branch()
618
open('b', 'wb').write('else\n')
620
bzr(['commit', '-m', 'added b'])
623
out = bzr('pull --verbose ../b', backtick=True)
624
self.failIfEqual(out.find('Added Revisions:'), -1)
625
self.failIfEqual(out.find('message:\n added b'), -1)
626
self.failIfEqual(out.find('added b'), -1)
628
# Check that --overwrite --verbose prints out the removed entries
629
bzr('commit -m foo --unchanged')
631
bzr('commit -m baz --unchanged')
632
bzr('pull ../a', retcode=3)
633
out = bzr('pull --overwrite --verbose ../a', backtick=1)
635
remove_loc = out.find('Removed Revisions:')
636
self.failIfEqual(remove_loc, -1)
637
added_loc = out.find('Added Revisions:')
638
self.failIfEqual(added_loc, -1)
640
removed_message = out.find('message:\n baz')
641
self.failIfEqual(removed_message, -1)
642
self.failUnless(remove_loc < removed_message < added_loc)
644
added_message = out.find('message:\n foo')
645
self.failIfEqual(added_message, -1)
646
self.failUnless(added_loc < added_message)
648
def test_locations(self):
649
"""Using and remembering different locations"""
653
self.runbzr('commit -m unchanged --unchanged')
654
self.runbzr('pull', retcode=3)
655
self.runbzr('merge', retcode=3)
656
self.runbzr('branch . ../b')
659
self.runbzr('branch . ../c')
660
self.runbzr('pull ../c')
663
self.runbzr('pull ../b')
665
self.runbzr('pull ../c')
666
self.runbzr('branch ../c ../d')
667
shutil.rmtree('../c')
672
self.runbzr('pull', retcode=3)
673
self.runbzr('pull ../a --remember')
676
def test_add_reports(self):
677
"""add command prints the names of added files."""
678
b = Branch.initialize('.')
679
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
680
out = self.run_bzr_captured(['add'], retcode=0)[0]
681
# the ordering is not defined at the moment
682
results = sorted(out.rstrip('\n').split('\n'))
683
self.assertEquals(['If you wish to add some of these files, please'\
684
' add them by name.',
688
'ignored 1 file(s) matching "CVS"'],
690
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
691
results = sorted(out.rstrip('\n').split('\n'))
692
self.assertEquals(['If you wish to add some of these files, please'\
693
' add them by name.',
694
'ignored CVS matching "CVS"'],
697
def test_add_quiet_is(self):
698
"""add -q does not print the names of added files."""
699
b = Branch.initialize('.')
700
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
701
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
702
# the ordering is not defined at the moment
703
results = sorted(out.rstrip('\n').split('\n'))
704
self.assertEquals([''], results)
706
def test_add_in_unversioned(self):
707
"""Try to add a file in an unversioned directory.
709
"bzr add" should add the parent(s) as necessary.
711
from bzrlib.branch import Branch
712
Branch.initialize('.')
713
self.build_tree(['inertiatic/', 'inertiatic/esp'])
714
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
715
self.run_bzr('add', 'inertiatic/esp')
716
self.assertEquals(self.capture('unknowns'), '')
718
# Multiple unversioned parents
719
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
720
self.assertEquals(self.capture('unknowns'), 'veil\n')
721
self.run_bzr('add', 'veil/cerpin/taxt')
722
self.assertEquals(self.capture('unknowns'), '')
724
# Check whacky paths work
725
self.build_tree(['cicatriz/', 'cicatriz/esp'])
726
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
727
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
728
self.assertEquals(self.capture('unknowns'), '')
730
def test_add_in_versioned(self):
731
"""Try to add a file in a versioned directory.
733
"bzr add" should do this happily.
735
from bzrlib.branch import Branch
736
Branch.initialize('.')
737
self.build_tree(['inertiatic/', 'inertiatic/esp'])
738
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
739
self.run_bzr('add', '--no-recurse', 'inertiatic')
740
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
741
self.run_bzr('add', 'inertiatic/esp')
742
self.assertEquals(self.capture('unknowns'), '')
744
def test_subdir_add(self):
745
"""Add in subdirectory should add only things from there down"""
746
from bzrlib.branch import Branch
748
eq = self.assertEqual
752
b = Branch.initialize('.')
754
self.build_tree(['src/', 'README'])
756
eq(sorted(t.unknowns()),
759
self.run_bzr('add', 'src')
761
self.build_tree(['src/foo.c'])
766
self.assertEquals(self.capture('unknowns'), 'README\n')
767
eq(len(t.read_working_inventory()), 3)
771
self.assertEquals(self.capture('unknowns'), '')
772
self.run_bzr('check')
774
def test_unknown_command(self):
775
"""Handling of unknown command."""
776
out, err = self.run_bzr_captured(['fluffy-badger'],
778
self.assertEquals(out, '')
779
err.index('unknown command')
781
def create_conflicts(self):
782
"""Create a conflicted tree"""
785
file('hello', 'wb').write("hi world")
786
file('answer', 'wb').write("42")
789
self.runbzr('commit -m base')
790
self.runbzr('branch . ../other')
791
self.runbzr('branch . ../this')
793
file('hello', 'wb').write("Hello.")
794
file('answer', 'wb').write("Is anyone there?")
795
self.runbzr('commit -m other')
797
file('hello', 'wb').write("Hello, world")
798
self.runbzr('mv answer question')
799
file('question', 'wb').write("What do you get when you multiply six"
801
self.runbzr('commit -m this')
803
def test_remerge(self):
804
"""Remerge command works as expected"""
805
self.create_conflicts()
806
self.runbzr('merge ../other --show-base', retcode=1)
807
conflict_text = file('hello').read()
808
assert '|||||||' in conflict_text
809
assert 'hi world' in conflict_text
810
self.runbzr('remerge', retcode=1)
811
conflict_text = file('hello').read()
812
assert '|||||||' not in conflict_text
813
assert 'hi world' not in conflict_text
814
os.unlink('hello.OTHER')
815
self.runbzr('remerge hello --merge-type weave', retcode=1)
816
assert os.path.exists('hello.OTHER')
817
file_id = self.runbzr('file-id hello')
818
file_id = self.runbzr('file-id hello.THIS', retcode=3)
819
self.runbzr('remerge --merge-type weave', retcode=1)
820
assert os.path.exists('hello.OTHER')
821
assert not os.path.exists('hello.BASE')
822
assert '|||||||' not in conflict_text
823
assert 'hi world' not in conflict_text
824
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
825
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
826
self.runbzr('remerge . --show-base --reprocess', retcode=3)
827
self.runbzr('remerge hello --show-base', retcode=1)
828
self.runbzr('remerge hello --reprocess', retcode=1)
829
self.runbzr('resolve --all')
830
self.runbzr('commit -m done',)
831
self.runbzr('remerge', retcode=3)
833
def test_status(self):
837
self.runbzr('commit --unchanged --message f')
838
self.runbzr('branch . ../branch2')
839
self.runbzr('branch . ../branch3')
840
self.runbzr('commit --unchanged --message peter')
841
os.chdir('../branch2')
842
self.runbzr('merge ../branch1')
843
self.runbzr('commit --unchanged --message pumpkin')
844
os.chdir('../branch3')
845
self.runbzr('merge ../branch2')
846
message = self.capture('status')
849
def test_conflicts(self):
850
"""Handling of merge conflicts"""
851
self.create_conflicts()
852
self.runbzr('merge ../other --show-base', retcode=1)
853
conflict_text = file('hello').read()
854
self.assert_('<<<<<<<' in conflict_text)
855
self.assert_('>>>>>>>' in conflict_text)
856
self.assert_('=======' in conflict_text)
857
self.assert_('|||||||' in conflict_text)
858
self.assert_('hi world' in conflict_text)
859
self.runbzr('revert')
860
self.runbzr('resolve --all')
861
self.runbzr('merge ../other', retcode=1)
862
conflict_text = file('hello').read()
863
self.assert_('|||||||' not in conflict_text)
864
self.assert_('hi world' not in conflict_text)
865
result = self.runbzr('conflicts', backtick=1)
866
self.assertEquals(result, "hello\nquestion\n")
867
result = self.runbzr('status', backtick=1)
868
self.assert_("conflicts:\n hello\n question\n" in result, result)
869
self.runbzr('resolve hello')
870
result = self.runbzr('conflicts', backtick=1)
871
self.assertEquals(result, "question\n")
872
self.runbzr('commit -m conflicts', retcode=3)
873
self.runbzr('resolve --all')
874
result = self.runbzr('conflicts', backtick=1)
875
self.runbzr('commit -m conflicts')
876
self.assertEquals(result, "")
878
def test_resign(self):
879
"""Test re signing of data."""
881
oldstrategy = bzrlib.gpg.GPGStrategy
882
branch = Branch.initialize('.')
883
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
885
# monkey patch gpg signing mechanism
886
from bzrlib.testament import Testament
887
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
888
self.runbzr('re-sign -r revid:A')
889
self.assertEqual(Testament.from_revision(branch.repository,
890
'A').as_short_text(),
891
branch.repository.revision_store.get('A',
894
bzrlib.gpg.GPGStrategy = oldstrategy
896
def test_resign_range(self):
898
oldstrategy = bzrlib.gpg.GPGStrategy
899
branch = Branch.initialize('.')
900
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
901
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
902
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
904
# monkey patch gpg signing mechanism
905
from bzrlib.testament import Testament
906
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
907
self.runbzr('re-sign -r 1..')
909
Testament.from_revision(branch.repository,'A').as_short_text(),
910
branch.repository.revision_store.get('A', 'sig').read())
912
Testament.from_revision(branch.repository,'B').as_short_text(),
913
branch.repository.revision_store.get('B', 'sig').read())
914
self.assertEqual(Testament.from_revision(branch.repository,
915
'C').as_short_text(),
916
branch.repository.revision_store.get('C',
919
bzrlib.gpg.GPGStrategy = oldstrategy
922
# create a source branch
923
os.mkdir('my-branch')
924
os.chdir('my-branch')
925
self.example_branch()
927
# with no push target, fail
928
self.runbzr('push', retcode=3)
929
# with an explicit target work
930
self.runbzr('push ../output-branch')
931
# with an implicit target work
934
self.runbzr('missing ../output-branch')
935
# advance this branch
936
self.runbzr('commit --unchanged -m unchanged')
938
os.chdir('../output-branch')
939
# There is no longer a difference as long as we have
940
# access to the working tree
943
# But we should be missing a revision
944
self.runbzr('missing ../my-branch', retcode=1)
946
# diverge the branches
947
self.runbzr('commit --unchanged -m unchanged')
948
os.chdir('../my-branch')
950
self.runbzr('push', retcode=3)
951
# and there are difference
952
self.runbzr('missing ../output-branch', retcode=1)
953
self.runbzr('missing --verbose ../output-branch', retcode=1)
954
# but we can force a push
955
self.runbzr('push --overwrite')
957
self.runbzr('missing ../output-branch')
959
# pushing to a new dir with no parent should fail
960
self.runbzr('push ../missing/new-branch', retcode=3)
961
# unless we provide --create-prefix
962
self.runbzr('push --create-prefix ../missing/new-branch')
964
self.runbzr('missing ../missing/new-branch')
966
def test_external_command(self):
967
"""test that external commands can be run by setting the path"""
968
cmd_name = 'test-command'
969
output = 'Hello from test-command'
970
if sys.platform == 'win32':
976
oldpath = os.environ.get('BZRPATH', None)
981
if os.environ.has_key('BZRPATH'):
982
del os.environ['BZRPATH']
984
f = file(cmd_name, 'wb')
985
if sys.platform == 'win32':
986
f.write('@echo off\n')
988
f.write('#!/bin/sh\n')
989
f.write('echo Hello from test-command')
991
os.chmod(cmd_name, 0755)
993
# It should not find the command in the local
994
# directory by default, since it is not in my path
995
bzr(cmd_name, retcode=3)
997
# Now put it into my path
998
os.environ['BZRPATH'] = '.'
1001
# The test suite does not capture stdout for external commands
1002
# this is because you have to have a real file object
1003
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
1004
# (just replacing sys.stdout does not change a spawned objects stdout)
1005
#self.assertEquals(bzr(cmd_name), output)
1007
# Make sure empty path elements are ignored
1008
os.environ['BZRPATH'] = os.pathsep
1010
bzr(cmd_name, retcode=3)
1014
os.environ['BZRPATH'] = oldpath
1017
def listdir_sorted(dir):
176
self.assertEquals(list(b.unknowns()), [])
177
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
1023
182
class OldTests(ExternalBase):
1024
"""old tests moved from ./testbzr."""
183
# old tests moved from ./testbzr
1027
185
from os import chdir, mkdir
1028
186
from os.path import exists
1030
189
runbzr = self.runbzr
1031
capture = self.capture
190
backtick = self.backtick
1032
191
progress = self.log
1034
193
progress("basic branch creation")