~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

Update news and readme

- better explanation of dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
 
26
26
 
27
 
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
28
 
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
29
 
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
30
 
# UI command/aspect that is being tested.
31
 
 
32
 
 
33
27
from cStringIO import StringIO
34
28
import os
35
29
import re
40
34
from bzrlib.clone import copy_branch
41
35
from bzrlib.errors import BzrCommandError
42
36
from bzrlib.osutils import has_symlinks
43
 
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
44
 
from bzrlib.tests.blackbox import ExternalBase
 
37
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
38
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
 
39
 
 
40
 
 
41
class ExternalBase(TestCaseInTempDir):
 
42
 
 
43
    def runbzr(self, args, retcode=0, backtick=False):
 
44
        if isinstance(args, basestring):
 
45
            args = args.split()
 
46
 
 
47
        if backtick:
 
48
            return self.run_bzr_captured(args, retcode=retcode)[0]
 
49
        else:
 
50
            return self.run_bzr_captured(args, retcode=retcode)
 
51
 
45
52
 
46
53
class TestCommands(ExternalBase):
47
54
 
55
62
    def test_init_branch(self):
56
63
        self.runbzr(['init'])
57
64
 
58
 
        # Can it handle subdirectories as well?
59
 
        self.runbzr('init subdir1')
60
 
        self.assert_(os.path.exists('subdir1'))
61
 
        self.assert_(os.path.exists('subdir1/.bzr'))
62
 
 
63
 
        self.runbzr('init subdir2/nothere', retcode=3)
64
 
        
65
 
        os.mkdir('subdir2')
66
 
        self.runbzr('init subdir2')
67
 
        self.runbzr('init subdir2', retcode=3)
68
 
 
69
 
        self.runbzr('init subdir2/subsubdir1')
70
 
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
71
 
 
72
65
    def test_whoami(self):
73
66
        # this should always identify something, if only "john@localhost"
74
67
        self.runbzr("whoami")
100
93
        if bzr_email is not None:
101
94
            os.environ['BZREMAIL'] = bzr_email
102
95
 
103
 
    def test_nick_command(self):
104
 
        """bzr nick for viewing, setting nicknames"""
105
 
        os.mkdir('me.dev')
106
 
        os.chdir('me.dev')
107
 
        self.runbzr('init')
108
 
        nick = self.runbzr("nick",backtick=True)
109
 
        self.assertEqual(nick, 'me.dev\n')
110
 
        nick = self.runbzr("nick moo")
111
 
        nick = self.runbzr("nick",backtick=True)
112
 
        self.assertEqual(nick, 'moo\n')
113
 
 
114
 
 
115
96
    def test_invalid_commands(self):
116
 
        self.runbzr("pants", retcode=3)
117
 
        self.runbzr("--pants off", retcode=3)
118
 
        self.runbzr("diff --message foo", retcode=3)
 
97
        self.runbzr("pants", retcode=1)
 
98
        self.runbzr("--pants off", retcode=1)
 
99
        self.runbzr("diff --message foo", retcode=1)
119
100
 
120
101
    def test_empty_commit(self):
121
102
        self.runbzr("init")
122
103
        self.build_tree(['hello.txt'])
123
 
        self.runbzr("commit -m empty", retcode=3)
 
104
        self.runbzr("commit -m empty", retcode=1)
124
105
        self.runbzr("add hello.txt")
125
 
        self.runbzr("commit -m added")       
 
106
        self.runbzr("commit -m added")
126
107
 
127
108
    def test_empty_commit_message(self):
128
109
        self.runbzr("init")
129
110
        file('foo.c', 'wt').write('int main() {}')
130
111
        self.runbzr(['add', 'foo.c'])
131
 
        self.runbzr(["commit", "-m", ""] , retcode=3) 
132
 
 
133
 
    def test_remove_deleted(self):
134
 
        self.runbzr("init")
135
 
        self.build_tree(['a'])
136
 
        self.runbzr(['add', 'a'])
137
 
        self.runbzr(['commit', '-m', 'added a'])
138
 
        os.unlink('a')
139
 
        self.runbzr(['remove', 'a'])
140
 
 
141
 
    def test_other_branch_commit(self):
142
 
        # this branch is to ensure consistent behaviour, whether we're run
143
 
        # inside a branch, or not.
144
 
        os.mkdir('empty_branch')
145
 
        os.chdir('empty_branch')
146
 
        self.runbzr('init')
147
 
        os.mkdir('branch')
148
 
        os.chdir('branch')
149
 
        self.runbzr('init')
150
 
        file('foo.c', 'wt').write('int main() {}')
151
 
        file('bar.c', 'wt').write('int main() {}')
152
 
        os.chdir('..')
153
 
        self.runbzr(['add', 'branch/foo.c'])
154
 
        self.runbzr(['add', 'branch'])
155
 
        # can't commit files in different trees; sane error
156
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
157
 
        self.runbzr('commit -m newstuff branch/foo.c')
158
 
        self.runbzr('commit -m newstuff branch')
159
 
        self.runbzr('commit -m newstuff branch', retcode=3)
 
112
        self.runbzr(["commit", "-m", ""] , retcode=1) 
160
113
 
161
114
    def test_ignore_patterns(self):
162
115
        from bzrlib.branch import Branch
163
 
        Branch.initialize('.')
164
 
        self.assertEquals(self.capture('unknowns'), '')
 
116
        
 
117
        b = Branch.initialize('.')
 
118
        self.assertEquals(list(b.unknowns()), [])
165
119
 
166
120
        file('foo.tmp', 'wt').write('tmp files are ignored')
167
 
        self.assertEquals(self.capture('unknowns'), '')
 
121
        self.assertEquals(list(b.unknowns()), [])
 
122
        assert self.capture('unknowns') == ''
168
123
 
169
124
        file('foo.c', 'wt').write('int main() {}')
170
 
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
 
125
        self.assertEquals(list(b.unknowns()), ['foo.c'])
 
126
        assert self.capture('unknowns') == 'foo.c\n'
171
127
 
172
128
        self.runbzr(['add', 'foo.c'])
173
 
        self.assertEquals(self.capture('unknowns'), '')
 
129
        assert self.capture('unknowns') == ''
174
130
 
175
131
        # 'ignore' works when creating the .bzignore file
176
132
        file('foo.blah', 'wt').write('blah')
177
 
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
 
133
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
178
134
        self.runbzr('ignore *.blah')
179
 
        self.assertEquals(self.capture('unknowns'), '')
180
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
 
135
        self.assertEquals(list(b.unknowns()), [])
 
