~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-10-12 10:44:57 UTC
  • mto: (1185.16.26)
  • mto: This revision was merged to the branch mainline in revision 1454.
  • Revision ID: mbp@sourcefrog.net-20051012104457-a186917c83a2afc7
[pick] clear hashcache in format upgrade to avoid worrisome warning

robertc@lifelesslap.robertcollins.net-20051012002452-64068f25c8656f66

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
 
import re
36
29
import shutil
37
30
import sys
 
31
import os
38
32
 
39
33
from bzrlib.branch import Branch
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')
216
173
        self.runbzr('commit -m f')
217
174
        os.unlink('symlink')
218
175
        self.runbzr('revert')
219
 
        self.failUnlessExists('symlink')
220
 
        os.unlink('symlink')
221
 
        os.symlink('a-different-path', 'symlink')
222
 
        self.runbzr('revert')
223
 
        self.assertEqual('/unlikely/to/exist',
224
 
                         os.readlink('symlink'))
225
176
        
226
177
        file('hello', 'wt').write('xyz')
227
178
        self.runbzr('commit -m xyz hello')
233
184
        self.runbzr('revert')
234
185
        os.chdir('..')
235
186
 
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
187
 
252
188
    def test_mv_modes(self):
253
189
        """Test two modes of operation for mv"""
292
228
        self.runbzr('export ../latest')
293
229
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
294
230
        self.runbzr('export ../first -r 1')
295
 
        self.assert_(not os.path.exists('../first/goodbye'))
 
231
        assert not os.path.exists('../first/goodbye')
296
232
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
297
233
        self.runbzr('export ../first.gz -r 1')
298
234
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
299
235
        self.runbzr('export ../first.bz2 -r 1')
300
236
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
301
 
 
 
237
        self.runbzr('export ../first.tar -r 1')
 
238
        assert os.path.isfile('../first.tar')
302
239
        from tarfile import TarFile
303
 
        self.runbzr('export ../first.tar -r 1')
304
 
        self.assert_(os.path.isfile('../first.tar'))
305
240
        tf = TarFile('../first.tar')
306
 
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
 
241
        assert 'first/hello' in tf.getnames(), tf.getnames()
307
242
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
308
243
        self.runbzr('export ../first.tar.gz -r 1')
309
 
        self.assert_(os.path.isfile('../first.tar.gz'))
 
244
        assert os.path.isfile('../first.tar.gz')
310
245
        self.runbzr('export ../first.tbz2 -r 1')
311
 
        self.assert_(os.path.isfile('../first.tbz2'))
 
246
        assert os.path.isfile('../first.tbz2')
312
247
        self.runbzr('export ../first.tar.bz2 -r 1')
313
 
        self.assert_(os.path.isfile('../first.tar.bz2'))
 
248
        assert os.path.isfile('../first.tar.bz2')
314
249
        self.runbzr('export ../first.tar.tbz2 -r 1')
315
 
        self.assert_(os.path.isfile('../first.tar.tbz2'))
316
 
 
 
250
        assert os.path.isfile('../first.tar.tbz2')
317
251
        from bz2 import BZ2File
318
252
        tf = TarFile('../first.tar.tbz2', 
319
253
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
320
 
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
 
254
        assert 'first.tar/hello' in tf.getnames(), tf.getnames()
321
255
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
322
256
        self.runbzr('export ../first2.tar -r 1 --root pizza')
323
257
        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())
 
258
        assert 'pizza/hello' in tf.getnames(), tf.getnames()
340
259
 
341
260
    def test_diff(self):
342
261
        self.example_branch()
343
262
        file('hello', 'wt').write('hello world!')
344
263
        self.runbzr('commit -m fixing hello')
345
 
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
 
264
        output = self.runbzr('diff -r 2..3', backtick=1)
346
265
        self.assert_('\n+hello world!' in output)
347
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
 
266
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
348
267
        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
268
 
354
269
    def test_diff_branches(self):
355
 
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
 
270
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
356
271
        branch = Branch.initialize('branch1')
357
 
        branch.working_tree().add(['file'])
358
 
        branch.working_tree().commit('add file')
 
272
        branch.add(['file'])
 
273
        branch.commit('add file')
359
274
        copy_branch(branch, 'branch2')
360
 
        print >> open('branch2/file', 'wb'), 'new content'
 
275
        print >> open('branch2/file', 'w'), 'new content'
361
276
        branch2 = Branch.open('branch2')
362
 
        branch2.working_tree().commit('update file')
 
277
        branch2.commit('update file')
363
278
        # should open branch1 and diff against branch2, 
364
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
365
 
                                        'branch1'],
366
 
                                       retcode=1)
 
