~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: abentley
  • Date: 2005-10-14 03:50:50 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014035050-d779472ccb599a51
semi-broke merge

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