136
        assert file('.bzrignore', 'rU').read() == '*.blah\n'
181
137
 
182
138
        # 'ignore' works when then .bzrignore file already exists
183
139
        file('garh', 'wt').write('garh')
184
 
        self.assertEquals(self.capture('unknowns'), 'garh\n')
 
140
        self.assertEquals(list(b.unknowns()), ['garh'])
 
141
        assert self.capture('unknowns') == 'garh\n'
185
142
        self.runbzr('ignore garh')
186
 
        self.assertEquals(self.capture('unknowns'), '')
187
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
 
143
        self.assertEquals(list(b.unknowns()), [])
 
144
        assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
188
145
 
189
146
    def test_revert(self):
190
147
        self.runbzr('init')
233
190
        self.runbzr('revert')
234
191
        os.chdir('..')
235
192
 
236
 
    def test_status(self):
237
 
        self.runbzr("init")
238
 
        self.build_tree(['hello.txt'])
239
 
        result = self.runbzr("status")
240
 
        self.assert_("unknown:\n  hello.txt\n" in result, result)
241
 
        self.runbzr("add hello.txt")
242
 
        result = self.runbzr("status")
243
 
        self.assert_("added:\n  hello.txt\n" in result, result)
244
 
        self.runbzr("commit -m added")
245
 
        result = self.runbzr("status -r 0..1")
246
 
        self.assert_("added:\n  hello.txt\n" in result, result)
247
 
        self.build_tree(['world.txt'])
248
 
        result = self.runbzr("status -r 0")
249
 
        self.assert_("added:\n  hello.txt\n" \
250
 
                     "unknown:\n  world.txt\n" in result, result)
251
193
 
252
194
    def test_mv_modes(self):
253
195
        """Test two modes of operation for mv"""
292
234
        self.runbzr('export ../latest')
293
235
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
294
236
        self.runbzr('export ../first -r 1')
295
 
        self.assert_(not os.path.exists('../first/goodbye'))
 
237
        assert not os.path.exists('../first/goodbye')
296
238
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
297
239
        self.runbzr('export ../first.gz -r 1')
298
240
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
299
241
        self.runbzr('export ../first.bz2 -r 1')
300
242
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
301
 
 
 
243
        self.runbzr('export ../first.tar -r 1')
 
244
        assert os.path.isfile('../first.tar')
302
245
        from tarfile import TarFile
303
 
        self.runbzr('export ../first.tar -r 1')
304
 
        self.assert_(os.path.isfile('../first.tar'))
305
246
        tf = TarFile('../first.tar')
306
 
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
 
247
        assert 'first/hello' in tf.getnames(), tf.getnames()
307
248
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
308
249
        self.runbzr('export ../first.tar.gz -r 1')
309
 
        self.assert_(os.path.isfile('../first.tar.gz'))
 
250
        assert os.path.isfile('../first.tar.gz')
310
251
        self.runbzr('export ../first.tbz2 -r 1')
311
 
        self.assert_(os.path.isfile('../first.tbz2'))
 
252
        assert os.path.isfile('../first.tbz2')
312
253
        self.runbzr('export ../first.tar.bz2 -r 1')
313
 
        self.assert_(os.path.isfile('../first.tar.bz2'))
 
254
        assert os.path.isfile('../first.tar.bz2')
314
255
        self.runbzr('export ../first.tar.tbz2 -r 1')
315
 
        self.assert_(os.path.isfile('../first.tar.tbz2'))
316
 
 
 
256
        assert os.path.isfile('../first.tar.tbz2')
317
257
        from bz2 import BZ2File
318
258
        tf = TarFile('../first.tar.tbz2', 
319
259
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
320
 
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
 
260
        assert 'first.tar/hello' in tf.getnames(), tf.getnames()
321
261
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
322
262
        self.runbzr('export ../first2.tar -r 1 --root pizza')
323
263
        tf = TarFile('../first2.tar')
324
 
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
325
 
 
326
 
        from zipfile import ZipFile
327
 
        self.runbzr('export ../first.zip -r 1')
328
 
        self.failUnlessExists('../first.zip')
329
 
        zf = ZipFile('../first.zip')
330
 
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
331
 
        self.assertEqual(zf.read('first/hello'), 'foo')
332
 
 
333
 
        self.runbzr('export ../first2.zip -r 1 --root pizza')
334
 
        zf = ZipFile('../first2.zip')
335
 
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
336
 
        
337
 
        self.runbzr('export ../first-zip --format=zip -r 1')
338
 
        zf = ZipFile('../first-zip')
339
 
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
 
264
        assert 'pizza/hello' in tf.getnames(), tf.getnames()
340
265
 
341
266
    def test_diff(self):
342
267
        self.example_branch()
343
268
        file('hello', 'wt').write('hello world!')
344
269
        self.runbzr('commit -m fixing hello')
345
 
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
 
270
        output = self.runbzr('diff -r 2..3', backtick=1)
346
271
        self.assert_('\n+hello world!' in output)
347
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
 
272
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
348
273
        self.assert_('\n+baz' in output)
349
 
        file('moo', 'wb').write('moo')
350
 
        self.runbzr('add moo')
351
 
        os.unlink('moo')
352
 
        self.runbzr('diff')
353
274
 
354
275
    def test_diff_branches(self):
355
 
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
 
276
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
356
277
        branch = Branch.initialize('branch1')
357
 
        branch.working_tree().add(['file'])
358
 
        branch.working_tree().commit('add file')
 
278
        branch.add(['file'])
 
279
        branch.commit('add file')
359
280
        copy_branch(branch, 'branch2')
360
 
        print >> open('branch2/file', 'wb'), 'new content'
 
281
        print >> open('branch2/file', 'w'), 'new content'
361
282
        branch2 = Branch.open('branch2')
362
 
        branch2.working_tree().commit('update file')
 
283
        branch2.commit('update file')
363
284
        # should open branch1 and diff against branch2, 
364
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
365
 
                                        'branch1'],
366
 
                                       retcode=1)
 
285
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
367
286
        self.assertEquals(("=== modified file 'file'\n"
368
 
                           "--- file\t\n"
369
 
                           "+++ file\t\n"
 
287
                           "--- file\n"
 
288
                           "+++ file\n"
370
289
                           "@@ -1,1 +1,1 @@\n"
371
290
                           "-new content\n"
372
291
                           "+contents of branch1/file\n"
373
292
                           "\n", ''), output)
374
 
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
375
 
                                       retcode=1)