279
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
367
280
        self.assertEquals(("=== modified file 'file'\n"
368
 
                           "--- file\t\n"
369
 
                           "+++ file\t\n"
 
281
                           "--- file\n"
 
282
                           "+++ file\n"
370
283
                           "@@ -1,1 +1,1 @@\n"
371
284
                           "-new content\n"
372
285
                           "+contents of branch1/file\n"
373
286
                           "\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
287
 
385
288
    def test_branch(self):
386
289
        """Branch from one branch to another."""
389
292
        self.example_branch()
390
293
        os.chdir('..')
391
294
        self.runbzr('branch a b')
392
 
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
393
295
        self.runbzr('branch a c -r 1')
394
296
        os.chdir('b')
395
297
        self.runbzr('commit -m foo --unchanged')
416
318
        os.chdir('../a')
417
319
        file('hello', 'wt').write('quuux')
418
320
        # We can't merge when there are in-tree changes
419
 
        self.runbzr('merge ../b', retcode=3)
 
321
        self.runbzr('merge ../b', retcode=1)
420
322
        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')
 
323
        self.runbzr('merge ../b')
430
324
        self.check_file_contents('goodbye', 'quux')
431
325
        # Merging a branch pulls its revision into the tree
432
326
        a = Branch.open('.')
433
327
        b = Branch.open('../b')
434
328
        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(), [])
 
329
        self.log('pending merges: %s', a.pending_merges())
 
330
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
 
331
        #        % (a.pending_merges(), b.last_patch())
441
332
 
442
333
    def test_merge_with_missing_file(self):
443
334
        """Merge handles missing file conflicts"""
465
356
        print >> file('b.txt', 'ab'), "something"
466
357
        print >> file('sub/c.txt', 'ab'), "something"
467
358
        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'))
 
359
        self.runbzr('merge ../a/')
 
360
        assert os.path.exists('sub/a.txt.THIS')
 
361
        assert os.path.exists('sub/a.txt.BASE')
471
362
        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'))
 
363
        self.runbzr('merge ../b/')
 
364
        assert os.path.exists('sub/a.txt.OTHER')
 
365
        assert os.path.exists('sub/a.txt.BASE')
475
366
 
476
367
    def test_pull(self):
477
368
        """Pull changes from one branch to another."""
479
370
        os.chdir('a')
480
371
 
481
372
        self.example_branch()
482
 
        self.runbzr('pull', retcode=3)
483
 
        self.runbzr('missing', retcode=3)
 
373
        self.runbzr('pull', retcode=1)
 
374
        self.runbzr('missing', retcode=1)
484
375
        self.runbzr('missing .')
485
376
        self.runbzr('missing')
486
377
        self.runbzr('pull')
487
 
        self.runbzr('pull /', retcode=3)
 
378
        self.runbzr('pull /', retcode=1)
488
379
        self.runbzr('pull')
489
380
 
490
381
        os.chdir('..')
497
388
        os.chdir('../a')
498
389
        a = Branch.open('.')
499
390
        b = Branch.open('../b')
500
 
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
 
391
        assert a.revision_history() == b.revision_history()[:-1]
501
392
        self.runbzr('pull ../b')
502
 
        self.assertEquals(a.revision_history(), b.revision_history())
 
393
        assert a.revision_history() == b.revision_history()
503
394
        self.runbzr('commit -m blah2 --unchanged')
504
395
        os.chdir('../b')
505
396
        self.runbzr('commit -m blah3 --unchanged')
506
 
        # no overwrite
507
 
        self.runbzr('pull ../a', retcode=3)
508
 
        os.chdir('..')
509
 
        self.runbzr('branch b overwriteme')
510
 
        os.chdir('overwriteme')
511
 
        self.runbzr('pull --overwrite ../a')
512
 
        overwritten = Branch.open('.')
513
 
        self.assertEqual(overwritten.revision_history(),
514
 
                         a.revision_history())
 
397
        self.runbzr('pull ../a', retcode=1)
 
398
        print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
 
399
        return
515
400
        os.chdir('../a')
516
401
        self.runbzr('merge ../b')
517
402
        self.runbzr('commit -m blah4 --unchanged')
518
403
        os.chdir('../b/subdir')
519
404
        self.runbzr('pull ../../a')
520
 
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
 
405
        assert a.revision_history()[-1] == b.revision_history()[-1]
521
406
        self.runbzr('commit -m blah5 --unchanged')
522
407
        self.runbzr('commit -m blah6 --unchanged')
523
408
        os.chdir('..')
529
414
        self.runbzr('pull ../b')
530
415
        self.runbzr('pull ../b')
531
416
 
532
 
    def test_inventory(self):
533
 
        bzr = self.runbzr
534
 
        def output_equals(value, *args):
535
 
            out = self.runbzr(['inventory'] + list(args), backtick=True)
536
 
            self.assertEquals(out, value)
537
 
 
538
 
        bzr('init')
539
 
        open('a', 'wb').write('hello\n')
540
 
        os.mkdir('b')
541
 
 
542
 
        bzr('add a b')
543
 
        bzr('commit -m add')
544
 
 
545
 
        output_equals('a\n', '--kind', 'file')
546
 
        output_equals('b\n', '--kind', 'directory')        
547
 
 
548
 
    def test_ls(self):
549
 
        """Test the abilities of 'bzr ls'"""
550
 
        bzr = self.runbzr
551
 
        def bzrout(*args, **kwargs):
552
 
            kwargs['backtick'] = True
553
 
            return self.runbzr(*args, **kwargs)
554
 
 
555
 
        def ls_equals(value, *args):
556
 
            out = self.runbzr(['ls'] + list(args), backtick=True)
557
 
            self.assertEquals(out, value)
558
 
 
559
 
        bzr('init')
560
 
        open('a', 'wb').write('hello\n')
561
 
 
562
 
        # Can't supply both
563
 
        bzr('ls --verbose --null', retcode=3)
564
 
 
565
 
        ls_equals('a\n')
566
 
        ls_equals('?        a\n', '--verbose')
567
 
        ls_equals('a\n', '--unknown')
568
 
        ls_equals('', '--ignored')
569
 
        ls_equals('', '--versioned')
570
 
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
571
 
        ls_equals('', '--ignored', '--versioned')
572
 
        ls_equals('a\0', '--null')
573
 
 
574
 
        bzr('add a')
575
 
        ls_equals('V        a\n', '--verbose')
576
 
        bzr('commit -m add')
577
 
        
578
 
        os.mkdir('subdir')
579
 
        ls_equals('V        a\n'
580
 
                  '?        subdir/\n'
581
 
                  , '--verbose')
582
 
        open('subdir/b', 'wb').write('b\n')
583
 
        bzr('add')
584
 
        ls_equals('V        a\n'
585
 
                  'V        subdir/\n'
586
 
                  'V        subdir/b\n'
587
 
                  , '--verbose')
588
 
        bzr('commit -m subdir')
589
 
 
590
 
        ls_equals('a\n'
591
 
                  'subdir\n'
592
 
                  , '--non-recursive')
593
 
 
594
 
        ls_equals('V        a\n'
595
 
                  'V        subdir/\n'
596
 
                  , '--verbose', '--non-recursive')
597
 
 
598
 
        # Check what happens in a sub-directory
599
 
        os.chdir('subdir')
600
 
        ls_equals('b\n')
601
 
        ls_equals('b\0'
602
 
                  , '--null')
603
 
        ls_equals('a\n'
604
 
                  'subdir\n'
605
 
                  'subdir/b\n'
606
 
                  , '--from-root')
607
 
        ls_equals('a\0'
608
 
                  'subdir\0'
609
 
                  'subdir/b\0'
610
 
                  , '--from-root', '--null')
611
 
        ls_equals('a\n'
612
 
                  'subdir\n'
613
 
                  , '--from-root', '--non-recursive')
614
 
 
615
 
        os.chdir('..')
616
 
 
617
 
        # Check what happens when we supply a specific revision
618
 
        ls_equals('a\n', '--revision', '1')
619
 
        ls_equals('V        a\n'
620
 
                  , '--verbose', '--revision', '1')
621
 
 
622
 
        os.chdir('subdir')
623
 
        ls_equals('', '--revision', '1')
624
 
 
625
 
        # Now try to do ignored files.
626
 
        os.chdir('..')
627
 
        open('blah.py', 'wb').write('unknown\n')
628
 
        open('blah.pyo', 'wb').write('ignored\n')
629
 
        ls_equals('a\n'
630
 
                  'blah.py\n'
631
 
                  'blah.pyo\n'
632
 
                  'subdir\n'
633
 
                  'subdir/b\n')
634
 
        ls_equals('V        a\n'
635
 
                  '?        blah.py\n'
636
 
                  'I        blah.pyo\n'
637
 
                  'V        subdir/\n'
638
 
                  'V        subdir/b\n'
639
 
                  , '--verbose')
640
 
        ls_equals('blah.pyo\n'
641
 
                  , '--ignored')
642
 
        ls_equals('blah.py\n'
643
 
                  , '--unknown')
644
 
        ls_equals('a\n'
645
 
                  'subdir\n'
646
 
                  'subdir/b\n'
647
 
                  , '--versioned')
648
 
 
649
 
    def test_pull_verbose(self):
650
 
        """Pull changes from one branch to another and watch the output."""
651
 
 
652
 
        os.mkdir('a')
653
 
        os.chdir('a')
654
 
 
655
 
        bzr = self.runbzr
656
 
        self.example_branch()
657
 
 
658
 
        os.chdir('..')
659
 
        bzr('branch a b')
660
 
        os.chdir('b')
661
 
        open('b', 'wb').write('else\n')
662
 
        bzr('add b')
663
 
        bzr(['commit', '-m', 'added b'])
664
 
 
665
 
        os.chdir('../a')
666
 
        out = bzr('pull --verbose ../b', backtick=True)
667
 
        self.failIfEqual(out.find('Added Revisions:'), -1)
668
 
        self.failIfEqual(out.find('message:\n  added b'), -1)
669
 
        self.failIfEqual(out.find('added b'), -1)
670
 
 
671
 
        # Check that --overwrite --verbose prints out the removed entries
672
 
        bzr('commit -m foo --unchanged')
673
 
        os.chdir('../b')
674
 
        bzr('commit -m baz --unchanged')
675
 
        bzr('pull ../a', retcode=3)
676
 
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
677
 
 
678
 
        remove_loc = out.find('Removed Revisions:')
679
 
        self.failIfEqual(remove_loc, -1)
680
 
        added_loc = out.find('Added Revisions:')
681
 
        self.failIfEqual(added_loc, -1)
682
 
 
683
 
        removed_message = out.find('message:\n  baz')
684
 
        self.failIfEqual(removed_message, -1)
685
 
        self.failUnless(remove_loc < removed_message < added_loc)
686
 
 
687
 
        added_message = out.find('message:\n  foo')
688
 
        self.failIfEqual(added_message, -1)
689
 
        self.failUnless(added_loc < added_message)
690
 
        
691
417
    def test_locations(self):
692
418
        """Using and remembering different locations"""
693
419
        os.mkdir('a')
694
420
        os.chdir('a')
695
421
        self.runbzr('init')
696
422
        self.runbzr('commit -m unchanged --unchanged')
697
 
        self.runbzr('pull', retcode=3)
698
 
        self.runbzr('merge', retcode=3)
 
423
        self.runbzr('pull', retcode=1)
 
424
        self.runbzr('merge', retcode=1)
699
425
        self.runbzr('branch . ../b')
700
426
        os.chdir('../b')
701
427
        self.runbzr('pull')
712
438
        os.chdir('../b')
713
439
        self.runbzr('pull')
714
440
        os.chdir('../d')
715
 
        self.runbzr('pull', retcode=3)
 
441
        self.runbzr('pull', retcode=1)
716
442
        self.runbzr('pull ../a --remember')
717
443
        self.runbzr('pull')
718
444
        
720
446
        """add command prints the names of added files."""
721
447
        b = Branch.initialize('.')
722
448
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
723
 
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
449
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
724
450
        # the ordering is not defined at the moment
725
451
        results = sorted(out.rstrip('\n').split('\n'))
726
452
        self.assertEquals(['added dir',
728
454
                           'added top.txt',],
729
455
                          results)
730
456
 
731
 
    def test_add_quiet_is(self):
732
 
        """add -q does not print the names of added files."""
733
 
        b = Branch.initialize('.')
734
 
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
735
 
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
736
 
        # the ordering is not defined at the moment
737
 
        results = sorted(out.rstrip('\n').split('\n'))
738
 
        self.assertEquals([''], results)
739
 
 
740
 
    def test_add_in_unversioned(self):
741
 
        """Try to add a file in an unversioned directory.
742
 
 
743
 
        "bzr add" should add the parent(s) as necessary.
744
 
        """
745
 
        from bzrlib.branch import Branch
746
 
        Branch.initialize('.')
747
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
748
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
749
 
        self.run_bzr('add', 'inertiatic/esp')
750
 
        self.assertEquals(self.capture('unknowns'), '')
751
 
 
752
 
        # Multiple unversioned parents
753
 
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
754
 
        self.assertEquals(self.capture('unknowns'), 'veil\n')
755
 
        self.run_bzr('add', 'veil/cerpin/taxt')
756
 
        self.assertEquals(self.capture('unknowns'), '')
757
 
 
758
 
        # Check whacky paths work
759
 
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
760
 
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
761
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
762
 
        self.assertEquals(self.capture('unknowns'), '')
763
 
 
764
 
    def test_add_in_versioned(self):
765
 
        """Try to add a file in a versioned directory.
766
 
 
767
 
        "bzr add" should do this happily.
768
 
        """
769
 
        from bzrlib.branch import Branch
770
 
        Branch.initialize('.')
771
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
772
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
773
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
774
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
775
 
        self.run_bzr('add', 'inertiatic/esp')
776
 
        self.assertEquals(self.capture('unknowns'), '')
777
 
 
778
 
    def test_subdir_add(self):
779
 
        """Add in subdirectory should add only things from there down"""
780
 
        from bzrlib.branch import Branch
781
 
        
782
 
        eq = self.assertEqual
783
 
        ass = self.assert_
784
 
        chdir = os.chdir
785
 
        
786
 
        b = Branch.initialize('.')
787
 
        t = b.working_tree()
788
 
        self.build_tree(['src/', 'README'])
789
 
        
790
 
        eq(sorted(t.unknowns()),
791
 
           ['README', 'src'])
792
 
        
793
 
        self.run_bzr('add', 'src')
794
 
        
795
 
        self.build_tree(['src/foo.c'])
796
 
        
797
 
        chdir('src')
798
 
        self.run_bzr('add')
799
 
        
800
 
        self.assertEquals(self.capture('unknowns'), 'README\n')
801
 
        eq(len(t.read_working_inventory()), 3)
802
 
                
803
 
        chdir('..')
804
 
        self.run_bzr('add')
805
 
        self.assertEquals(self.capture('unknowns'), '')
806
 
        self.run_bzr('check')
807
 
 
808
457
    def test_unknown_command(self):
809
458
        """Handling of unknown command."""
810
459
        out, err = self.run_bzr_captured(['fluffy-badger'],
811
 
                                         retcode=3)
 
460
                                         retcode=1)
