/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

MergeĀ fromĀ mainline

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