376
 
        self.assertEqualDiff(("=== modified file 'file'\n"
377
 
                              "--- file\t\n"
378
 
                              "+++ file\t\n"
379
 
                              "@@ -1,1 +1,1 @@\n"
380
 
                              "-new content\n"
381
 
                              "+contents of branch1/file\n"
382
 
                              "\n", ''), output)
383
 
 
384
293
 
385
294
    def test_branch(self):
386
295
        """Branch from one branch to another."""
389
298
        self.example_branch()
390
299
        os.chdir('..')
391
300
        self.runbzr('branch a b')
392
 
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
393
301
        self.runbzr('branch a c -r 1')
394
302
        os.chdir('b')
395
303
        self.runbzr('commit -m foo --unchanged')
416
324
        os.chdir('../a')
417
325
        file('hello', 'wt').write('quuux')
418
326
        # We can't merge when there are in-tree changes
419
 
        self.runbzr('merge ../b', retcode=3)
 
327
        self.runbzr('merge ../b', retcode=1)
420
328
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
421
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
422
 
                    retcode=3)
423
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
424
 
        self.runbzr('revert --no-backup')
425
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
426
 
        self.runbzr('revert --no-backup')
427
 
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
428
 
        self.runbzr('revert --no-backup')
429
 
        self.runbzr('merge ../b -r last:1')
 
329
        self.runbzr('merge ../b')
430
330
        self.check_file_contents('goodbye', 'quux')
431
331
        # Merging a branch pulls its revision into the tree
432
332
        a = Branch.open('.')
433
333
        b = Branch.open('../b')
434
334
        a.get_revision_xml(b.last_revision())
435
 
        self.log('pending merges: %s', a.working_tree().pending_merges())
436
 
        self.assertEquals(a.working_tree().pending_merges(),
437
 
                          [b.last_revision()])
438
 
        self.runbzr('commit -m merged')
439
 
        self.runbzr('merge ../b -r last:1')
440
 
        self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
 
335
        self.log('pending merges: %s', a.pending_merges())
 
336
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
 
337
        #        % (a.pending_merges(), b.last_patch())
441
338
 
442
339
    def test_merge_with_missing_file(self):
443
340
        """Merge handles missing file conflicts"""
465
362
        print >> file('b.txt', 'ab'), "something"
466
363
        print >> file('sub/c.txt', 'ab'), "something"
467
364
        self.runbzr(('commit', '-m', 'Modified a.txt'))
468
 
        self.runbzr('merge ../a/', retcode=1)
469
 
        self.assert_(os.path.exists('sub/a.txt.THIS'))
470
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
 
365
        self.runbzr('merge ../a/')
 
366
        assert os.path.exists('sub/a.txt.THIS')
 
367
        assert os.path.exists('sub/a.txt.BASE')
471
368
        os.chdir('../a')
472
 
        self.runbzr('merge ../b/', retcode=1)
473
 
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
474
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
475
 
 
476
 
    def test_inventory(self):
477
 
        bzr = self.runbzr
478
 
        def output_equals(value, *args):
479
 
            out = self.runbzr(['inventory'] + list(args), backtick=True)
480
 
            self.assertEquals(out, value)
481
 
 
482
 
        bzr('init')
483
 
        open('a', 'wb').write('hello\n')
484
 
        os.mkdir('b')
485
 
 
486
 
        bzr('add a b')
487
 
        bzr('commit -m add')
488
 
 
489
 
        output_equals('a\n', '--kind', 'file')
490
 
        output_equals('b\n', '--kind', 'directory')        
491
 
 
492
 
    def test_ls(self):
493
 
        """Test the abilities of 'bzr ls'"""
494
 
        bzr = self.runbzr
495
 
        def bzrout(*args, **kwargs):
496
 
            kwargs['backtick'] = True
497
 
            return self.runbzr(*args, **kwargs)
498
 
 
499
 
        def ls_equals(value, *args):
500
 
            out = self.runbzr(['ls'] + list(args), backtick=True)
501
 
            self.assertEquals(out, value)
502
 
 
503
 
        bzr('init')
504
 
        open('a', 'wb').write('hello\n')
505
 
 
506
 
        # Can't supply both
507
 
        bzr('ls --verbose --null', retcode=3)
508
 
 
509
 
        ls_equals('a\n')
510
 
        ls_equals('?        a\n', '--verbose')
511
 
        ls_equals('a\n', '--unknown')
512
 
        ls_equals('', '--ignored')
513
 
        ls_equals('', '--versioned')
514
 
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
515
 
        ls_equals('', '--ignored', '--versioned')
516
 
        ls_equals('a\0', '--null')
517
 
 
518
 
        bzr('add a')
519
 
        ls_equals('V        a\n', '--verbose')
520
 
        bzr('commit -m add')
521
 
        
 
369
        self.runbzr('merge ../b/')
 
370
        assert os.path.exists('sub/a.txt.OTHER')
 
371
        assert os.path.exists('sub/a.txt.BASE')
 
372
 
 
373
    def test_pull(self):
 
374
        """Pull changes from one branch to another."""
 
375
        os.mkdir('a')
 
376
        os.chdir('a')
 
377
 
 
378
        self.example_branch()
 
379
        self.runbzr('pull', retcode=1)
 
380
        self.runbzr('missing', retcode=1)
 
381
        self.runbzr('missing .')
 
382
        self.runbzr('missing')
 
383
        self.runbzr('pull')
 
384
        self.runbzr('pull /', retcode=1)
 
385
        self.runbzr('pull')
 
386
 
 
387
        os.chdir('..')
 
388
        self.runbzr('branch a b')
 
389
        os.chdir('b')
 
390
        self.runbzr('pull')
522
391
        os.mkdir('subdir')
523
 
        ls_equals('V        a\n'
524
 
                  '?        subdir/\n'
525
 
                  , '--verbose')
526
 
        open('subdir/b', 'wb').write('b\n')
527
 
        bzr('add')
528
 
        ls_equals('V        a\n'
529
 
                  'V        subdir/\n'
530
 
                  'V        subdir/b\n'
531
 
                  , '--verbose')
532
 
        bzr('commit -m subdir')
533
 
 
534
 
        ls_equals('a\n'
535
 
                  'subdir\n'
536
 
                  , '--non-recursive')
537
 
 
538
 
        ls_equals('V        a\n'
539
 
                  'V        subdir/\n'
540
 
                  , '--verbose', '--non-recursive')
541
 
 
542
 
        # Check what happens in a sub-directory
543
 
        os.chdir('subdir')
544
 
        ls_equals('b\n')
545
 
        ls_equals('b\0'
546
 
                  , '--null')