812
461
        self.assertEquals(out, '')
813
462
        err.index('unknown command')
814
463
 
815
 
    def create_conflicts(self):
816
 
        """Create a conflicted tree"""
 
464
    def test_conflicts(self):
 
465
        """Handling of merge conflicts"""
817
466
        os.mkdir('base')
818
467
        os.chdir('base')
819
468
        file('hello', 'wb').write("hi world")
833
482
        file('question', 'wb').write("What do you get when you multiply six"
834
483
                                   "times nine?")
835
484
        self.runbzr('commit -m this')
836
 
 
837
 
    def test_remerge(self):
838
 
        """Remerge command works as expected"""
839
 
        self.create_conflicts()
840
 
        self.runbzr('merge ../other --show-base', retcode=1)
841
 
        conflict_text = file('hello').read()
842
 
        assert '|||||||' in conflict_text
843
 
        assert 'hi world' in conflict_text
844
 
        self.runbzr('remerge', retcode=1)
845
 
        conflict_text = file('hello').read()
846
 
        assert '|||||||' not in conflict_text
847
 
        assert 'hi world' not in conflict_text
848
 
        os.unlink('hello.OTHER')
849
 
        self.runbzr('remerge hello --merge-type weave', retcode=1)
850
 
        assert os.path.exists('hello.OTHER')
