~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

[path] bgu in help_on_command (Robert Widhopf-Frank)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr.
 
20
 
 
21
These check that it behaves properly when it's invoked through the regular
 
22
command-line interface. This doesn't actually run a new interpreter but 
 
23
rather starts again from the run_bzr function.
 
24
"""
 
25
 
 
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
from cStringIO import StringIO
 
33
import os
 
34
import re
 
35
import shutil
 
36
import sys
 
37
 
 
38
from bzrlib.branch import Branch
 
39
from bzrlib.clone import copy_branch
 
40
from bzrlib.errors import BzrCommandError
 
41
from bzrlib.osutils import has_symlinks
 
42
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
43
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
 
44
 
 
45
 
 
46
class ExternalBase(TestCaseInTempDir):
 
47
 
 
48
    def runbzr(self, args, retcode=0, backtick=False):
 
49
        if isinstance(args, basestring):
 
50
            args = args.split()
 
51
 
 
52
        if backtick:
 
53
            return self.run_bzr_captured(args, retcode=retcode)[0]
 
54
        else:
 
55
            return self.run_bzr_captured(args, retcode=retcode)
 
56
 
 
57
 
 
58
class TestCommands(ExternalBase):
 
59
 
 
60
    def test_help_commands(self):
 
61
        self.runbzr('--help')
 
62
        self.runbzr('help')
 
63
        self.runbzr('help commands')
 
64
        self.runbzr('help help')
 
65
        self.runbzr('commit -h')
 
66
 
 
67
    def test_init_branch(self):
 
68
        self.runbzr(['init'])
 
69
 
 
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=2)
 
76
        
 
77
        os.mkdir('subdir2')
 
78
        self.runbzr('init subdir2')
 
79
        self.runbzr('init subdir2', retcode=1)
 
80
 
 
81
        self.runbzr('init subdir2/subsubdir1')
 
82
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
 
83
 
 
84
    def test_whoami(self):
 
85
        # this should always identify something, if only "john@localhost"
 
86
        self.runbzr("whoami")
 
87
        self.runbzr("whoami --email")
 
88
 
 
89
        self.assertEquals(self.runbzr("whoami --email",
 
90
                                      backtick=True).count('@'), 1)
 
91
        
 
92
    def test_whoami_branch(self):
 
93
        """branch specific user identity works."""
 
94
        self.runbzr('init')
 
95
        f = file('.bzr/email', 'wt')
 
96
        f.write('Branch Identity <branch@identi.ty>')
 
97
        f.close()
 
98
        bzr_email = os.environ.get('BZREMAIL')
 
99
        if bzr_email is not None:
 
100
            del os.environ['BZREMAIL']
 
101
        whoami = self.runbzr("whoami",backtick=True)
 
102
        whoami_email = self.runbzr("whoami --email",backtick=True)
 
103
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
 
104
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
 
105
        # Verify that the environment variable overrides the value 
 
106
        # in the file
 
107
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
 
108
        whoami = self.runbzr("whoami",backtick=True)
 
109
        whoami_email = self.runbzr("whoami --email",backtick=True)
 
110
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
 
111
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
 
112
        if bzr_email is not None:
 
113
            os.environ['BZREMAIL'] = bzr_email
 
114
 
 
115
    def test_invalid_commands(self):
 
116
        self.runbzr("pants", retcode=1)
 
117
        self.runbzr("--pants off", retcode=1)
 
118
        self.runbzr("diff --message foo", retcode=1)
 
119
 
 
120
    def test_empty_commit(self):
 
121
        self.runbzr("init")
 
122
        self.build_tree(['hello.txt'])
 
123
        self.runbzr("commit -m empty", retcode=1)
 
124
        self.runbzr("add hello.txt")
 
125
        self.runbzr("commit -m added")       
 
126
 
 
127
    def test_empty_commit_message(self):
 
128
        self.runbzr("init")
 
129
        file('foo.c', 'wt').write('int main() {}')
 
130
        self.runbzr(['add', 'foo.c'])
 
131
        self.runbzr(["commit", "-m", ""] , retcode=1) 
 
132
 
 
133
    def test_other_branch_commit(self):
 
134
        # this branch is to ensure consistent behaviour, whether we're run
 
135
        # inside a branch, or not.
 
136
        os.mkdir('empty_branch')
 
137
        os.chdir('empty_branch')
 
138
        self.runbzr('init')
 
139
        os.mkdir('branch')
 
140
        os.chdir('branch')
 
141
        self.runbzr('init')
 
142
        file('foo.c', 'wt').write('int main() {}')
 
143
        file('bar.c', 'wt').write('int main() {}')
 
144
        os.chdir('..')
 
145
        self.runbzr(['add', 'branch/foo.c'])
 
146
        self.runbzr(['add', 'branch'])
 
147
        # can't commit files in different trees; sane error
 
148
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
 
149
        self.runbzr('commit -m newstuff branch/foo.c')
 
150
        self.runbzr('commit -m newstuff branch')
 
151
        self.runbzr('commit -m newstuff branch', retcode=1)
 
152
 
 
153
 
 
154
    def test_ignore_patterns(self):
 
155
        from bzrlib.branch import Branch
 
156
        
 
157
        b = Branch.initialize('.')
 
158
        self.assertEquals(list(b.unknowns()), [])
 
159
 
 
160
        file('foo.tmp', 'wt').write('tmp files are ignored')
 
161
        self.assertEquals(list(b.unknowns()), [])
 
162
        self.assertEquals(self.capture('unknowns'), '')
 
163
 
 
164
        file('foo.c', 'wt').write('int main() {}')
 
165
        self.assertEquals(list(b.unknowns()), ['foo.c'])
 
166
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
 
167
 
 
168
        self.runbzr(['add', 'foo.c'])
 
169
        self.assertEquals(self.capture('unknowns'), '')
 
170
 
 
171
        # 'ignore' works when creating the .bzignore file
 
172
        file('foo.blah', 'wt').write('blah')
 
173
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
 
174
        self.runbzr('ignore *.blah')
 
175
        self.assertEquals(list(b.unknowns()), [])
 
176
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
 
177
 
 
178
        # 'ignore' works when then .bzrignore file already exists
 
179
        file('garh', 'wt').write('garh')
 
180
        self.assertEquals(list(b.unknowns()), ['garh'])
 
181
        self.assertEquals(self.capture('unknowns'), 'garh\n')
 
182
        self.runbzr('ignore garh')
 
183
        self.assertEquals(list(b.unknowns()), [])
 
184
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
 
185
 
 
186
    def test_revert(self):
 
187
        self.runbzr('init')
 
188
 
 
189
        file('hello', 'wt').write('foo')
 
190
        self.runbzr('add hello')
 
191
        self.runbzr('commit -m setup hello')
 
192
 
 
193
        file('goodbye', 'wt').write('baz')
 
194
        self.runbzr('add goodbye')
 
195
        self.runbzr('commit -m setup goodbye')
 
196
 
 
197
        file('hello', 'wt').write('bar')
 
198
        file('goodbye', 'wt').write('qux')
 
199
        self.runbzr('revert hello')
 
200
        self.check_file_contents('hello', 'foo')
 
201
        self.check_file_contents('goodbye', 'qux')
 
202
        self.runbzr('revert')
 
203
        self.check_file_contents('goodbye', 'baz')
 
204
 
 
205
        os.mkdir('revertdir')
 
206
        self.runbzr('add revertdir')
 
207
        self.runbzr('commit -m f')
 
208
        os.rmdir('revertdir')
 
209
        self.runbzr('revert')
 
210
 
 
211
        os.symlink('/unlikely/to/exist', 'symlink')
 
212
        self.runbzr('add symlink')
 
213
        self.runbzr('commit -m f')
 
214
        os.unlink('symlink')
 
215
        self.runbzr('revert')
 
216
        self.failUnlessExists('symlink')
 
217
        os.unlink('symlink')
 
218
        os.symlink('a-different-path', 'symlink')
 
219
        self.runbzr('revert')
 
220
        self.assertEqual('/unlikely/to/exist',
 
221
                         os.readlink('symlink'))
 
222
        
 
223
        file('hello', 'wt').write('xyz')
 
224
        self.runbzr('commit -m xyz hello')
 
225
        self.runbzr('revert -r 1 hello')
 
226
        self.check_file_contents('hello', 'foo')
 
227
        self.runbzr('revert hello')
 
228
        self.check_file_contents('hello', 'xyz')
 
229
        os.chdir('revertdir')
 
230
        self.runbzr('revert')
 
231
        os.chdir('..')
 
232
 
 
233
    def test_status(self):
 
234
        self.runbzr("init")
 
235
        self.build_tree(['hello.txt'])
 
236
        result = self.runbzr("status")
 
237
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
238
        self.runbzr("add hello.txt")
 
239
        result = self.runbzr("status")
 
240
        self.assert_("added:\n  hello.txt\n" in result, result)
 
241
        self.runbzr("commit -m added")
 
242
        result = self.runbzr("status -r 0..1")
 
243
        self.assert_("added:\n  hello.txt\n" in result, result)
 
244
        self.build_tree(['world.txt'])
 
245
        result = self.runbzr("status -r 0")
 
246
        self.assert_("added:\n  hello.txt\n" \
 
247
                     "unknown:\n  world.txt\n" in result, result)
 
248
 
 
249
    def test_mv_modes(self):
 
250
        """Test two modes of operation for mv"""
 
251
        from bzrlib.branch import Branch
 
252
        b = Branch.initialize('.')
 
253
        self.build_tree(['a', 'c', 'subdir/'])
 
254
        self.run_bzr_captured(['add', self.test_dir])
 
255
        self.run_bzr_captured(['mv', 'a', 'b'])
 
256
        self.run_bzr_captured(['mv', 'b', 'subdir'])
 
257
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
 
258
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
 
259
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
 
260
 
 
261
    def test_main_version(self):
 
262
        """Check output from version command and master option is reasonable"""
 
263
        # output is intentionally passed through to stdout so that we
 
264
        # can see the version being tested
 
265
        output = self.runbzr('version', backtick=1)
 
266
        self.log('bzr version output:')
 
267
        self.log(output)
 
268
        self.assert_(output.startswith('bzr (bazaar-ng) '))
 
269
        self.assertNotEqual(output.index('Canonical'), -1)
 
270
        # make sure --version is consistent
 
271
        tmp_output = self.runbzr('--version', backtick=1)
 
272
        self.log('bzr --version output:')
 
273
        self.log(tmp_output)
 
274
        self.assertEquals(output, tmp_output)
 
275
 
 
276
    def example_branch(test):
 
277
        test.runbzr('init')
 
278
        file('hello', 'wt').write('foo')
 
279
        test.runbzr('add hello')
 
280
        test.runbzr('commit -m setup hello')
 
281
        file('goodbye', 'wt').write('baz')
 
282
        test.runbzr('add goodbye')
 
283
        test.runbzr('commit -m setup goodbye')
 
284
 
 
285
    def test_export(self):
 
286
        os.mkdir('branch')
 
287
        os.chdir('branch')
 
288
        self.example_branch()
 
289
        self.runbzr('export ../latest')
 
290
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
 
291
        self.runbzr('export ../first -r 1')
 
292
        self.assert_(not os.path.exists('../first/goodbye'))
 
293
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
 
294
        self.runbzr('export ../first.gz -r 1')
 
295
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
 
296
        self.runbzr('export ../first.bz2 -r 1')
 
297
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
 
298
        self.runbzr('export ../first.tar -r 1')
 
299
        self.assert_(os.path.isfile('../first.tar'))
 
300
        from tarfile import TarFile
 
301
        tf = TarFile('../first.tar')
 
302
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
 
303
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
 
304
        self.runbzr('export ../first.tar.gz -r 1')
 
305
        self.assert_(os.path.isfile('../first.tar.gz'))
 
306
        self.runbzr('export ../first.tbz2 -r 1')
 
307
        self.assert_(os.path.isfile('../first.tbz2'))
 
308
        self.runbzr('export ../first.tar.bz2 -r 1')
 
309
        self.assert_(os.path.isfile('../first.tar.bz2'))
 
310
        self.runbzr('export ../first.tar.tbz2 -r 1')
 
311
        self.assert_(os.path.isfile('../first.tar.tbz2'))
 
312
        from bz2 import BZ2File
 
313
        tf = TarFile('../first.tar.tbz2', 
 
314
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
 
315
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
 
316
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
 
317
        self.runbzr('export ../first2.tar -r 1 --root pizza')
 
318
        tf = TarFile('../first2.tar')
 
319
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
 
320
 
 
321
    def test_diff(self):
 
322
        self.example_branch()
 
323
        file('hello', 'wt').write('hello world!')
 
324
        self.runbzr('commit -m fixing hello')
 
325
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
 
326
        self.assert_('\n+hello world!' in output)
 
327
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
 
328
        self.assert_('\n+baz' in output)
 
329
 
 
330
    def test_diff_branches(self):
 
331
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
 
332
        branch = Branch.initialize('branch1')
 
333
        branch.add(['file'])
 
334
        branch.commit('add file')
 
335
        copy_branch(branch, 'branch2')
 
336
        print >> open('branch2/file', 'w'), 'new content'
 
337
        branch2 = Branch.open('branch2')
 
338
        branch2.commit('update file')
 
339
        # should open branch1 and diff against branch2, 
 
340
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
341
                                        'branch1'],
 
342
                                       retcode=1)
 
343
        self.assertEquals(("=== modified file 'file'\n"
 
344
                           "--- file\n"
 
345
                           "+++ file\n"
 
346
                           "@@ -1,1 +1,1 @@\n"
 
347
                           "-new content\n"
 
348
                           "+contents of branch1/file\n"
 
349
                           "\n", ''), output)
 
350
 
 
351
    def test_branch(self):
 
352
        """Branch from one branch to another."""
 
353
        os.mkdir('a')
 
354
        os.chdir('a')
 
355
        self.example_branch()
 
356
        os.chdir('..')
 
357
        self.runbzr('branch a b')
 
358
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
 
359
        self.runbzr('branch a c -r 1')
 
360
        os.chdir('b')
 
361
        self.runbzr('commit -m foo --unchanged')
 
362
        os.chdir('..')
 
363
        # naughty - abstraction violations RBC 20050928  
 
364
        print "test_branch used to delete the stores, how is this meant to work ?"
 
365
        #shutil.rmtree('a/.bzr/revision-store')
 
366
        #shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
 
367
        #shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
 
368
        self.runbzr('branch a d --basis b')
 
369
 
 
370
    def test_merge(self):
 
371
        from bzrlib.branch import Branch
 
372
        
 
373
        os.mkdir('a')
 
374
        os.chdir('a')
 
375
        self.example_branch()
 
376
        os.chdir('..')
 
377
        self.runbzr('branch a b')
 
378
        os.chdir('b')
 
379
        file('goodbye', 'wt').write('quux')
 
380
        self.runbzr(['commit',  '-m',  "more u's are always good"])
 
381
 
 
382
        os.chdir('../a')
 
383
        file('hello', 'wt').write('quuux')
 
384
        # We can't merge when there are in-tree changes
 
385
        self.runbzr('merge ../b', retcode=1)
 
386
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
 
387
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
 
388
                    retcode=1)
 
389
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
 
390
        self.runbzr('revert --no-backup')
 
391
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
 
392
        self.runbzr('revert --no-backup')
 
393
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
 
394
        self.runbzr('revert --no-backup')
 
395
        self.runbzr('merge ../b -r last:1')
 
396
        self.check_file_contents('goodbye', 'quux')
 
397
        # Merging a branch pulls its revision into the tree
 
398
        a = Branch.open('.')
 
399
        b = Branch.open('../b')
 
400
        a.get_revision_xml(b.last_revision())
 
401
        self.log('pending merges: %s', a.pending_merges())
 
402
        self.assertEquals(a.pending_merges(), [b.last_revision()])
 
403
        self.runbzr('commit -m merged')
 
404
        self.runbzr('merge ../b -r last:1')
 
405
        self.assertEqual(Branch.open('.').pending_merges(), [])
 
406
 
 
407
 
 
408
    def test_merge_with_missing_file(self):
 
409
        """Merge handles missing file conflicts"""
 
410
        os.mkdir('a')
 
411
        os.chdir('a')
 
412
        os.mkdir('sub')
 
413
        print >> file('sub/a.txt', 'wb'), "hello"
 
414
        print >> file('b.txt', 'wb'), "hello"
 
415
        print >> file('sub/c.txt', 'wb'), "hello"
 
416
        self.runbzr('init')
 
417
        self.runbzr('add')
 
418
        self.runbzr(('commit', '-m', 'added a'))
 
419
        self.runbzr('branch . ../b')
 
420
        print >> file('sub/a.txt', 'ab'), "there"
 
421
        print >> file('b.txt', 'ab'), "there"
 
422
        print >> file('sub/c.txt', 'ab'), "there"
 
423
        self.runbzr(('commit', '-m', 'Added there'))
 
424
        os.unlink('sub/a.txt')
 
425
        os.unlink('sub/c.txt')
 
426
        os.rmdir('sub')
 
427
        os.unlink('b.txt')
 
428
        self.runbzr(('commit', '-m', 'Removed a.txt'))
 
429
        os.chdir('../b')
 
430
        print >> file('sub/a.txt', 'ab'), "something"
 
431
        print >> file('b.txt', 'ab'), "something"
 
432
        print >> file('sub/c.txt', 'ab'), "something"
 
433
        self.runbzr(('commit', '-m', 'Modified a.txt'))
 
434
        self.runbzr('merge ../a/', retcode=1)
 
435
        self.assert_(os.path.exists('sub/a.txt.THIS'))
 
436
        self.assert_(os.path.exists('sub/a.txt.BASE'))
 
437
        os.chdir('../a')
 
438
        self.runbzr('merge ../b/', retcode=1)
 
439
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
 
440
        self.assert_(os.path.exists('sub/a.txt.BASE'))
 
441
 
 
442
    def test_pull(self):
 
443
        """Pull changes from one branch to another."""
 
444
        os.mkdir('a')
 
445
        os.chdir('a')
 
446
 
 
447
        self.example_branch()
 
448
        self.runbzr('pull', retcode=1)
 
449
        self.runbzr('missing', retcode=1)
 
450
        self.runbzr('missing .')
 
451
        self.runbzr('missing')
 
452
        self.runbzr('pull')
 
453
        self.runbzr('pull /', retcode=1)
 
454
        self.runbzr('pull')
 
455
 
 
456
        os.chdir('..')
 
457
        self.runbzr('branch a b')
 
458
        os.chdir('b')
 
459
        self.runbzr('pull')
 
460
        os.mkdir('subdir')
 
461
        self.runbzr('add subdir')
 
462
        self.runbzr('commit -m blah --unchanged')
 
463
        os.chdir('../a')
 
464
        a = Branch.open('.')
 
465
        b = Branch.open('../b')
 
466
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
 
467
        self.runbzr('pull ../b')
 
468
        self.assertEquals(a.revision_history(), b.revision_history())
 
469
        self.runbzr('commit -m blah2 --unchanged')
 
470
        os.chdir('../b')
 
471
        self.runbzr('commit -m blah3 --unchanged')
 
472
        # no overwrite
 
473
        self.runbzr('pull ../a', retcode=1)
 
474
        os.chdir('..')
 
475
        self.runbzr('branch b overwriteme')
 
476
        os.chdir('overwriteme')
 
477
        self.runbzr('pull --overwrite ../a')
 
478
        overwritten = Branch.open('.')
 
479
        self.assertEqual(overwritten.revision_history(),
 
480
                         a.revision_history())
 
481
        os.chdir('../a')
 
482
        self.runbzr('merge ../b')
 
483
        self.runbzr('commit -m blah4 --unchanged')
 
484
        os.chdir('../b/subdir')
 
485
        self.runbzr('pull ../../a')
 
486
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
 
487
        self.runbzr('commit -m blah5 --unchanged')
 
488
        self.runbzr('commit -m blah6 --unchanged')
 
489
        os.chdir('..')
 
490
        self.runbzr('pull ../a')
 
491
        os.chdir('../a')
 
492
        self.runbzr('commit -m blah7 --unchanged')
 
493
        self.runbzr('merge ../b')
 
494
        self.runbzr('commit -m blah8 --unchanged')
 
495
        self.runbzr('pull ../b')
 
496
        self.runbzr('pull ../b')
 
497
 
 
498
    def test_ls(self):
 
499
        """Test the abilities of 'bzr ls'"""
 
500
        bzr = self.runbzr
 
501
        def bzrout(*args, **kwargs):
 
502
            kwargs['backtick'] = True
 
503
            return self.runbzr(*args, **kwargs)
 
504
 
 
505
        def ls_equals(value, *args):
 
506
            out = self.runbzr(['ls'] + list(args), backtick=True)
 
507
            self.assertEquals(out, value)
 
508
 
 
509
        bzr('init')
 
510
        open('a', 'wb').write('hello\n')
 
511
 
 
512
        # Can't supply both
 
513
        bzr('ls --verbose --null', retcode=1)
 
514
 
 
515
        ls_equals('a\n')
 
516
        ls_equals('?        a\n', '--verbose')
 
517
        ls_equals('a\n', '--unknown')
 
518
        ls_equals('', '--ignored')
 
519
        ls_equals('', '--versioned')
 
520
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
 
521
        ls_equals('', '--ignored', '--versioned')
 
522
        ls_equals('a\0', '--null')
 
523
 
 
524
        bzr('add a')
 
525
        ls_equals('V        a\n', '--verbose')
 
526
        bzr('commit -m add')
 
527
        
 
528
        os.mkdir('subdir')
 
529
        ls_equals('V        a\n'
 
530
                  '?        subdir/\n'
 
531
                  , '--verbose')
 
532
        open('subdir/b', 'wb').write('b\n')
 
533
        bzr('add')
 
534
        ls_equals('V        a\n'
 
535
                  'V        subdir/\n'
 
536
                  'V        subdir/b\n'
 
537
                  , '--verbose')
 
538
        bzr('commit -m subdir')
 
539
 
 
540
        ls_equals('a\n'
 
541
                  'subdir\n'
 
542
                  , '--non-recursive')
 
543
 
 
544
        ls_equals('V        a\n'
 
545
                  'V        subdir/\n'
 
546
                  , '--verbose', '--non-recursive')
 
547
 
 
548
        # Check what happens in a sub-directory
 
549
        os.chdir('subdir')
 
550
        ls_equals('b\n')
 
551
        ls_equals('b\0'
 
552
                  , '--null')
 
553
        ls_equals('a\n'
 
554
                  'subdir\n'
 
555
                  'subdir/b\n'
 
556
                  , '--from-root')
 
557
        ls_equals('a\0'
 
558
                  'subdir\0'
 
559
                  'subdir/b\0'
 
560
                  , '--from-root', '--null')
 
561
        ls_equals('a\n'
 
562
                  'subdir\n'
 
563
                  , '--from-root', '--non-recursive')
 
564
 
 
565
        os.chdir('..')
 
566
 
 
567
        # Check what happens when we supply a specific revision
 
568
        ls_equals('a\n', '--revision', '1')
 
569
        ls_equals('V        a\n'
 
570
                  , '--verbose', '--revision', '1')
 
571
 
 
572
        os.chdir('subdir')
 
573
        ls_equals('', '--revision', '1')
 
574
 
 
575
        # Now try to do ignored files.
 
576
        os.chdir('..')
 
577
        open('blah.py', 'wb').write('unknown\n')
 
578
        open('blah.pyo', 'wb').write('ignored\n')
 
579
        ls_equals('a\n'
 
580
                  'blah.py\n'
 
581
                  'blah.pyo\n'
 
582
                  'subdir\n'
 
583
                  'subdir/b\n')
 
584
        ls_equals('V        a\n'
 
585
                  '?        blah.py\n'
 
586
                  'I        blah.pyo\n'
 
587
                  'V        subdir/\n'
 
588
                  'V        subdir/b\n'
 
589
                  , '--verbose')
 
590
        ls_equals('blah.pyo\n'
 
591
                  , '--ignored')
 
592
        ls_equals('blah.py\n'
 
593
                  , '--unknown')
 
594
        ls_equals('a\n'
 
595
                  'subdir\n'
 
596
                  'subdir/b\n'
 
597
                  , '--versioned')
 
598
 
 
599
 
 
600
    def test_locations(self):
 
601
        """Using and remembering different locations"""
 
602
        os.mkdir('a')
 
603
        os.chdir('a')
 
604
        self.runbzr('init')
 
605
        self.runbzr('commit -m unchanged --unchanged')
 
606
        self.runbzr('pull', retcode=1)
 
607
        self.runbzr('merge', retcode=1)
 
608
        self.runbzr('branch . ../b')
 
609
        os.chdir('../b')
 
610
        self.runbzr('pull')
 
611
        self.runbzr('branch . ../c')
 
612
        self.runbzr('pull ../c')
 
613
        self.runbzr('merge')
 
614
        os.chdir('../a')
 
615
        self.runbzr('pull ../b')
 
616
        self.runbzr('pull')
 
617
        self.runbzr('pull ../c')
 
618
        self.runbzr('branch ../c ../d')
 
619
        shutil.rmtree('../c')
 
620
        self.runbzr('pull')
 
621
        os.chdir('../b')
 
622
        self.runbzr('pull')
 
623
        os.chdir('../d')
 
624
        self.runbzr('pull', retcode=1)
 
625
        self.runbzr('pull ../a --remember')
 
626
        self.runbzr('pull')
 
627
        
 
628
    def test_add_reports(self):
 
629
        """add command prints the names of added files."""
 
630
        b = Branch.initialize('.')
 
631
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
632
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
 
633
        # the ordering is not defined at the moment
 
634
        results = sorted(out.rstrip('\n').split('\n'))
 
635
        self.assertEquals(['added dir',
 
636
                           'added dir'+os.sep+'sub.txt',
 
637
                           'added top.txt',],
 
638
                          results)
 
639
 
 
640
    def test_add_quiet_is(self):
 
641
        """add -q does not print the names of added files."""
 
642
        b = Branch.initialize('.')
 
643
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
644
        out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
 
645
        # the ordering is not defined at the moment
 
646
        results = sorted(out.rstrip('\n').split('\n'))
 
647
        self.assertEquals([''], results)
 
648
 
 
649
    def test_unknown_command(self):
 
650
        """Handling of unknown command."""
 
651
        out, err = self.run_bzr_captured(['fluffy-badger'],
 
652
                                         retcode=1)
 
653
        self.assertEquals(out, '')
 
654
        err.index('unknown command')
 
655
 
 
656
    def test_conflicts(self):
 
657
        """Handling of merge conflicts"""
 
658
        os.mkdir('base')
 
659
        os.chdir('base')
 
660
        file('hello', 'wb').write("hi world")
 
661
        file('answer', 'wb').write("42")
 
662
        self.runbzr('init')
 
663
        self.runbzr('add')
 
664
        self.runbzr('commit -m base')
 
665
        self.runbzr('branch . ../other')
 
666
        self.runbzr('branch . ../this')
 
667
        os.chdir('../other')
 
668
        file('hello', 'wb').write("Hello.")
 
669
        file('answer', 'wb').write("Is anyone there?")
 
670
        self.runbzr('commit -m other')
 
671
        os.chdir('../this')
 
672
        file('hello', 'wb').write("Hello, world")
 
673
        self.runbzr('mv answer question')
 
674
        file('question', 'wb').write("What do you get when you multiply six"
 
675
                                   "times nine?")
 
676
        self.runbzr('commit -m this')
 
677
        self.runbzr('merge ../other --show-base', retcode=1)
 
678
        conflict_text = file('hello').read()
 
679
        self.assert_('<<<<<<<' in conflict_text)
 
680
        self.assert_('>>>>>>>' in conflict_text)
 
681
        self.assert_('=======' in conflict_text)
 
682
        self.assert_('|||||||' in conflict_text)
 
683
        self.assert_('hi world' in conflict_text)
 
684
        self.runbzr('revert')
 
685
        self.runbzr('resolve --all')
 
686
        self.runbzr('merge ../other', retcode=1)
 
687
        conflict_text = file('hello').read()
 
688
        self.assert_('|||||||' not in conflict_text)
 
689
        self.assert_('hi world' not in conflict_text)
 
690
        result = self.runbzr('conflicts', backtick=1)
 
691
        self.assertEquals(result, "hello\nquestion\n")
 
692
        result = self.runbzr('status', backtick=1)
 
693
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
 
694
        self.runbzr('resolve hello')
 
695
        result = self.runbzr('conflicts', backtick=1)
 
696
        self.assertEquals(result, "question\n")
 
697
        self.runbzr('commit -m conflicts', retcode=1)
 
698
        self.runbzr('resolve --all')
 
699
        result = self.runbzr('conflicts', backtick=1)
 
700
        self.runbzr('commit -m conflicts')
 
701
        self.assertEquals(result, "")
 
702
 
 
703
    def test_resign(self):
 
704
        """Test re signing of data."""
 
705
        import bzrlib.gpg
 
706
        oldstrategy = bzrlib.gpg.GPGStrategy
 
707
        branch = Branch.initialize('.')
 
708
        branch.commit("base", allow_pointless=True, rev_id='A')
 
709
        try:
 
710
            # monkey patch gpg signing mechanism
 
711
            from bzrlib.testament import Testament
 
712
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
713
            self.runbzr('re-sign -r revid:A')
 
714
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
 
715
                             branch.revision_store.get('A', 'sig').read())
 
716
        finally:
 
717
            bzrlib.gpg.GPGStrategy = oldstrategy
 
718
            
 
719
    def test_resign_range(self):
 
720
        import bzrlib.gpg
 
721
        oldstrategy = bzrlib.gpg.GPGStrategy
 
722
        branch = Branch.initialize('.')
 
723
        branch.commit("base", allow_pointless=True, rev_id='A')
 
724
        branch.commit("base", allow_pointless=True, rev_id='B')
 
725
        branch.commit("base", allow_pointless=True, rev_id='C')
 
726
        try:
 
727
            # monkey patch gpg signing mechanism
 
728
            from bzrlib.testament import Testament
 
729
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
730
            self.runbzr('re-sign -r 1..')
 
731
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
 
732
                             branch.revision_store.get('A', 'sig').read())
 
733
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
 
734
                             branch.revision_store.get('B', 'sig').read())
 
735
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
 
736
                             branch.revision_store.get('C', 'sig').read())
 
737
        finally:
 
738
            bzrlib.gpg.GPGStrategy = oldstrategy
 
739
 
 
740
    def test_push(self):
 
741
        # create a source branch
 
742
        os.mkdir('my-branch')
 
743
        os.chdir('my-branch')
 
744
        self.example_branch()
 
745
 
 
746
        # with no push target, fail
 
747
        self.runbzr('push', retcode=1)
 
748
        # with an explicit target work
 
749
        self.runbzr('push ../output-branch')
 
750
        # with an implicit target work
 
751
        self.runbzr('push')
 
752
        # nothing missing
 
753
        self.runbzr('missing ../output-branch')
 
754
        # advance this branch
 
755
        self.runbzr('commit --unchanged -m unchanged')
 
756
 
 
757
        os.chdir('../output-branch')
 
758
        # should be a diff as we have not pushed the tree
 
759
        self.runbzr('diff', retcode=1)
 
760
        self.runbzr('revert')
 
761
        # but not now.
 
762
        self.runbzr('diff')
 
763
        # diverge the branches
 
764
        self.runbzr('commit --unchanged -m unchanged')
 
765
        os.chdir('../my-branch')
 
766
        # cannot push now
 
767
        self.runbzr('push', retcode=1)
 
768
        # and there are difference
 
769
        self.runbzr('missing ../output-branch', retcode=1)
 
770
        # but we can force a push
 
771
        self.runbzr('push --overwrite')
 
772
        # nothing missing
 
773
        self.runbzr('missing ../output-branch')
 
774
        
 
775
        # pushing to a new dir with no parent should fail
 
776
        self.runbzr('push ../missing/new-branch', retcode=1)
 
777
        # unless we provide --create-prefix
 
778
        self.runbzr('push --create-prefix ../missing/new-branch')
 
779
        # nothing missing
 
780
        self.runbzr('missing ../missing/new-branch')
 
781
 
 
782
 
 
783
def listdir_sorted(dir):
 
784
    L = os.listdir(dir)
 
785
    L.sort()
 
786
    return L
 
787
 
 
788
 
 
789
class OldTests(ExternalBase):
 
790
    """old tests moved from ./testbzr."""
 
791
 
 
792
    def test_bzr(self):
 
793
        from os import chdir, mkdir
 
794
        from os.path import exists
 
795
 
 
796
        runbzr = self.runbzr
 
797
        capture = self.capture
 
798
        progress = self.log
 
799
 
 
800
        progress("basic branch creation")
 
801
        mkdir('branch1')
 
802
        chdir('branch1')
 
803
        runbzr('init')
 
804
 
 
805
        self.assertEquals(capture('root').rstrip(),
 
806
                          os.path.join(self.test_dir, 'branch1'))
 
807
 
 
808
        progress("status of new file")
 
809
 
 
810
        f = file('test.txt', 'wt')
 
811
        f.write('hello world!\n')
 
812
        f.close()
 
813
 
 
814
        self.assertEquals(capture('unknowns'), 'test.txt\n')
 
815
 
 
816
        out = capture("status")
 
817
        self.assertEquals(out, 'unknown:\n  test.txt\n')
 
818
 
 
819
        out = capture("status --all")
 
820
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
821
 
 
822
        out = capture("status test.txt --all")
 
823
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
824
 
 
825
        f = file('test2.txt', 'wt')
 
826
        f.write('goodbye cruel world...\n')
 
827
        f.close()
 
828
 
 
829
        out = capture("status test.txt")
 
830
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
831
 
 
832
        out = capture("status")
 
833
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
 
834
 
 
835
        os.unlink('test2.txt')
 
836
 
 
837
        progress("command aliases")
 
838
        out = capture("st --all")
 
839
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
840
 
 
841
        out = capture("stat")
 
842
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
843
 
 
844
        progress("command help")
 
845
        runbzr("help st")
 
846
        runbzr("help")
 
847
        runbzr("help commands")
 
848
        runbzr("help slartibartfast", 1)
 
849
 
 
850
        out = capture("help ci")
 
851
        out.index('aliases: ')
 
852
 
 
853
        progress("can't rename unversioned file")
 
854
        runbzr("rename test.txt new-test.txt", 1)
 
855
 
 
856
        progress("adding a file")
 
857
 
 
858
        runbzr("add test.txt")
 
859
        self.assertEquals(capture("unknowns"), '')
 
860
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
 
861
 
 
862
        progress("rename newly-added file")
 
863
        runbzr("rename test.txt hello.txt")
 
864
        self.assert_(os.path.exists("hello.txt"))
 
865
        self.assert_(not os.path.exists("test.txt"))
 
866
 
 
867
        self.assertEquals(capture("revno"), '0\n')
 
868
 
 
869
        progress("add first revision")
 
870
        runbzr(['commit', '-m', 'add first revision'])
 
871
 
 
872
        progress("more complex renames")
 
873
        os.mkdir("sub1")
 
874
        runbzr("rename hello.txt sub1", 1)
 
875
        runbzr("rename hello.txt sub1/hello.txt", 1)
 
876
        runbzr("move hello.txt sub1", 1)
 
877
 
 
878
        runbzr("add sub1")
 
879
        runbzr("rename sub1 sub2")
 
880
        runbzr("move hello.txt sub2")
 
881
        self.assertEqual(capture("relpath sub2/hello.txt"),
 
882
                         os.path.join("sub2", "hello.txt\n"))
 
883
 
 
884
        self.assert_(exists("sub2"))
 
885
        self.assert_(exists("sub2/hello.txt"))
 
886
        self.assert_(not exists("sub1"))
 
887
        self.assert_(not exists("hello.txt"))
 
888
 
 
889
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
 
890
 
 
891
        mkdir("sub1")
 
892
        runbzr('add sub1')
 
893
        runbzr('move sub2/hello.txt sub1')
 
894
        self.assert_(not exists('sub2/hello.txt'))
 
895
        self.assert_(exists('sub1/hello.txt'))
 
896
        runbzr('move sub2 sub1')
 
897
        self.assert_(not exists('sub2'))
 
898
        self.assert_(exists('sub1/sub2'))
 
899
 
 
900
        runbzr(['commit', '-m', 'rename nested subdirectories'])
 
901
 
 
902
        chdir('sub1/sub2')
 
903
        self.assertEquals(capture('root')[:-1],
 
904
                          os.path.join(self.test_dir, 'branch1'))
 
905
        runbzr('move ../hello.txt .')
 
906
        self.assert_(exists('./hello.txt'))
 
907
        self.assertEquals(capture('relpath hello.txt'),
 
908
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
 
909
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
910
        runbzr(['commit', '-m', 'move to parent directory'])
 
911
        chdir('..')
 
912
        self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
913
 
 
914
        runbzr('move sub2/hello.txt .')
 
915
        self.assert_(exists('hello.txt'))
 
916
 
 
917
        f = file('hello.txt', 'wt')
 
918
        f.write('some nice new content\n')
 
919
        f.close()
 
920
 
 
921
        f = file('msg.tmp', 'wt')
 
922
        f.write('this is my new commit\nand it has multiple lines, for fun')
 
923
        f.close()
 
924
 
 
925
        runbzr('commit -F msg.tmp')
 
926
 
 
927
        self.assertEquals(capture('revno'), '5\n')
 
928
        runbzr('export -r 5 export-5.tmp')
 
929
        runbzr('export export.tmp')
 
930
 
 
931
        runbzr('log')
 
932
        runbzr('log -v')
 
933
        runbzr('log -v --forward')
 
934
        runbzr('log -m', retcode=1)
 
935
        log_out = capture('log -m commit')
 
936
        self.assert_("this is my new commit\n  and" in log_out)
 
937
        self.assert_("rename nested" not in log_out)
 
938
        self.assert_('revision-id' not in log_out)
 
939
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
 
940
 
 
941
        log_out = capture('log --line')
 
942
        for line in log_out.splitlines():
 
943
            self.assert_(len(line) <= 79, len(line))
 
944
        self.assert_("this is my new commit and" in log_out)
 
945
 
 
946
 
 
947
        progress("file with spaces in name")
 
948
        mkdir('sub directory')
 
949
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
 
950
        runbzr('add .')
 
951
        runbzr('diff', retcode=1)
 
952
        runbzr('commit -m add-spaces')
 
953
        runbzr('check')
 
954
 
 
955
        runbzr('log')
 
956
        runbzr('log --forward')
 
957
 
 
958
        runbzr('info')
 
959
 
 
960
        if has_symlinks():
 
961
            progress("symlinks")
 
962
            mkdir('symlinks')
 
963
            chdir('symlinks')
 
964
            runbzr('init')
 
965
            os.symlink("NOWHERE1", "link1")
 
966
            runbzr('add link1')
 
967
            self.assertEquals(self.capture('unknowns'), '')
 
968
            runbzr(['commit', '-m', '1: added symlink link1'])
 
969
    
 
970
            mkdir('d1')
 
971
            runbzr('add d1')
 
972
            self.assertEquals(self.capture('unknowns'), '')
 
973
            os.symlink("NOWHERE2", "d1/link2")
 
974
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
 
975
            # is d1/link2 found when adding d1
 
976
            runbzr('add d1')
 
977
            self.assertEquals(self.capture('unknowns'), '')
 
978
            os.symlink("NOWHERE3", "d1/link3")
 
979
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
 
980
            runbzr(['commit', '-m', '2: added dir, symlink'])
 
981
    
 
982
            runbzr('rename d1 d2')
 
983
            runbzr('move d2/link2 .')
 
984
            runbzr('move link1 d2')
 
985
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
 
986
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
 
987
            runbzr('add d2/link3')
 
988
            runbzr('diff', retcode=1)
 
989
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
 
990
    
 
991
            os.unlink("link2")
 
992
            os.symlink("TARGET 2", "link2")
 
993
            os.unlink("d2/link1")
 
994
            os.symlink("TARGET 1", "d2/link1")
 
995
            runbzr('diff', retcode=1)
 
996
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
 
997
            runbzr(['commit', '-m', '4: retarget of two links'])
 
998
    
 
999
            runbzr('remove d2/link1')
 
1000
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
1001
            runbzr(['commit', '-m', '5: remove d2/link1'])
 
1002
            # try with the rm alias
 
1003
            runbzr('add d2/link1')
 
1004
            runbzr(['commit', '-m', '6: add d2/link1'])
 
1005
            runbzr('rm d2/link1')
 
1006
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
1007
            runbzr(['commit', '-m', '7: remove d2/link1'])
 
1008
    
 
1009
            os.mkdir("d1")
 
1010
            runbzr('add d1')
 
1011
            runbzr('rename d2/link3 d1/link3new')
 
1012
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
1013
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
 
1014
            
 
1015
            runbzr(['check'])
 
1016
            
 
1017
            runbzr(['export', '-r', '1', 'exp1.tmp'])
 
1018
            chdir("exp1.tmp")
 
1019
            self.assertEquals(listdir_sorted("."), [ "link1" ])
 
1020
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
 
1021
            chdir("..")
 
1022
            
 
1023
            runbzr(['export', '-r', '2', 'exp2.tmp'])
 
1024
            chdir("exp2.tmp")
 
1025
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
 
1026
            chdir("..")
 
1027
            
 
1028
            runbzr(['export', '-r', '3', 'exp3.tmp'])
 
1029
            chdir("exp3.tmp")
 
1030
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
 
1031
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
 
1032
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
 
1033
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
 
1034
            chdir("..")
 
1035
            
 
1036
            runbzr(['export', '-r', '4', 'exp4.tmp'])
 
1037
            chdir("exp4.tmp")
 
1038
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
 
1039
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
 
1040
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
 
1041
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
 
1042
            chdir("..")
 
1043
            
 
1044
            runbzr(['export', '-r', '5', 'exp5.tmp'])
 
1045
            chdir("exp5.tmp")
 
1046
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
 
1047
            self.assert_(os.path.islink("link2"))
 
1048
            self.assert_(listdir_sorted("d2")== [ "link3" ])
 
1049
            chdir("..")
 
1050
            
 
1051
            runbzr(['export', '-r', '8', 'exp6.tmp'])
 
1052
            chdir("exp6.tmp")
 
1053
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
 
1054
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
 
1055
            self.assertEquals(listdir_sorted("d2"), [])
 
1056
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
 
1057
            chdir("..")
 
1058
        else:
 
1059
            progress("skipping symlink tests")
 
1060
 
 
1061
 
 
1062
class HttpTests(TestCaseWithWebserver):
 
1063
    """Test bzr ui commands against remote branches."""
 
1064
 
 
1065
    def test_branch(self):
 
1066
        os.mkdir('from')
 
1067
        branch = Branch.initialize('from')
 
1068
        branch.commit('empty commit for nonsense', allow_pointless=True)
 
1069
        url = self.get_remote_url('from')
 
1070
        self.run_bzr('branch', url, 'to')
 
1071
        branch = Branch.open('to')
 
1072
        self.assertEqual(1, len(branch.revision_history()))
 
1073
 
 
1074
    def test_log(self):
 
1075
        self.build_tree(['branch/', 'branch/file'])
 
1076
        branch = Branch.initialize('branch')
 
1077
        branch.add(['file'])
 
1078
        branch.commit('add file', rev_id='A')
 
1079
        url = self.get_remote_url('branch/file')
 
1080
        output = self.capture('log %s' % url)
 
1081
        self.assertEqual(7, len(output.split('\n')))
 
1082
        
 
1083
 
 
1084
 
 
1085