547
 
        ls_equals('a\n'
548
 
                  'subdir\n'
549
 
                  'subdir/b\n'
550
 
                  , '--from-root')
551
 
        ls_equals('a\0'
552
 
                  'subdir\0'
553
 
                  'subdir/b\0'
554
 
                  , '--from-root', '--null')
555
 
        ls_equals('a\n'
556
 
                  'subdir\n'
557
 
                  , '--from-root', '--non-recursive')
558
 
 
559
 
        os.chdir('..')
560
 
 
561
 
        # Check what happens when we supply a specific revision
562
 
        ls_equals('a\n', '--revision', '1')
563
 
        ls_equals('V        a\n'
564
 
                  , '--verbose', '--revision', '1')
565
 
 
566
 
        os.chdir('subdir')
567
 
        ls_equals('', '--revision', '1')
568
 
 
569
 
        # Now try to do ignored files.
570
 
        os.chdir('..')
571
 
        open('blah.py', 'wb').write('unknown\n')
572
 
        open('blah.pyo', 'wb').write('ignored\n')
573
 
        ls_equals('a\n'
574
 
                  'blah.py\n'
575
 
                  'blah.pyo\n'
576
 
                  'subdir\n'
577
 
                  'subdir/b\n')
578
 
        ls_equals('V        a\n'
579
 
                  '?        blah.py\n'
580
 
                  'I        blah.pyo\n'
581
 
                  'V        subdir/\n'
582
 
                  'V        subdir/b\n'
583
 
                  , '--verbose')
584
 
        ls_equals('blah.pyo\n'
585
 
                  , '--ignored')
586
 
        ls_equals('blah.py\n'
587
 
                  , '--unknown')
588
 
        ls_equals('a\n'
589
 
                  'subdir\n'
590
 
                  'subdir/b\n'
591
 
                  , '--versioned')
592
 
 
593
 
    def test_pull_verbose(self):
594
 
        """Pull changes from one branch to another and watch the output."""
595
 
 
596
 
        os.mkdir('a')
597
 
        os.chdir('a')
598
 
 
599
 
        bzr = self.runbzr
600
 
        self.example_branch()
601
 
 
602
 
        os.chdir('..')
603
 
        bzr('branch a b')
604
 
        os.chdir('b')
605
 
        open('b', 'wb').write('else\n')
606
 
        bzr('add b')
607
 
        bzr(['commit', '-m', 'added b'])
608
 
 
 
392
        self.runbzr('add subdir')
 
393
        self.runbzr('commit -m blah --unchanged')
609
394
        os.chdir('../a')
610
 
        out = bzr('pull --verbose ../b', backtick=True)
611
 
        self.failIfEqual(out.find('Added Revisions:'), -1)
612
 
        self.failIfEqual(out.find('message:\n  added b'), -1)
613
 
        self.failIfEqual(out.find('added b'), -1)
614
 
 
615
 
        # Check that --overwrite --verbose prints out the removed entries
616
 
        bzr('commit -m foo --unchanged')
 
395
        a = Branch.open('.')
 
396
        b = Branch.open('../b')
 
397
        assert a.revision_history() == b.revision_history()[:-1]
 
398
        self.runbzr('pull ../b')
 
399
        assert a.revision_history() == b.revision_history()
 
400
        self.runbzr('commit -m blah2 --unchanged')
617
401
        os.chdir('../b')
618
 
        bzr('commit -m baz --unchanged')
619
 
        bzr('pull ../a', retcode=3)
620
 
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
621
 
 
622
 
        remove_loc = out.find('Removed Revisions:')
623
 
        self.failIfEqual(remove_loc, -1)
624
 
        added_loc = out.find('Added Revisions:')
625
 
        self.failIfEqual(added_loc, -1)
626
 
 
627
 
        removed_message = out.find('message:\n  baz')
628
 
        self.failIfEqual(removed_message, -1)
629
 
        self.failUnless(remove_loc < removed_message < added_loc)
630
 
 
631
 
        added_message = out.find('message:\n  foo')
632
 
        self.failIfEqual(added_message, -1)
633
 
        self.failUnless(added_loc < added_message)
634
 
        
 
402
        self.runbzr('commit -m blah3 --unchanged')
 
403
        self.runbzr('pull ../a', retcode=1)
 
404
        os.chdir('../a')
 
405
        self.runbzr('merge ../b')
 
406
        self.runbzr('commit -m blah4 --unchanged')
 
407
        os.chdir('../b/subdir')
 
408
        self.runbzr('pull ../../a')
 
409
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
410
        self.runbzr('commit -m blah5 --unchanged')
 
411
        self.runbzr('commit -m blah6 --unchanged')
 
412
        os.chdir('..')
 
413
        self.runbzr('pull ../a')
 
414
        os.chdir('../a')
 
415
        self.runbzr('commit -m blah7 --unchanged')
 
416
        self.runbzr('merge ../b')
 
417
        self.runbzr('commit -m blah8 --unchanged')
 
418
        self.runbzr('pull ../b')
 
419
        self.runbzr('pull ../b')
 
420
 
635
421
    def test_locations(self):
636
422
        """Using and remembering different locations"""
637
423
        os.mkdir('a')
638
424
        os.chdir('a')
639
425
        self.runbzr('init')
640
426
        self.runbzr('commit -m unchanged --unchanged')
641
 
        self.runbzr('pull', retcode=3)
642
 
        self.runbzr('merge', retcode=3)
 
427
        self.runbzr('pull', retcode=1)
 
428
        self.runbzr('merge', retcode=1)
643
429
        self.runbzr('branch . ../b')
644
430
        os.chdir('../b')
645
431
        self.runbzr('pull')
656
442
        os.chdir('../b')
657
443
        self.runbzr('pull')
658
444
        os.chdir('../d')
659
 
        self.runbzr('pull', retcode=3)
 
445
        self.runbzr('pull', retcode=1)
660
446
        self.runbzr('pull ../a --remember')
661
447
        self.runbzr('pull')
662
448
        
664
450
        """add command prints the names of added files."""
665
451
        b = Branch.initialize('.')
666
452
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
667
 
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
453
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
668
454
        # the ordering is not defined at the moment
669
455
        results = sorted(out.rstrip('\n').split('\n'))