851
 
        file_id = self.runbzr('file-id hello')
852
 
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
853
 
        self.runbzr('remerge --merge-type weave', retcode=1)
854
 
        assert os.path.exists('hello.OTHER')
855
 
        assert not os.path.exists('hello.BASE')
856
 
        assert '|||||||' not in conflict_text
857
 
        assert 'hi world' not in conflict_text
858
 
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
859
 
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
860
 
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
861
 
        self.runbzr('remerge hello --show-base', retcode=1)
862
 
        self.runbzr('remerge hello --reprocess', retcode=1)
863
 
        self.runbzr('resolve --all')
864
 
        self.runbzr('commit -m done',)
865
 
        self.runbzr('remerge', retcode=3)
866
 
 
867
 
 
868
 
    def test_conflicts(self):
869
 
        """Handling of merge conflicts"""
870
 
        self.create_conflicts()
871
 
        self.runbzr('merge ../other --show-base', retcode=1)
872
 
        conflict_text = file('hello').read()
873
 
        self.assert_('<<<<<<<' in conflict_text)
874
 
        self.assert_('>>>>>>>' in conflict_text)
875
 
        self.assert_('=======' in conflict_text)
876
 
        self.assert_('|||||||' in conflict_text)
877
 
        self.assert_('hi world' in conflict_text)
