~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Robert Collins
  • Date: 2005-10-06 12:14:01 UTC
  • mfrom: (1393.1.67)
  • Revision ID: robertc@robertcollins.net-20051006121401-ce87bcb93909bbdf
merge martins latest

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Black-box tests for bzr.
20
20
 
21
21
These check that it behaves properly when it's invoked through the regular
22
 
command-line interface.
23
 
 
24
 
This always reinvokes bzr through a new Python interpreter, which is a
25
 
bit inefficient but arguably tests in a way more representative of how
26
 
it's normally invoked.
 
22
command-line interface. This doesn't actually run a new interpreter but 
 
23
rather starts again from the run_bzr function.
27
24
"""
28
25
 
 
26
 
 
27
from cStringIO import StringIO
 
28
import os
 
29
import shutil
29
30
import sys
30
31
import os
31
32
 
 
33
from bzrlib.branch import Branch
 
34
from bzrlib.errors import BzrCommandError
 
35
from bzrlib.osutils import has_symlinks
32
36
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
33
 
from bzrlib.branch import Branch
34
 
from bzrlib.commands import run_bzr
 
37
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
35
38
 
36
39
 
37
40
class ExternalBase(TestCaseInTempDir):
38
 
    def runbzr(self, args, retcode=0,backtick=False):
 
41
 
 
42
    def runbzr(self, args, retcode=0, backtick=False):
39
43
        if isinstance(args, basestring):
40
44
            args = args.split()
41
45
 
42
46
        if backtick:
43
 
            return self.backtick(['python', self.BZRPATH,] + args,
44
 
                           retcode=retcode)
 
47
            return self.run_bzr_captured(args, retcode=retcode)[0]
45
48
        else:
46
 
            return self.runcmd(['python', self.BZRPATH,] + args,
47
 
                           retcode=retcode)
 
49
            return self.run_bzr_captured(args, retcode=retcode)
48
50
 
49
51
 
50
52
class TestCommands(ExternalBase):
73
75
        f = file('.bzr/email', 'wt')
74
76
        f.write('Branch Identity <branch@identi.ty>')
75
77
        f.close()
 
78
        bzr_email = os.environ.get('BZREMAIL')
 
79
        if bzr_email is not None:
 
80
            del os.environ['BZREMAIL']
76
81
        whoami = self.runbzr("whoami",backtick=True)
77
82
        whoami_email = self.runbzr("whoami --email",backtick=True)
78
83
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
84
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
 
85
        # Verify that the environment variable overrides the value 
 
86
        # in the file
 
87
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
 
88
        whoami = self.runbzr("whoami",backtick=True)
 
89
        whoami_email = self.runbzr("whoami --email",backtick=True)
 
90
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
 
91
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
 
92
        if bzr_email is not None:
 
93
            os.environ['BZREMAIL'] = bzr_email
80
94
 
81
95
    def test_invalid_commands(self):
82
96
        self.runbzr("pants", retcode=1)
90
104
        self.runbzr("add hello.txt")
91
105
        self.runbzr("commit -m added")
92
106
 
 
107
    def test_empty_commit_message(self):
 
108
        self.runbzr("init")
 
109
        file('foo.c', 'wt').write('int main() {}')
 
110
        self.runbzr(['add', 'foo.c'])
 
111
        self.runbzr(["commit", "-m", ""] , retcode=1) 
 
112
 
93
113
    def test_ignore_patterns(self):
94
114
        from bzrlib.branch import Branch
95
115
        
96
 
        b = Branch('.', init=True)
 
116
        b = Branch.initialize('.')
97
117
        self.assertEquals(list(b.unknowns()), [])
98
118
 
99
119
        file('foo.tmp', 'wt').write('tmp files are ignored')
100
120
        self.assertEquals(list(b.unknowns()), [])
101
 
        assert self.backtick('bzr unknowns') == ''
 
121
        assert self.capture('unknowns') == ''
102
122
 
103
123
        file('foo.c', 'wt').write('int main() {}')
104
124
        self.assertEquals(list(b.unknowns()), ['foo.c'])
105
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
 
125
        assert self.capture('unknowns') == 'foo.c\n'
106
126
 
107
127
        self.runbzr(['add', 'foo.c'])
108
 
        assert self.backtick('bzr unknowns') == ''
 
128
        assert self.capture('unknowns') == ''
109
129
 
110
130
        # 'ignore' works when creating the .bzignore file
111
131
        file('foo.blah', 'wt').write('blah')
112
132
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
113
133
        self.runbzr('ignore *.blah')
114
134
        self.assertEquals(list(b.unknowns()), [])
115
 
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
 
135
        assert file('.bzrignore', 'rU').read() == '*.blah\n'
116
136
 
117
137
        # 'ignore' works when then .bzrignore file already exists
118
138
        file('garh', 'wt').write('garh')
119
139
        self.assertEquals(list(b.unknowns()), ['garh'])
120
 
        assert self.backtick('bzr unknowns') == 'garh\n'
 
140
        assert self.capture('unknowns') == 'garh\n'
121
141
        self.runbzr('ignore garh')
122
142
        self.assertEquals(list(b.unknowns()), [])
123
 
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
 
143
        assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
124
144
 
125
145
    def test_revert(self):
126
146
        self.runbzr('init')
132
152
        file('goodbye', 'wt').write('baz')
133
153
        self.runbzr('add goodbye')
134
154
        self.runbzr('commit -m setup goodbye')
135
 
        
 
155
 
136
156
        file('hello', 'wt').write('bar')
137
157
        file('goodbye', 'wt').write('qux')
138
158
        self.runbzr('revert hello')
147
167
        os.rmdir('revertdir')
148
168
        self.runbzr('revert')
149
169
 
 
170
        os.symlink('/unlikely/to/exist', 'symlink')
 
171
        self.runbzr('add symlink')
 
172
        self.runbzr('commit -m f')
 
173
        os.unlink('symlink')
 
174
        self.runbzr('revert')
 
175
        
 
176
        file('hello', 'wt').write('xyz')
 
177
        self.runbzr('commit -m xyz hello')
 
178
        self.runbzr('revert -r 1 hello')
 
179
        self.check_file_contents('hello', 'foo')
 
180
        self.runbzr('revert hello')
 
181
        self.check_file_contents('hello', 'xyz')
 
182
        os.chdir('revertdir')
 
183
        self.runbzr('revert')
 
184
        os.chdir('..')
 
185
 
 
186
 
150
187
    def test_mv_modes(self):
151
188
        """Test two modes of operation for mv"""
152
189
        from bzrlib.branch import Branch
153
 
        b = Branch('.', init=True)
 
190
        b = Branch.initialize('.')
154
191
        self.build_tree(['a', 'c', 'subdir/'])
155
 
        self.run_bzr('add', self.test_dir)
156
 
        self.run_bzr('mv', 'a', 'b')
157
 
        self.run_bzr('mv', 'b', 'subdir')
158
 
        self.run_bzr('mv', 'subdir/b', 'a')
159
 
        self.run_bzr('mv', 'a', 'c', 'subdir')
160
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
161
 
 
 
192
        self.run_bzr_captured(['add', self.test_dir])
 
193
        self.run_bzr_captured(['mv', 'a', 'b'])
 
194
        self.run_bzr_captured(['mv', 'b', 'subdir'])
 
195
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
 
196
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
 
197
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
162
198
 
163
199
    def test_main_version(self):
164
200
        """Check output from version command and master option is reasonable"""
184
220
        test.runbzr('add goodbye')
185
221
        test.runbzr('commit -m setup goodbye')
186
222
 
187
 
    def test_revert(self):
188
 
        self.example_branch()
189
 
        file('hello', 'wt').write('bar')
190
 
        file('goodbye', 'wt').write('qux')
191
 
        self.runbzr('revert hello')
192
 
        self.check_file_contents('hello', 'foo')
193
 
        self.check_file_contents('goodbye', 'qux')
194
 
        self.runbzr('revert')
195
 
        self.check_file_contents('goodbye', 'baz')
 
223
    def test_export(self):
 
224
        os.mkdir('branch')
 
225
        os.chdir('branch')
 
226
        self.example_branch()
 
227
        self.runbzr('export ../latest')
 
228
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
 
229
        self.runbzr('export ../first -r 1')
 
230
        assert not os.path.exists('../first/goodbye')
 
231
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
 
232
        self.runbzr('export ../first.gz -r 1')
 
233
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
 
234
        self.runbzr('export ../first.bz2 -r 1')
 
235
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
 
236
        self.runbzr('export ../first.tar -r 1')
 
237
        assert os.path.isfile('../first.tar')
 
238
        from tarfile import TarFile
 
239
        tf = TarFile('../first.tar')
 
240
        assert 'first/hello' in tf.getnames(), tf.getnames()
 
241
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
 
242
        self.runbzr('export ../first.tar.gz -r 1')
 
243
        assert os.path.isfile('../first.tar.gz')
 
244
        self.runbzr('export ../first.tbz2 -r 1')
 
245
        assert os.path.isfile('../first.tbz2')
 
246
        self.runbzr('export ../first.tar.bz2 -r 1')
 
247
        assert os.path.isfile('../first.tar.bz2')
 
248
        self.runbzr('export ../first.tar.tbz2 -r 1')
 
249
        assert os.path.isfile('../first.tar.tbz2')
 
250
        from bz2 import BZ2File
 
251
        tf = TarFile('../first.tar.tbz2', 
 
252
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
 
253
        assert 'first.tar/hello' in tf.getnames(), tf.getnames()
 
254
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
 
255
        self.runbzr('export ../first2.tar -r 1 --root pizza')
 
256
        tf = TarFile('../first2.tar')
 
257
        assert 'pizza/hello' in tf.getnames(), tf.getnames()
 
258
 
 
259
    def test_diff(self):
 
260
        self.example_branch()
 
261
        file('hello', 'wt').write('hello world!')
 
262
        self.runbzr('commit -m fixing hello')
 
263
        output = self.runbzr('diff -r 2..3', backtick=1)
 
264
        self.assert_('\n+hello world!' in output)
 
265
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
 
266
        self.assert_('\n+baz' in output)
 
267
 
 
268
    def test_branch(self):
 
269
        """Branch from one branch to another."""
 
270
        os.mkdir('a')
 
271
        os.chdir('a')
 
272
        self.example_branch()
 
273
        os.chdir('..')
 
274
        self.runbzr('branch a b')
 
275
        self.runbzr('branch a c -r 1')
 
276
        os.chdir('b')
 
277
        self.runbzr('commit -m foo --unchanged')
 
278
        os.chdir('..')
 
279
        # naughty - abstraction violations RBC 20050928  
 
280
        print "test_branch used to delete the stores, how is this meant to work ?"
 
281
        #shutil.rmtree('a/.bzr/revision-store')
 
282
        #shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
 
283
        #shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
 
284
        self.runbzr('branch a d --basis b')
196
285
 
197
286
    def test_merge(self):
198
287
        from bzrlib.branch import Branch
214
303
        self.runbzr('merge ../b')
215
304
        self.check_file_contents('goodbye', 'quux')
216
305
        # Merging a branch pulls its revision into the tree
217
 
        a = Branch('.')
218
 
        b = Branch('../b')
219
 
        a.get_revision_xml(b.last_patch())
 
306
        a = Branch.open('.')
 
307
        b = Branch.open('../b')
 
308
        a.get_revision_xml(b.last_revision())
220
309
        self.log('pending merges: %s', a.pending_merges())
221
 
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
 
        #        % (a.pending_merges(), b.last_patch())
 
310
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
 
311
        #        % (a.pending_merges(), b.last_revision())
 
312
 
 
313
    def test_merge_with_missing_file(self):
 
314
        """Merge handles missing file conflicts"""
 
315
        os.mkdir('a')
 
316
        os.chdir('a')
 
317
        os.mkdir('sub')
 
318
        print >> file('sub/a.txt', 'wb'), "hello"
 
319
        print >> file('b.txt', 'wb'), "hello"
 
320
        print >> file('sub/c.txt', 'wb'), "hello"
 
321
        self.runbzr('init')
 
322
        self.runbzr('add')
 
323
        self.runbzr(('commit', '-m', 'added a'))
 
324
        self.runbzr('branch . ../b')
 
325
        print >> file('sub/a.txt', 'ab'), "there"
 
326
        print >> file('b.txt', 'ab'), "there"
 
327
        print >> file('sub/c.txt', 'ab'), "there"
 
328
        self.runbzr(('commit', '-m', 'Added there'))
 
329
        os.unlink('sub/a.txt')
 
330
        os.unlink('sub/c.txt')
 
331
        os.rmdir('sub')
 
332
        os.unlink('b.txt')
 
333
        self.runbzr(('commit', '-m', 'Removed a.txt'))
 
334
        os.chdir('../b')
 
335
        print >> file('sub/a.txt', 'ab'), "something"
 
336
        print >> file('b.txt', 'ab'), "something"
 
337
        print >> file('sub/c.txt', 'ab'), "something"
 
338
        self.runbzr(('commit', '-m', 'Modified a.txt'))
 
339
        self.runbzr('merge ../a/')
 
340
        assert os.path.exists('sub/a.txt.THIS')
 
341
        assert os.path.exists('sub/a.txt.BASE')
 
342
        os.chdir('../a')
 
343
        self.runbzr('merge ../b/')
 
344
        assert os.path.exists('sub/a.txt.OTHER')
 
345
        assert os.path.exists('sub/a.txt.BASE')
223
346
 
224
347
    def test_pull(self):
225
348
        """Pull changes from one branch to another."""
239
362
        self.runbzr('branch a b')
240
363
        os.chdir('b')
241
364
        self.runbzr('pull')
 
365
        os.mkdir('subdir')
 
366
        self.runbzr('add subdir')
242
367
        self.runbzr('commit -m blah --unchanged')
243
368
        os.chdir('../a')
244
 
        a = Branch('.')
245
 
        b = Branch('../b')
 
369
        a = Branch.open('.')
 
370
        b = Branch.open('../b')
246
371
        assert a.revision_history() == b.revision_history()[:-1]
247
372
        self.runbzr('pull ../b')
248
373
        assert a.revision_history() == b.revision_history()
250
375
        os.chdir('../b')
251
376
        self.runbzr('commit -m blah3 --unchanged')
252
377
        self.runbzr('pull ../a', retcode=1)
 
378
        print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
 
379
        return
253
380
        os.chdir('../a')
254
381
        self.runbzr('merge ../b')
255
382
        self.runbzr('commit -m blah4 --unchanged')
256
 
        os.chdir('../b')
 
383
        os.chdir('../b/subdir')
 
384
        self.runbzr('pull ../../a')
 
385
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
386
        self.runbzr('commit -m blah5 --unchanged')
 
387
        self.runbzr('commit -m blah6 --unchanged')
 
388
        os.chdir('..')
257
389
        self.runbzr('pull ../a')
258
 
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
390
        os.chdir('../a')
 
391
        self.runbzr('commit -m blah7 --unchanged')
 
392
        self.runbzr('merge ../b')
 
393
        self.runbzr('commit -m blah8 --unchanged')
 
394
        self.runbzr('pull ../b')
 
395
        self.runbzr('pull ../b')
259
396
        
260
 
 
261
397
    def test_add_reports(self):
262
398
        """add command prints the names of added files."""
263
 
        b = Branch('.', init=True)
 
399
        b = Branch.initialize('.')
264
400
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
265
 
 
266
 
        from cStringIO import StringIO
267
 
        out = StringIO()
268
 
 
269
 
        ret = self.apply_redirected(None, out, None,
270
 
                                    run_bzr,
271
 
                                    ['add'])
272
 
        self.assertEquals(ret, 0)
273
 
 
 
401
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
274
402
        # the ordering is not defined at the moment
275
 
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
 
403
        results = sorted(out.rstrip('\n').split('\n'))
276
404
        self.assertEquals(['added dir',
277
 
                           'added dir/sub.txt',
 
405
                           'added dir'+os.sep+'sub.txt',
278
406
                           'added top.txt',],
279
407
                          results)
280
408
 
 
409
    def test_unknown_command(self):
 
410
        """Handling of unknown command."""
 
411
        out, err = self.run_bzr_captured(['fluffy-badger'],
 
412
                                         retcode=1)
 
413
        self.assertEquals(out, '')
 
414
        err.index('unknown command')
 
415
 
 
416
 
 
417
def listdir_sorted(dir):
 
418
    L = os.listdir(dir)
 
419
    L.sort()
 
420
    return L
 
421
 
281
422
 
282
423
class OldTests(ExternalBase):
283
424
    """old tests moved from ./testbzr."""
287
428
        from os.path import exists
288
429
 
289
430
        runbzr = self.runbzr
290
 
        backtick = self.backtick
 
431
        capture = self.capture
291
432
        progress = self.log
292
433
 
293
434
        progress("basic branch creation")
295
436
        chdir('branch1')
296
437
        runbzr('init')
297
438
 
298
 
        self.assertEquals(backtick('bzr root').rstrip(),
 
439
        self.assertEquals(capture('root').rstrip(),
299
440
                          os.path.join(self.test_dir, 'branch1'))
300
441
 
301
442
        progress("status of new file")
304
445
        f.write('hello world!\n')
305
446
        f.close()
306
447
 
307
 
        out = backtick("bzr unknowns")
308
 
        self.assertEquals(out, 'test.txt\n')
 
448
        self.assertEquals(capture('unknowns'), 'test.txt\n')
309
449
 
310
 
        out = backtick("bzr status")
 
450
        out = capture("status")
311
451
        assert out == 'unknown:\n  test.txt\n'
312
452
 
313
 
        out = backtick("bzr status --all")
 
453
        out = capture("status --all")
314
454
        assert out == "unknown:\n  test.txt\n"
315
455
 
316
 
        out = backtick("bzr status test.txt --all")
 
456
        out = capture("status test.txt --all")
317
457
        assert out == "unknown:\n  test.txt\n"
318
458
 
319
459
        f = file('test2.txt', 'wt')
320
460
        f.write('goodbye cruel world...\n')
321
461
        f.close()
322
462
 
323
 
        out = backtick("bzr status test.txt")
 
463
        out = capture("status test.txt")
324
464
        assert out == "unknown:\n  test.txt\n"
325
465
 
326
 
        out = backtick("bzr status")
 
466
        out = capture("status")
327
467
        assert out == ("unknown:\n"
328
468
                       "  test.txt\n"
329
469
                       "  test2.txt\n")
331
471
        os.unlink('test2.txt')
332
472
 
333
473
        progress("command aliases")
334
 
        out = backtick("bzr st --all")
 
474
        out = capture("st --all")
335
475
        assert out == ("unknown:\n"
336
476
                       "  test.txt\n")
337
477
 
338
 
        out = backtick("bzr stat")
 
478
        out = capture("stat")
339
479
        assert out == ("unknown:\n"
340
480
                       "  test.txt\n")
341
481
 
345
485
        runbzr("help commands")
346
486
        runbzr("help slartibartfast", 1)
347
487
 
348
 
        out = backtick("bzr help ci")
 
488
        out = capture("help ci")
349
489
        out.index('aliases: ')
350
490
 
351
491
        progress("can't rename unversioned file")
354
494
        progress("adding a file")
355
495
 
356
496
        runbzr("add test.txt")
357
 
        assert backtick("bzr unknowns") == ''
358
 
        assert backtick("bzr status --all") == ("added:\n"
 
497
        assert capture("unknowns") == ''
 
498
        assert capture("status --all") == ("added:\n"
359
499
                                                "  test.txt\n")
360
500
 
361
501
        progress("rename newly-added file")
363
503
        assert os.path.exists("hello.txt")
364
504
        assert not os.path.exists("test.txt")
365
505
 
366
 
        assert backtick("bzr revno") == '0\n'
 
506
        assert capture("revno") == '0\n'
367
507
 
368
508
        progress("add first revision")
369
509
        runbzr(['commit', '-m', 'add first revision'])
377
517
        runbzr("add sub1")
378
518
        runbzr("rename sub1 sub2")
379
519
        runbzr("move hello.txt sub2")
380
 
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
520
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
381
521
 
382
522
        assert exists("sub2")
383
523
        assert exists("sub2/hello.txt")
398
538
        runbzr(['commit', '-m', 'rename nested subdirectories'])
399
539
 
400
540
        chdir('sub1/sub2')
401
 
        self.assertEquals(backtick('bzr root')[:-1],
 
541
        self.assertEquals(capture('root')[:-1],
402
542
                          os.path.join(self.test_dir, 'branch1'))
403
543
        runbzr('move ../hello.txt .')
404
544
        assert exists('./hello.txt')
405
 
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
406
 
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
545
        self.assertEquals(capture('relpath hello.txt'),
 
546
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
 
547
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
407
548
        runbzr(['commit', '-m', 'move to parent directory'])
408
549
        chdir('..')
409
 
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
550
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
410
551
 
411
552
        runbzr('move sub2/hello.txt .')
412
553
        assert exists('hello.txt')
421
562
 
422
563
        runbzr('commit -F msg.tmp')
423
564
 
424
 
        assert backtick('bzr revno') == '5\n'
 
565
        assert capture('revno') == '5\n'
425
566
        runbzr('export -r 5 export-5.tmp')
426
567
        runbzr('export export.tmp')
427
568
 
429
570
        runbzr('log -v')
430
571
        runbzr('log -v --forward')
431
572
        runbzr('log -m', retcode=1)
432
 
        log_out = backtick('bzr log -m commit')
 
573
        log_out = capture('log -m commit')
433
574
        assert "this is my new commit" in log_out
434
575
        assert "rename nested" not in log_out
435
576
        assert 'revision-id' not in log_out
436
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
577
        assert 'revision-id' in capture('log --show-ids -m commit')
437
578
 
438
579
 
439
580
        progress("file with spaces in name")
449
590
 
450
591
        runbzr('info')
451
592
 
 
593
        if has_symlinks():
 
594
            progress("symlinks")
 
595
            mkdir('symlinks')
 
596
            chdir('symlinks')
 
597
            runbzr('init')
 
598
            os.symlink("NOWHERE1", "link1")
 
599
            runbzr('add link1')
 
600
            assert self.capture('unknowns') == ''
 
601
            runbzr(['commit', '-m', '1: added symlink link1'])
 
602
    
 
603
            mkdir('d1')
 
604
            runbzr('add d1')
 
605
            assert self.capture('unknowns') == ''
 
606
            os.symlink("NOWHERE2", "d1/link2")
 
607
            assert self.capture('unknowns') == 'd1/link2\n'
 
608
            # is d1/link2 found when adding d1
 
609
            runbzr('add d1')
 
610
            assert self.capture('unknowns') == ''
 
611
            os.symlink("NOWHERE3", "d1/link3")
 
612
            assert self.capture('unknowns') == 'd1/link3\n'
 
613
            runbzr(['commit', '-m', '2: added dir, symlink'])
 
614
    
 
615
            runbzr('rename d1 d2')
 
616
            runbzr('move d2/link2 .')
 
617
            runbzr('move link1 d2')
 
618
            assert os.readlink("./link2") == "NOWHERE2"
 
619
            assert os.readlink("d2/link1") == "NOWHERE1"
 
620
            runbzr('add d2/link3')
 
621
            runbzr('diff')
 
622
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
 
623
    
 
624
            os.unlink("link2")
 
625
            os.symlink("TARGET 2", "link2")
 
626
            os.unlink("d2/link1")
 
627
            os.symlink("TARGET 1", "d2/link1")
 
628
            runbzr('diff')
 
629
            assert self.capture("relpath d2/link1") == "d2/link1\n"
 
630
            runbzr(['commit', '-m', '4: retarget of two links'])
 
631
    
 
632
            runbzr('remove d2/link1')
 
633
            assert self.capture('unknowns') == 'd2/link1\n'
 
634
            runbzr(['commit', '-m', '5: remove d2/link1'])
 
635
    
 
636
            os.mkdir("d1")
 
637
            runbzr('add d1')
 
638
            runbzr('rename d2/link3 d1/link3new')
 
639
            assert self.capture('unknowns') == 'd2/link1\n'
 
640
            runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
 
641
            
 
642
            runbzr(['check'])
 
643
            
 
644
            runbzr(['export', '-r', '1', 'exp1.tmp'])
 
645
            chdir("exp1.tmp")
 
646
            assert listdir_sorted(".") == [ "link1" ]
 
647
            assert os.readlink("link1") == "NOWHERE1"
 
648
            chdir("..")
 
649
            
 
650
            runbzr(['export', '-r', '2', 'exp2.tmp'])
 
651
            chdir("exp2.tmp")
 
652
            assert listdir_sorted(".") == [ "d1", "link1" ]
 
653
            chdir("..")
 
654
            
 
655
            runbzr(['export', '-r', '3', 'exp3.tmp'])
 
656
            chdir("exp3.tmp")
 
657
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
658
            assert listdir_sorted("d2") == [ "link1", "link3" ]
 
659
            assert os.readlink("d2/link1") == "NOWHERE1"
 
660
            assert os.readlink("link2")    == "NOWHERE2"
 
661
            chdir("..")
 
662
            
 
663
            runbzr(['export', '-r', '4', 'exp4.tmp'])
 
664
            chdir("exp4.tmp")
 
665
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
666
            assert os.readlink("d2/link1") == "TARGET 1"
 
667
            assert os.readlink("link2")    == "TARGET 2"
 
668
            assert listdir_sorted("d2") == [ "link1", "link3" ]
 
669
            chdir("..")
 
670
            
 
671
            runbzr(['export', '-r', '5', 'exp5.tmp'])
 
672
            chdir("exp5.tmp")
 
673
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
674
            assert os.path.islink("link2")
 
675
            assert listdir_sorted("d2")== [ "link3" ]
 
676
            chdir("..")
 
677
            
 
678
            runbzr(['export', '-r', '6', 'exp6.tmp'])
 
679
            chdir("exp6.tmp")
 
680
            assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
 
681
            assert listdir_sorted("d1") == [ "link3new" ]
 
682
            assert listdir_sorted("d2") == []
 
683
            assert os.readlink("d1/link3new") == "NOWHERE3"
 
684
            chdir("..")
 
685
        else:
 
686
            progress("skipping symlink tests")
 
687
 
 
688
 
 
689
class HttpTests(TestCaseWithWebserver):
 
690
    """Test bzr ui commands against remote branches."""
 
691
 
 
692
    def test_branch(self):
 
693
        os.mkdir('from')
 
694
        branch = Branch.initialize('from')
 
695
        branch.commit('empty commit for nonsense', allow_pointless=True)
 
696
        url = self.get_remote_url('from')
 
697
        self.run_bzr('branch', url, 'to')
 
698
        branch = Branch.open('to')
 
699
        self.assertEqual(1, len(branch.revision_history()))