670
456
        self.assertEquals(['added dir',
676
462
        """add -q does not print the names of added files."""
677
463
        b = Branch.initialize('.')
678
464
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
679
 
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
 
465
        out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
680
466
        # the ordering is not defined at the moment
681
467
        results = sorted(out.rstrip('\n').split('\n'))
682
468
        self.assertEquals([''], results)
683
469
 
684
 
    def test_add_in_unversioned(self):
685
 
        """Try to add a file in an unversioned directory.
686
 
 
687
 
        "bzr add" should add the parent(s) as necessary.
688
 
        """
689
 
        from bzrlib.branch import Branch
690
 
        Branch.initialize('.')
691
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
692
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
693
 
        self.run_bzr('add', 'inertiatic/esp')
694
 
        self.assertEquals(self.capture('unknowns'), '')
695
 
 
696
 
        # Multiple unversioned parents
697
 
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
698
 
        self.assertEquals(self.capture('unknowns'), 'veil\n')
699
 
        self.run_bzr('add', 'veil/cerpin/taxt')
700
 
        self.assertEquals(self.capture('unknowns'), '')
701
 
 
702
 
        # Check whacky paths work
703
 
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
704
 
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
705
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
706
 
        self.assertEquals(self.capture('unknowns'), '')
707
 
 
708
 
    def test_add_in_versioned(self):
709
 
        """Try to add a file in a versioned directory.
710
 
 
711
 
        "bzr add" should do this happily.
712
 
        """
713
 
        from bzrlib.branch import Branch
714
 
        Branch.initialize('.')
715
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
716
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
717
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
718
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
719
 
        self.run_bzr('add', 'inertiatic/esp')
720
 
        self.assertEquals(self.capture('unknowns'), '')
721
 
 
722
 
    def test_subdir_add(self):
723
 
        """Add in subdirectory should add only things from there down"""
724
 
        from bzrlib.branch import Branch
725
 
        
726
 
        eq = self.assertEqual
727
 
        ass = self.assert_
728
 
        chdir = os.chdir
729
 
        
730
 
        b = Branch.initialize('.')
731
 
        t = b.working_tree()
732
 
        self.build_tree(['src/', 'README'])
733
 
        
734
 
        eq(sorted(t.unknowns()),
735
 
           ['README', 'src'])
736
 
        
737
 
        self.run_bzr('add', 'src')
738
 
        
739
 
        self.build_tree(['src/foo.c'])
740
 
        
741
 
        chdir('src')
742
 
        self.run_bzr('add')
743
 
        
744
 
        self.assertEquals(self.capture('unknowns'), 'README\n')
745
 
        eq(len(t.read_working_inventory()), 3)
746
 
                
747
 
        chdir('..')
748
 
        self.run_bzr('add')
749
 
        self.assertEquals(self.capture('unknowns'), '')
750
 
        self.run_bzr('check')
751
 
 
752
470
    def test_unknown_command(self):
753
471
        """Handling of unknown command."""
754
472
        out, err = self.run_bzr_captured(['fluffy-badger'],
755
 
                                         retcode=3)
 
473
                                         retcode=1)
756
474
        self.assertEquals(out, '')
757
475
        err.index('unknown command')
758
476
 
759
 
    def create_conflicts(self):
760
 
        """Create a conflicted tree"""
 
477
    def test_conflicts(self):
 
478
        """Handling of merge conflicts"""
761
479
        os.mkdir('base')
762
480
        os.chdir('base')
763
481
        file('hello', 'wb').write("hi world")
777
495
        file('question', 'wb').write("What do you get when you multiply six"
778
496
                                   "times nine?")
779
497
        self.runbzr('commit -m this')
780
 
 
781
 
    def test_remerge(self):
782
 
        """Remerge command works as expected"""
783
 
        self.create_conflicts()
784
 
        self.runbzr('merge ../other --show-base', retcode=1)
785
 
        conflict_text = file('hello').read()
786
 
        assert '|||||||' in conflict_text
787
 
        assert 'hi world' in conflict_text
788
 
        self.runbzr('remerge', retcode=1)
789
 
        conflict_text = file('hello').read()
790
 
        assert '|||||||' not in conflict_text
791
 
        assert 'hi world' not in conflict_text
792
 
        os.unlink('hello.OTHER')
793
 
        self.runbzr('remerge hello --merge-type weave', retcode=1)
794
 
        assert os.path.exists('hello.OTHER')
795
 
        file_id = self.runbzr('file-id hello')
796
 
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
797
 
        self.runbzr('remerge --merge-type weave', retcode=1)
798
 
        assert os.path.exists('hello.OTHER')
799
 
        assert not os.path.exists('hello.BASE')
800
 
        assert '|||||||' not in conflict_text
801
 
        assert 'hi world' not in conflict_text
802
 
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
803
 
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
804
 
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
805
 
        self.runbzr('remerge hello --show-base', retcode=1)
806
 
        self.runbzr('remerge hello --reprocess', retcode=1)
807
 
        self.runbzr('resolve --all')
808
 
        self.runbzr('commit -m done',)
809
 
        self.runbzr('remerge', retcode=3)
810
 
 
811
 
 
812
 
    def test_conflicts(self):
813
 
        """Handling of merge conflicts"""
814
 
        self.create_conflicts()
815
 
        self.runbzr('merge ../other --show-base', retcode=1)
816
 
        conflict_text = file('hello').read()
817
 
        self.assert_('<<<<<<<' in conflict_text)
818
 
        self.assert_('>>>>>>>' in conflict_text)
819
 
        self.assert_('=======' in conflict_text)
820
 
        self.assert_('|||||||' in conflict_text)
821
 
        self.assert_('hi world' in conflict_text)
822
 
        self.runbzr('revert')
823
 
        self.runbzr('resolve --all')
824
 
        self.runbzr('merge ../other', retcode=1)
825
 
        conflict_text = file('hello').read()
826
 
        self.assert_('|||||||' not in conflict_text)
827
 
        self.assert_('hi world' not in conflict_text)
 
498
        self.runbzr('merge ../other')
828
499
        result = self.runbzr('conflicts', backtick=1)
829
500
        self.assertEquals(result, "hello\nquestion\n")
830
501
        result = self.runbzr('status', backtick=1)
831
 
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
 
502
        assert "conflicts:\n  hello\n  question\n" in result, result
832
503
        self.runbzr('resolve hello')
833
504
        result = self.runbzr('conflicts', backtick=1)
834
505
        self.assertEquals(result, "question\n")
835
 
        self.runbzr('commit -m conflicts', retcode=3)
 
506
        self.runbzr('commit -m conflicts', retcode=1)
836
507
        self.runbzr('resolve --all')
837
508
        result = self.runbzr('conflicts', backtick=1)
838
509
        self.runbzr('commit -m conflicts')
843
514
        import bzrlib.gpg
844
515
        oldstrategy = bzrlib.gpg.GPGStrategy
845
516
        branch = Branch.initialize('.')
846
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
 
517
        branch.commit("base", allow_pointless=True, rev_id='A')
847
518
        try:
848
519
            # monkey patch gpg signing mechanism
849
520
            from bzrlib.testament import Testament
853
524
                             branch.revision_store.get('A', 'sig').read())