878
 
        self.runbzr('revert')
879
 
        self.runbzr('resolve --all')
880
 
        self.runbzr('merge ../other', retcode=1)
881
 
        conflict_text = file('hello').read()
882
 
        self.assert_('|||||||' not in conflict_text)
883
 
        self.assert_('hi world' not in conflict_text)
 
485
        self.runbzr('merge ../other')
884
486
        result = self.runbzr('conflicts', backtick=1)
885
487
        self.assertEquals(result, "hello\nquestion\n")
886
488
        result = self.runbzr('status', backtick=1)
887
 
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
 
489
        assert "conflicts:\n  hello\n  question\n" in result, result
888
490
        self.runbzr('resolve hello')
889
491
        result = self.runbzr('conflicts', backtick=1)
890
492
        self.assertEquals(result, "question\n")
891
 
        self.runbzr('commit -m conflicts', retcode=3)
 
493
        self.runbzr('commit -m conflicts', retcode=1)
892
494
        self.runbzr('resolve --all')
893
495
        result = self.runbzr('conflicts', backtick=1)
894
496
        self.runbzr('commit -m conflicts')
895
497
        self.assertEquals(result, "")
896
498
 
897
 
    def test_resign(self):
898
 
        """Test re signing of data."""
899
 
        import bzrlib.gpg
900
 
        oldstrategy = bzrlib.gpg.GPGStrategy
901
 
        branch = Branch.initialize('.')
902
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
903
 
        try:
904
 
            # monkey patch gpg signing mechanism
905
 
            from bzrlib.testament import Testament
906
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
907
 
            self.runbzr('re-sign -r revid:A')
908
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
909
 
                             branch.revision_store.get('A', 'sig').read())
910
 
        finally:
911
 
            bzrlib.gpg.GPGStrategy = oldstrategy
912
 
            
913
 
    def test_resign_range(self):
914
 
        import bzrlib.gpg
915
 
        oldstrategy = bzrlib.gpg.GPGStrategy
916
 
        branch = Branch.initialize('.')
917
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
918
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
919
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
920
 
        try:
921
 
            # monkey patch gpg signing mechanism
922
 
            from bzrlib.testament import Testament
923
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
924
 
            self.runbzr('re-sign -r 1..')
925
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
926
 
                             branch.revision_store.get('A', 'sig').read())
927
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
928
 
                             branch.revision_store.get('B', 'sig').read())
929
 
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
930
 
                             branch.revision_store.get('C', 'sig').read())
931
 
        finally:
932
 
            bzrlib.gpg.GPGStrategy = oldstrategy
933
 
 
934
 
    def test_push(self):
935
 
        # create a source branch
936
 
        os.mkdir('my-branch')
937
 
        os.chdir('my-branch')
938
 
        self.example_branch()
939
 
 
940
 
        # with no push target, fail
941
 
        self.runbzr('push', retcode=3)
942
 
        # with an explicit target work
943
 
        self.runbzr('push ../output-branch')
944
 
        # with an implicit target work
945
 
        self.runbzr('push')
946
 
        # nothing missing
947
 
        self.runbzr('missing ../output-branch')
948
 
        # advance this branch
949
 
        self.runbzr('commit --unchanged -m unchanged')
950
 
 
951
 
        os.chdir('../output-branch')
952
 
        # should be a diff as we have not pushed the tree
953
 
        self.runbzr('diff', retcode=1)
954
 
        self.runbzr('revert')
955
 
        # but not now.
956
 
        self.runbzr('diff')
957
 
        # diverge the branches
958
 
        self.runbzr('commit --unchanged -m unchanged')
959
 
        os.chdir('../my-branch')
960
 
        # cannot push now
961
 
        self.runbzr('push', retcode=3)
962
 
        # and there are difference
963
 
        self.runbzr('missing ../output-branch', retcode=1)
964
 
        self.runbzr('missing --verbose ../output-branch', retcode=1)
965
 
        # but we can force a push
966
 
        self.runbzr('push --overwrite')
967
 
        # nothing missing
968
 
        self.runbzr('missing ../output-branch')
969
 
        
970
 
        # pushing to a new dir with no parent should fail
971
 
        self.runbzr('push ../missing/new-branch', retcode=3)
972
 
        # unless we provide --create-prefix
973
 
        self.runbzr('push --create-prefix ../missing/new-branch')
974
 
        # nothing missing
975
 
        self.runbzr('missing ../missing/new-branch')
976
 
 
977
 
    def test_external_command(self):
978
 
        """test that external commands can be run by setting the path"""
979
 
        cmd_name = 'test-command'
980
 
        output = 'Hello from test-command'
981
 
        if sys.platform == 'win32':
982
 
            cmd_name += '.bat'
983
 
            output += '\r\n'
984
 
        else:
985
 
            output += '\n'
986
 
 
987
 
        oldpath = os.environ.get('BZRPATH', None)