854
525
        finally:
855
526
            bzrlib.gpg.GPGStrategy = oldstrategy
856
 
            
857
 
    def test_resign_range(self):
858
 
        import bzrlib.gpg
859
 
        oldstrategy = bzrlib.gpg.GPGStrategy
860
 
        branch = Branch.initialize('.')
861
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
862
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
863
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
864
 
        try:
865
 
            # monkey patch gpg signing mechanism
866
 
            from bzrlib.testament import Testament
867
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
868
 
            self.runbzr('re-sign -r 1..')
869
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
870
 
                             branch.revision_store.get('A', 'sig').read())
871
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
872
 
                             branch.revision_store.get('B', 'sig').read())
873
 
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
874
 
                             branch.revision_store.get('C', 'sig').read())
875
 
        finally:
876
 
            bzrlib.gpg.GPGStrategy = oldstrategy
877
 
 
878
 
    def test_push(self):
879
 
        # create a source branch
880
 
        os.mkdir('my-branch')
881
 
        os.chdir('my-branch')
882
 
        self.example_branch()
883
 
 
884
 
        # with no push target, fail
885
 
        self.runbzr('push', retcode=3)
886
 
        # with an explicit target work
887
 
        self.runbzr('push ../output-branch')
888
 
        # with an implicit target work
889
 
        self.runbzr('push')
890
 
        # nothing missing
891
 
        self.runbzr('missing ../output-branch')
892
 
        # advance this branch
893
 
        self.runbzr('commit --unchanged -m unchanged')
894
 
 
895
 
        os.chdir('../output-branch')
896
 
        # There is no longer a difference as long as we have
897
 
        # access to the working tree
898
 
        self.runbzr('diff')
899
 
 
900
 
        # But we should be missing a revision
901
 
        self.runbzr('missing ../my-branch', retcode=1)
902
 
 
903
 
        # diverge the branches
904
 
        self.runbzr('commit --unchanged -m unchanged')
905
 
        os.chdir('../my-branch')
906
 
        # cannot push now
907
 
        self.runbzr('push', retcode=3)
908
 
        # and there are difference
909
 
        self.runbzr('missing ../output-branch', retcode=1)
910
 
        self.runbzr('missing --verbose ../output-branch', retcode=1)
911
 
        # but we can force a push
912
 
        self.runbzr('push --overwrite')
913
 
        # nothing missing
914
 
        self.runbzr('missing ../output-branch')
915
 
        
916
 
        # pushing to a new dir with no parent should fail
917
 
        self.runbzr('push ../missing/new-branch', retcode=3)
918
 
        # unless we provide --create-prefix
919
 
        self.runbzr('push --create-prefix ../missing/new-branch')
920
 
        # nothing missing
921
 
        self.runbzr('missing ../missing/new-branch')
922
 
 
923
 
    def test_external_command(self):
924
 
        """test that external commands can be run by setting the path"""
925
 
        cmd_name = 'test-command'
926
 
        output = 'Hello from test-command'
927
 
        if sys.platform == 'win32':
928
 
            cmd_name += '.bat'
929
 
            output += '\r\n'
930
 
        else:
931
 
            output += '\n'
932
 
 
933
 
        oldpath = os.environ.get('BZRPATH', None)
934
 
 
935
 
        bzr = self.capture
936
 
 
937
 
        try:
938
 
            if os.environ.has_key('BZRPATH'):
939
 
                del os.environ['BZRPATH']
940
 
 
941
 
            f = file(cmd_name, 'wb')
942
 
            if sys.platform == 'win32':
943
 
                f.write('@echo off\n')
944
 
            else:
945
 
                f.write('#!/bin/sh\n')
946
 
            f.write('echo Hello from test-command')
947
 
            f.close()
948
 
            os.chmod(cmd_name, 0755)
949
 
 
950
 
            # It should not find the command in the local 
951
 
            # directory by default, since it is not in my path
952
 
            bzr(cmd_name, retcode=3)
953
 
 
954
 
            # Now put it into my path
955
 
            os.environ['BZRPATH'] = '.'
956
 
 
957
 
            bzr(cmd_name)
958
 
            # The test suite does not capture stdout for external commands
959
 
            # this is because you have to have a real file object
960
 
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
961
 
            # (just replacing sys.stdout does not change a spawned objects stdout)
962
 
            #self.assertEquals(bzr(cmd_name), output)
963
 
 
964
 
            # Make sure empty path elements are ignored
965
 
            os.environ['BZRPATH'] = os.pathsep
966
 
 
967
 
            bzr(cmd_name, retcode=3)
968
 
 
969
 
        finally:
970
 
            if oldpath:
971
 
                os.environ['BZRPATH'] = oldpath
972
 
 
973
527
 
974
528
def listdir_sorted(dir):
975
529
    L = os.listdir(dir)
1005
559
        self.assertEquals(capture('unknowns'), 'test.txt\n')
1006
560
 
1007
561
        out = capture("status")
1008
 
        self.assertEquals(out, 'unknown:\n  test.txt\n')
 
562
        assert out == 'unknown:\n  test.txt\n'
1009
563
 
1010
564
        out = capture("status --all")
1011
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
565
        assert out == "unknown:\n  test.txt\n"
1012
566
 
1013
567
        out = capture("status test.txt --all")
1014
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
568
        assert out == "unknown:\n  test.txt\n"
1015
569
 
1016
570
        f = file('test2.txt', 'wt')
1017
571
        f.write('goodbye cruel world...\n')
1018
572
        f.close()
1019
573
 
1020
574
        out = capture("status test.txt")
1021
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
575
        assert out == "unknown:\n  test.txt\n"
1022
576
 
1023
577
        out = capture("status")
1024
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
 
578
        assert out == ("unknown:\n"
 
579
                       "  test.txt\n"
 
580
                       "  test2.txt\n")
1025
581
 
1026
582
        os.unlink('test2.txt')
1027
583
 
1028
584
        progress("command aliases")
1029
585
        out = capture("st --all")
1030
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
586
        assert out == ("unknown:\n"
 
587
                       "  test.txt\n")
1031
588
 
1032
589
        out = capture("stat")
1033
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
590
        assert out == ("unknown:\n"
 
591
                       "  test.txt\n")
1034
592
 
1035
593
        progress("command help")
1036
594
        runbzr("help st")
1037
595
        runbzr("help")
1038
596
        runbzr("help commands")
1039
 
        runbzr("help slartibartfast", 3)
 
597
        runbzr("help slartibartfast", 1)
1040
598
 
1041
599
        out = capture("help ci")
1042
600
        out.index('aliases: ')
1043
601
 
1044
602
        progress("can't rename unversioned file")
1045
 
        runbzr("rename test.txt new-test.txt", 3)
 
603
        runbzr("rename test.txt new-test.txt", 1)
1046
604
 
1047
605
        progress("adding a file")
1048
606
 
1049
607
        runbzr("add test.txt")
1050
 
        self.assertEquals(capture("unknowns"), '')
1051
 
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
 
608
        assert capture("unknowns") == ''
 
609
        assert capture("status --all") == ("added:\n"
 
610
                                                "  test.txt\n")
1052
611
 
1053
612
        progress("rename newly-added file")
1054
613
        runbzr("rename test.txt hello.txt")
1055
 
        self.assert_(os.path.exists("hello.txt"))
1056
 
        self.assert_(not os.path.exists("test.txt"))
 
614
        assert os.path.exists("hello.txt")
 
615
        assert not os.path.exists("test.txt")
1057
616
 
1058
 
        self.assertEquals(capture("revno"), '0\n')
 
617
        assert capture("revno") == '0\n'
1059
618
 
1060
619
        progress("add first revision")
1061
620
        runbzr(['commit', '-m', 'add first revision'])
1062
621
 
1063
622
        progress("more complex renames")
1064
623
        os.mkdir("sub1")
1065
 
        runbzr("rename hello.txt sub1", 3)
1066
 
        runbzr("rename hello.txt sub1/hello.txt", 3)
1067
 
        runbzr("move hello.txt sub1", 3)
 
624
        runbzr("rename hello.txt sub1", 1)
 
625
        runbzr("rename hello.txt sub1/hello.txt", 1)
 
626
        runbzr("move hello.txt sub1", 1)
1068
627
 
1069
628
        runbzr("add sub1")
1070
629
        runbzr("rename sub1 sub2")
1072
631
        self.assertEqual(capture("relpath sub2/hello.txt"),
1073
632
                         os.path.join("sub2", "hello.txt\n"))
1074
633
 
1075
 
        self.assert_(exists("sub2"))
1076
 
        self.assert_(exists("sub2/hello.txt"))
1077
 
        self.assert_(not exists("sub1"))
1078
 
        self.assert_(not exists("hello.txt"))
 
634
        assert exists("sub2")
 
635
        assert exists("sub2/hello.txt")
 
636
        assert not exists("sub1")
 
637
        assert not exists("hello.txt")
1079
638
 
1080
639
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1081
640
 
1082
641
        mkdir("sub1")
1083
642
        runbzr('add sub1')
1084
643
        runbzr('move sub2/hello.txt sub1')
1085
 
        self.assert_(not exists('sub2/hello.txt'))
1086
 
        self.assert_(exists('sub1/hello.txt'))
 
644
        assert not exists('sub2/hello.txt')
 
645
        assert exists('sub1/hello.txt')
1087
646
        runbzr('move sub2 sub1')
1088
 
        self.assert_(not exists('sub2'))
1089
 
        self.assert_(exists('sub1/sub2'))
 
647
        assert not exists('sub2')
 
648
        assert exists('sub1/sub2')
1090
649
 
1091
650
        runbzr(['commit', '-m', 'rename nested subdirectories'])
1092
651
 
1094
653
        self.assertEquals(capture('root')[:-1],
1095
654
                          os.path.join(self.test_dir, 'branch1'))
1096
655
        runbzr('move ../hello.txt .')
1097
 
        self.assert_(exists('./hello.txt'))
 
656
        assert exists('./hello.txt')