988
 
 
989
 
        bzr = self.capture
990
 
 
991
 
        try:
992
 
            if os.environ.has_key('BZRPATH'):
993
 
                del os.environ['BZRPATH']
994
 
 
995
 
            f = file(cmd_name, 'wb')
996
 
            if sys.platform == 'win32':
997
 
                f.write('@echo off\n')
998
 
            else:
999
 
                f.write('#!/bin/sh\n')
1000
 
            f.write('echo Hello from test-command')
1001
 
            f.close()
1002
 
            os.chmod(cmd_name, 0755)
1003
 
 
1004
 
            # It should not find the command in the local 
1005
 
            # directory by default, since it is not in my path
1006
 
            bzr(cmd_name, retcode=3)
1007
 
 
1008
 
            # Now put it into my path
1009
 
            os.environ['BZRPATH'] = '.'
1010
 
 
1011
 
            bzr(cmd_name)
1012
 
            # The test suite does not capture stdout for external commands
1013
 
            # this is because you have to have a real file object
1014
 
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
1015
 
            # (just replacing sys.stdout does not change a spawned objects stdout)
1016
 
            #self.assertEquals(bzr(cmd_name), output)
1017
 
 
1018
 
            # Make sure empty path elements are ignored
1019
 
            os.environ['BZRPATH'] = os.pathsep
1020
 
 
1021
 
            bzr(cmd_name, retcode=3)
1022
 
 
1023
 
        finally:
1024
 
            if oldpath:
1025
 
                os.environ['BZRPATH'] = oldpath
1026
 
 
1027
 
 
1028
499
def listdir_sorted(dir):
1029
500
    L = os.listdir(dir)
1030
501
    L.sort()
1059
530
        self.assertEquals(capture('unknowns'), 'test.txt\n')
1060
531
 
1061
532
        out = capture("status")
1062
 
        self.assertEquals(out, 'unknown:\n  test.txt\n')
 
533
        assert out == 'unknown:\n  test.txt\n'
1063
534
 
1064
535
        out = capture("status --all")
1065
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
536
        assert out == "unknown:\n  test.txt\n"
1066
537
 
1067
538
        out = capture("status test.txt --all")
1068
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
539
        assert out == "unknown:\n  test.txt\n"
1069
540
 
1070
541
        f = file('test2.txt', 'wt')
1071
542
        f.write('goodbye cruel world...\n')
1072
543
        f.close()
1073
544
 
1074
545
        out = capture("status test.txt")
1075
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
546
        assert out == "unknown:\n  test.txt\n"
1076
547
 
1077
548
        out = capture("status")
1078
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
 
549
        assert out == ("unknown:\n"
 
550
                       "  test.txt\n"
 
551
                       "  test2.txt\n")
1079
552
 
1080
553
        os.unlink('test2.txt')
1081
554
 
1082
555
        progress("command aliases")
1083
556
        out = capture("st --all")
1084
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
557
        assert out == ("unknown:\n"
 
558
                       "  test.txt\n")
1085
559
 
1086
560
        out = capture("stat")
1087
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
561
        assert out == ("unknown:\n"
 
562
                       "  test.txt\n")
1088
563
 
1089
564
        progress("command help")
1090
565
        runbzr("help st")
1091
566
        runbzr("help")
1092
567
        runbzr("help commands")
1093
 
        runbzr("help slartibartfast", 3)
 
568
        runbzr("help slartibartfast", 1)
1094
569
 
1095
570
        out = capture("help ci")
1096
571
        out.index('aliases: ')
1097
572
 
1098
573
        progress("can't rename unversioned file")
1099
 
        runbzr("rename test.txt new-test.txt", 3)
 
574
        runbzr("rename test.txt new-test.txt", 1)
1100
575
 
1101
576
        progress("adding a file")
1102
577
 
1103
578
        runbzr("add test.txt")
1104
 
        self.assertEquals(capture("unknowns"), '')
1105
 
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
 
579
        assert capture("unknowns") == ''
 
580
        assert capture("status --all") == ("added:\n"
 
581
                                                "  test.txt\n")
1106
582
 
1107
583
        progress("rename newly-added file")
1108
584
        runbzr("rename test.txt hello.txt")
1109
 
        self.assert_(os.path.exists("hello.txt"))
1110
 
        self.assert_(not os.path.exists("test.txt"))
 
585
        assert os.path.exists("hello.txt")
 
586
        assert not os.path.exists("test.txt")
1111
587
 
1112
 
        self.assertEquals(capture("revno"), '0\n')
 
588
        assert capture("revno") == '0\n'
1113
589
 
1114
590
        progress("add first revision")
1115
591
        runbzr(['commit', '-m', 'add first revision'])
1116
592
 
1117
593
        progress("more complex renames")
1118
594
        os.mkdir("sub1")
1119
 
        runbzr("rename hello.txt sub1", 3)
1120
 
        runbzr("rename hello.txt sub1/hello.txt", 3)
1121
 
        runbzr("move hello.txt sub1", 3)
 
595
        runbzr("rename hello.txt sub1", 1)
 
596
        runbzr("rename hello.txt sub1/hello.txt", 1)
 
597
        runbzr("move hello.txt sub1", 1)
1122
598
 
1123
599
        runbzr("add sub1")
1124
600
        runbzr("rename sub1 sub2")
1125
601
        runbzr("move hello.txt sub2")
1126
 
        self.assertEqual(capture("relpath sub2/hello.txt"),
1127
 
                         os.path.join("sub2", "hello.txt\n"))
 