1098
657
        self.assertEquals(capture('relpath hello.txt'),
1099
658
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1100
 
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
659
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1101
660
        runbzr(['commit', '-m', 'move to parent directory'])
1102
661
        chdir('..')
1103
 
        self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
662
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1104
663
 
1105
664
        runbzr('move sub2/hello.txt .')
1106
 
        self.assert_(exists('hello.txt'))
 
665
        assert exists('hello.txt')
1107
666
 
1108
667
        f = file('hello.txt', 'wt')
1109
668
        f.write('some nice new content\n')
1115
674
 
1116
675
        runbzr('commit -F msg.tmp')
1117
676
 
1118
 
        self.assertEquals(capture('revno'), '5\n')
 
677
        assert capture('revno') == '5\n'
1119
678
        runbzr('export -r 5 export-5.tmp')
1120
679
        runbzr('export export.tmp')
1121
680
 
1122
681
        runbzr('log')
1123
682
        runbzr('log -v')
1124
683
        runbzr('log -v --forward')
1125
 
        runbzr('log -m', retcode=3)
 
684
        runbzr('log -m', retcode=1)
1126
685
        log_out = capture('log -m commit')
1127
 
        self.assert_("this is my new commit\n  and" in log_out)
1128
 
        self.assert_("rename nested" not in log_out)
1129
 
        self.assert_('revision-id' not in log_out)
1130
 
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
 
686
        assert "this is my new commit\n  and" in log_out
 
687
        assert "rename nested" not in log_out
 
688
        assert 'revision-id' not in log_out
 
689
        assert 'revision-id' in capture('log --show-ids -m commit')
1131
690
 
1132
691
        log_out = capture('log --line')
1133
692
        for line in log_out.splitlines():
1134
 
            self.assert_(len(line) <= 79, len(line))
1135
 
        self.assert_("this is my new commit and" in log_out)
 
693
            assert len(line) <= 79, len(line)
 
694
        assert "this is my new commit and" in log_out
1136
695
 
1137
696
 
1138
697
        progress("file with spaces in name")
1139
698
        mkdir('sub directory')
1140
699
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1141
700
        runbzr('add .')
1142
 
        runbzr('diff', retcode=1)
 
701
        runbzr('diff')
1143
702
        runbzr('commit -m add-spaces')
1144
703
        runbzr('check')
1145
704
 
1155
714
            runbzr('init')
1156
715
            os.symlink("NOWHERE1", "link1")
1157
716
            runbzr('add link1')
1158
 
            self.assertEquals(self.capture('unknowns'), '')
 
717
            assert self.capture('unknowns') == ''
1159
718
            runbzr(['commit', '-m', '1: added symlink link1'])
1160
719
    
1161
720
            mkdir('d1')
1162
721
            runbzr('add d1')
1163
 
            self.assertEquals(self.capture('unknowns'), '')
 
722
            assert self.capture('unknowns') == ''
1164
723
            os.symlink("NOWHERE2", "d1/link2")
1165
 
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
 
724
            assert self.capture('unknowns') == 'd1/link2\n'
1166
725
            # is d1/link2 found when adding d1
1167
726
            runbzr('add d1')
1168
 
            self.assertEquals(self.capture('unknowns'), '')
 
727
            assert self.capture('unknowns') == ''
1169
728
            os.symlink("NOWHERE3", "d1/link3")
1170
 
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
 
729
            assert self.capture('unknowns') == 'd1/link3\n'
1171
730
            runbzr(['commit', '-m', '2: added dir, symlink'])
1172
731
    
1173
732
            runbzr('rename d1 d2')
1174
733
            runbzr('move d2/link2 .')
1175
734
            runbzr('move link1 d2')
1176
 
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1177
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
 
735
            assert os.readlink("./link2") == "NOWHERE2"
 
736
            assert os.readlink("d2/link1") == "NOWHERE1"
1178
737
            runbzr('add d2/link3')
1179
 
            runbzr('diff', retcode=1)
 
738
            runbzr('diff')
1180
739
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1181
740
    
1182
741
            os.unlink("link2")
1183
742
            os.symlink("TARGET 2", "link2")
1184
743
            os.unlink("d2/link1")
1185
744
            os.symlink("TARGET 1", "d2/link1")
1186
 
            runbzr('diff', retcode=1)
1187
 
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
 
745
            runbzr('diff')
 
746
            assert self.capture("relpath d2/link1") == "d2/link1\n"
1188
747
            runbzr(['commit', '-m', '4: retarget of two links'])
1189
748
    
1190
749
            runbzr('remove d2/link1')
1191
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
750
            assert self.capture('unknowns') == 'd2/link1\n'
1192
751
            runbzr(['commit', '-m', '5: remove d2/link1'])
1193
752
            # try with the rm alias
1194
753
            runbzr('add d2/link1')
1195
754
            runbzr(['commit', '-m', '6: add d2/link1'])
1196
755
            runbzr('rm d2/link1')
1197
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
756
            assert self.capture('unknowns') == 'd2/link1\n'
1198
757
            runbzr(['commit', '-m', '7: remove d2/link1'])
1199
758
    
1200
759
            os.mkdir("d1")
1201
760
            runbzr('add d1')
1202
761
            runbzr('rename d2/link3 d1/link3new')
1203
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
762
            assert self.capture('unknowns') == 'd2/link1\n'
1204
763
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1205
764
            
1206
765
            runbzr(['check'])
1207
766
            
1208
767
            runbzr(['export', '-r', '1', 'exp1.tmp'])
1209
768
            chdir("exp1.tmp")
1210
 
            self.assertEquals(listdir_sorted("."), [ "link1" ])
1211
 
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
 
769
            assert listdir_sorted(".") == [ "link1" ]
 
770
            assert os.readlink("link1") == "NOWHERE1"
1212
771
            chdir("..")
1213
772
            
1214
773
            runbzr(['export', '-r', '2', 'exp2.tmp'])
1215
774
            chdir("exp2.tmp")
1216
 
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
 
775
            assert listdir_sorted(".") == [ "d1", "link1" ]
1217
776
            chdir("..")
1218
777
            
1219
778
            runbzr(['export', '-r', '3', 'exp3.tmp'])
1220
779
            chdir("exp3.tmp")
1221
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1222
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1223
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1224
 
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
 
780
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
781
            assert listdir_sorted("d2") == [ "link1", "link3" ]
 
782
            assert os.readlink("d2/link1") == "NOWHERE1"
 
783
            assert os.readlink("link2")    == "NOWHERE2"
1225
784
            chdir("..")
1226
785
            
1227
786
            runbzr(['export', '-r', '4', 'exp4.tmp'])
1228
787
            chdir("exp4.tmp")
1229
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1230
 
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1231
 
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
1232
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
 
788
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
789
            assert os.readlink("d2/link1") == "TARGET 1"
 
790
            assert os.readlink("link2")    == "TARGET 2"
 
791
            assert listdir_sorted("d2") == [ "link1", "link3" ]
1233
792
            chdir("..")
1234
793
            
1235
794
            runbzr(['export', '-r', '5', 'exp5.tmp'])
1236
795
            chdir("exp5.tmp")
1237
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1238
 
            self.assert_(os.path.islink("link2"))
1239
 
            self.assert_(listdir_sorted("d2")== [ "link3" ])
 
796
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
797
            assert os.path.islink("link2")
 
798
            assert listdir_sorted("d2")== [ "link3" ]
1240
799
            chdir("..")
1241
800
            
1242
801
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1243
802
            chdir("exp6.tmp")
1244
803
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1245
 
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1246
 
            self.assertEquals(listdir_sorted("d2"), [])
1247
 
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
 
804
            assert listdir_sorted("d1") == [ "link3new" ]
 
805
            assert listdir_sorted("d2") == []
 
806
            assert os.readlink("d1/link3new") == "NOWHERE3"
1248
807
            chdir("..")
1249
808
        else:
1250
809
            progress("skipping symlink tests")
1256
815
    def test_branch(self):
1257
816
        os.mkdir('from')
1258
817
        branch = Branch.initialize('from')
1259
 
        branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
 
818
        branch.commit('empty commit for nonsense', allow_pointless=True)
1260
819
        url = self.get_remote_url('from')
1261
820
        self.run_bzr('branch', url, 'to')
1262
821
        branch = Branch.open('to')
1265
824
    def test_log(self):
1266
825
        self.build_tree(['branch/', 'branch/file'])
1267
826
        branch = Branch.initialize('branch')
1268
 
        branch.working_tree().add(['file'])
1269
 
        branch.working_tree().commit('add file', rev_id='A')
 
827
        branch.add(['file'])
 
828
        branch.commit('add file', rev_id='A')
1270
829
        url = self.get_remote_url('branch/file')
1271
830
        output = self.capture('log %s' % url)
1272
 
        self.assertEqual(8, len(output.split('\n')))
 
831
        self.assertEqual(7, len(output.split('\n')))
1273
832
        
1274
 
    def test_check(self):
1275
 
        self.build_tree(['branch/', 'branch/file'])
1276
 
        branch = Branch.initialize('branch')
1277
 
        branch.working_tree().add(['file'])
1278
 
        branch.working_tree().commit('add file', rev_id='A')
1279
 
        url = self.get_remote_url('branch/')
1280
 
        self.run_bzr('check', url)
 
833
 
 
834
 
 
835