602
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1128
603
 
1129
 
        self.assert_(exists("sub2"))
1130
 
        self.assert_(exists("sub2/hello.txt"))
1131
 
        self.assert_(not exists("sub1"))
1132
 
        self.assert_(not exists("hello.txt"))
 
604
        assert exists("sub2")
 
605
        assert exists("sub2/hello.txt")
 
606
        assert not exists("sub1")
 
607
        assert not exists("hello.txt")
1133
608
 
1134
609
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1135
610
 
1136
611
        mkdir("sub1")
1137
612
        runbzr('add sub1')
1138
613
        runbzr('move sub2/hello.txt sub1')
1139
 
        self.assert_(not exists('sub2/hello.txt'))
1140
 
        self.assert_(exists('sub1/hello.txt'))
 
614
        assert not exists('sub2/hello.txt')
 
615
        assert exists('sub1/hello.txt')
1141
616
        runbzr('move sub2 sub1')
1142
 
        self.assert_(not exists('sub2'))
1143
 
        self.assert_(exists('sub1/sub2'))
 
617
        assert not exists('sub2')
 
618
        assert exists('sub1/sub2')
1144
619
 
1145
620
        runbzr(['commit', '-m', 'rename nested subdirectories'])
1146
621
 
1148
623
        self.assertEquals(capture('root')[:-1],
1149
624
                          os.path.join(self.test_dir, 'branch1'))
1150
625
        runbzr('move ../hello.txt .')
1151
 
        self.assert_(exists('./hello.txt'))
 
626
        assert exists('./hello.txt')
1152
627
        self.assertEquals(capture('relpath hello.txt'),
1153
628
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1154
 
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
629
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1155
630
        runbzr(['commit', '-m', 'move to parent directory'])
1156
631
        chdir('..')
1157
 
        self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
632
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1158
633
 
1159
634
        runbzr('move sub2/hello.txt .')
1160
 
        self.assert_(exists('hello.txt'))
 
635
        assert exists('hello.txt')
1161
636
 
1162
637
        f = file('hello.txt', 'wt')
1163
638
        f.write('some nice new content\n')
1164
639
        f.close()
1165
640
 
1166
641
        f = file('msg.tmp', 'wt')
1167
 
        f.write('this is my new commit\nand it has multiple lines, for fun')
 
642
        f.write('this is my new commit\n')
1168
643
        f.close()
1169
644
 
1170
645
        runbzr('commit -F msg.tmp')
1171
646
 
1172
 
        self.assertEquals(capture('revno'), '5\n')
 
647
        assert capture('revno') == '5\n'
1173
648
        runbzr('export -r 5 export-5.tmp')
1174
649
        runbzr('export export.tmp')
1175
650
 
1176
651
        runbzr('log')
1177
652
        runbzr('log -v')
1178
653
        runbzr('log -v --forward')
1179
 
        runbzr('log -m', retcode=3)
 
654
        runbzr('log -m', retcode=1)
1180
655
        log_out = capture('log -m commit')
1181
 
        self.assert_("this is my new commit\n  and" in log_out)
1182
 
        self.assert_("rename nested" not in log_out)
1183
 
        self.assert_('revision-id' not in log_out)
1184
 
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
1185
 
 
1186
 
        log_out = capture('log --line')
1187
 
        for line in log_out.splitlines():
1188
 
            self.assert_(len(line) <= 79, len(line))
1189
 
        self.assert_("this is my new commit and" in log_out)
 
656
        assert "this is my new commit" in log_out
 
657
        assert "rename nested" not in log_out
 
658
        assert 'revision-id' not in log_out
 
659
        assert 'revision-id' in capture('log --show-ids -m commit')
1190
660
 
1191
661
 
1192
662
        progress("file with spaces in name")
1193
663
        mkdir('sub directory')
1194
664
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1195
665
        runbzr('add .')
1196
 
        runbzr('diff', retcode=1)
 
666
        runbzr('diff')
1197
667
        runbzr('commit -m add-spaces')
1198
668
        runbzr('check')
1199
669
 
1209
679
            runbzr('init')
1210
680
            os.symlink("NOWHERE1", "link1")
1211
681
            runbzr('add link1')
1212
 
            self.assertEquals(self.capture('unknowns'), '')
 
682
            assert self.capture('unknowns') == ''
1213
683
            runbzr(['commit', '-m', '1: added symlink link1'])
1214
684
    
1215
685
            mkdir('d1')
1216
686
            runbzr('add d1')
1217
 
            self.assertEquals(self.capture('unknowns'), '')
 
687
            assert self.capture('unknowns') == ''
1218
688
            os.symlink("NOWHERE2", "d1/link2")
1219
 
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
 
689
            assert self.capture('unknowns') == 'd1/link2\n'
1220
690
            # is d1/link2 found when adding d1
1221
691
            runbzr('add d1')
1222
 
            self.assertEquals(self.capture('unknowns'), '')
 
692
            assert self.capture('unknowns') == ''
1223
693
            os.symlink("NOWHERE3", "d1/link3")
1224
 
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
 
694
            assert self.capture('unknowns') == 'd1/link3\n'
1225
695
            runbzr(['commit', '-m', '2: added dir, symlink'])
1226
696
    
1227
697
            runbzr('rename d1 d2')
1228
698
            runbzr('move d2/link2 .')
1229
699
            runbzr('move link1 d2')
1230
 
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1231
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
 
700
            assert os.readlink("./link2") == "NOWHERE2"
 
701
            assert os.readlink("d2/link1") == "NOWHERE1"
1232
702
            runbzr('add d2/link3')
1233
 
            runbzr('diff', retcode=1)
 
703
            runbzr('diff')
1234
704
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1235
705
    
1236
706
            os.unlink("link2")
1237
707
            os.symlink("TARGET 2", "link2")
1238
708
            os.unlink("d2/link1")
1239
709
            os.symlink("TARGET 1", "d2/link1")
1240
 
            runbzr('diff', retcode=1)
1241
 
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
 
710
            runbzr('diff')
 
711
            assert self.capture("relpath d2/link1") == "d2/link1\n"
1242
712
            runbzr(['commit', '-m', '4: retarget of two links'])
1243
713
    
1244
714
            runbzr('remove d2/link1')
1245
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
715
            assert self.capture('unknowns') == 'd2/link1\n'
1246
716
            runbzr(['commit', '-m', '5: remove d2/link1'])
1247
717
            # try with the rm alias
1248
718
            runbzr('add d2/link1')
1249
719
            runbzr(['commit', '-m', '6: add d2/link1'])
1250
720
            runbzr('rm d2/link1')
1251
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
721
            assert self.capture('unknowns') == 'd2/link1\n'
1252
722
            runbzr(['commit', '-m', '7: remove d2/link1'])
1253
723
    
1254
724
            os.mkdir("d1")
1255
725
            runbzr('add d1')
1256
726
            runbzr('rename d2/link3 d1/link3new')
1257
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
727
            assert self.capture('unknowns') == 'd2/link1\n'
1258
728
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1259
729
            
1260
730
            runbzr(['check'])
1261
731
            
1262
732
            runbzr(['export', '-r', '1', 'exp1.tmp'])
1263
733
            chdir("exp1.tmp")
1264
 
            self.assertEquals(listdir_sorted("."), [ "link1" ])
1265
 
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
 
734
            assert listdir_sorted(".") == [ "link1" ]
 
735
            assert os.readlink("link1") == "NOWHERE1"
1266
736
            chdir("..")
1267
737
            
1268
738
            runbzr(['export', '-r', '2', 'exp2.tmp'])
1269
739
            chdir("exp2.tmp")
1270
 
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
 
740
            assert listdir_sorted(".") == [ "d1", "link1" ]
1271
741
            chdir("..")
1272
742
            
1273
743
            runbzr(['export', '-r', '3', 'exp3.tmp'])
1274
744
            chdir("exp3.tmp")
1275
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1276
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1277
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1278
 
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
 
745
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
746
            assert listdir_sorted("d2") == [ "link1", "link3" ]
 
747
            assert os.readlink("d2/link1") == "NOWHERE1"
 
748
            assert os.readlink("link2")    == "NOWHERE2"
1279
749
            chdir("..")
1280
750
            
1281
751
            runbzr(['export', '-r', '4', 'exp4.tmp'])
1282
752
            chdir("exp4.tmp")
1283
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1284
 
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1285
 
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
1286
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
 
753
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
754
            assert os.readlink("d2/link1") == "TARGET 1"
 
755
            assert os.readlink("link2")    == "TARGET 2"
 
756
            assert listdir_sorted("d2") == [ "link1", "link3" ]
1287
757
            chdir("..")
1288
758
            
1289
759
            runbzr(['export', '-r', '5', 'exp5.tmp'])
1290
760
            chdir("exp5.tmp")
1291
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1292
 
            self.assert_(os.path.islink("link2"))
1293
 
            self.assert_(listdir_sorted("d2")== [ "link3" ])
 
761
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
762
            assert os.path.islink("link2")
 
763
            assert listdir_sorted("d2")== [ "link3" ]
1294
764
            chdir("..")
1295
765
            
1296
766
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1297
767
            chdir("exp6.tmp")
1298
768
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1299
 
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1300
 
            self.assertEquals(listdir_sorted("d2"), [])
1301
 
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
 
769
            assert listdir_sorted("d1") == [ "link3new" ]
 
770
            assert listdir_sorted("d2") == []
 
771
            assert os.readlink("d1/link3new") == "NOWHERE3"
1302
772
            chdir("..")
1303
773
        else:
1304
774
            progress("skipping symlink tests")
1310
780
    def test_branch(self):
1311
781
        os.mkdir('from')
1312
782
        branch = Branch.initialize('from')
1313
 
        branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
 
783
        branch.commit('empty commit for nonsense', allow_pointless=True)
1314
784
        url = self.get_remote_url('from')
1315
785
        self.run_bzr('branch', url, 'to')
1316
786
        branch = Branch.open('to')
1317
787
        self.assertEqual(1, len(branch.revision_history()))
1318
 
 
1319
 
    def test_log(self):
1320
 
        self.build_tree(['branch/', 'branch/file'])
1321
 
        branch = Branch.initialize('branch')
1322
 
        branch.working_tree().add(['file'])
1323
 
        branch.working_tree().commit('add file', rev_id='A')
1324
 
        url = self.get_remote_url('branch/file')
1325
 
        output = self.capture('log %s' % url)
1326
 
        self.assertEqual(8, len(output.split('\n')))
1327
 
        
1328
 
    def test_check(self):
1329
 
        self.build_tree(['branch/', 'branch/file'])
1330
 
        branch = Branch.initialize('branch')
1331
 
        branch.working_tree().add(['file'])
1332
 
        branch.working_tree().commit('add file', rev_id='A')
1333
 
        url = self.get_remote_url('branch/')
1334
 
        self.run_bzr('check', url)