/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

  • Committer: Martin Pool
  • Date: 2005-09-13 08:21:32 UTC
  • Revision ID: mbp@sourcefrog.net-20050913082132-66279763a02e695c
- allow the same version to be repeatedly added to a weave

  (silently absorb them into a single version)

- tests for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
# Mr. Smoketoomuch: I'm sorry?
19
 
# Mr. Bounder: You'd better cut down a little then.
20
 
# Mr. Smoketoomuch: Oh, I see! Smoke too much so I'd better cut down a little
21
 
#                   then!
22
18
 
23
19
"""Black-box tests for bzr.
24
20
 
25
21
These check that it behaves properly when it's invoked through the regular
26
 
command-line interface. This doesn't actually run a new interpreter but 
27
 
rather starts again from the run_bzr function.
 
22
command-line interface.
 
23
 
 
24
This always reinvokes bzr through a new Python interpreter, which is a
 
25
bit inefficient but arguably tests in a way more representative of how
 
26
it's normally invoked.
28
27
"""
29
28
 
30
 
 
31
 
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
 
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
33
 
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
 
# UI command/aspect that is being tested.
35
 
 
36
 
 
37
 
from cStringIO import StringIO
38
 
import os
39
 
import re
40
 
import shutil
41
29
import sys
42
30
 
 
31
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
43
32
from bzrlib.branch import Branch
44
 
import bzrlib.bzrdir as bzrdir
45
 
from bzrlib.errors import BzrCommandError
46
 
from bzrlib.osutils import has_symlinks, pathjoin
47
 
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
49
 
from bzrlib.tests.blackbox import ExternalBase
50
 
from bzrlib.workingtree import WorkingTree
 
33
from bzrlib.commands import run_bzr
 
34
 
 
35
 
 
36
class ExternalBase(TestCaseInTempDir):
 
37
    def runbzr(self, args, retcode=0,backtick=False):
 
38
        if isinstance(args, basestring):
 
39
            args = args.split()
 
40
 
 
41
        if backtick:
 
42
            return self.backtick(['python', self.BZRPATH,] + args,
 
43
                           retcode=retcode)
 
44
        else:
 
45
            return self.runcmd(['python', self.BZRPATH,] + args,
 
46
                           retcode=retcode)
51
47
 
52
48
 
53
49
class TestCommands(ExternalBase):
54
50
 
 
51
    def test_help_commands(self):
 
52
        self.runbzr('--help')
 
53
        self.runbzr('help')
 
54
        self.runbzr('help commands')
 
55
        self.runbzr('help help')
 
56
        self.runbzr('commit -h')
 
57
 
 
58
    def test_init_branch(self):
 
59
        self.runbzr(['init'])
 
60
 
55
61
    def test_whoami(self):
56
62
        # this should always identify something, if only "john@localhost"
57
63
        self.runbzr("whoami")
66
72
        f = file('.bzr/email', 'wt')
67
73
        f.write('Branch Identity <branch@identi.ty>')
68
74
        f.close()
69
 
        bzr_email = os.environ.get('BZREMAIL')
70
 
        if bzr_email is not None:
71
 
            del os.environ['BZREMAIL']
72
75
        whoami = self.runbzr("whoami",backtick=True)
73
76
        whoami_email = self.runbzr("whoami --email",backtick=True)
74
77
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
75
78
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
76
 
        # Verify that the environment variable overrides the value 
77
 
        # in the file
78
 
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
79
 
        whoami = self.runbzr("whoami",backtick=True)
80
 
        whoami_email = self.runbzr("whoami --email",backtick=True)
81
 
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
82
 
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
83
 
        if bzr_email is not None:
84
 
            os.environ['BZREMAIL'] = bzr_email
85
 
 
86
 
    def test_nick_command(self):
87
 
        """bzr nick for viewing, setting nicknames"""
88
 
        os.mkdir('me.dev')
89
 
        os.chdir('me.dev')
90
 
        self.runbzr('init')
91
 
        nick = self.runbzr("nick",backtick=True)
92
 
        self.assertEqual(nick, 'me.dev\n')
93
 
        nick = self.runbzr("nick moo")
94
 
        nick = self.runbzr("nick",backtick=True)
95
 
        self.assertEqual(nick, 'moo\n')
96
79
 
97
80
    def test_invalid_commands(self):
98
 
        self.runbzr("pants", retcode=3)
99
 
        self.runbzr("--pants off", retcode=3)
100
 
        self.runbzr("diff --message foo", retcode=3)
 
81
        self.runbzr("pants", retcode=1)
 
82
        self.runbzr("--pants off", retcode=1)
 
83
        self.runbzr("diff --message foo", retcode=1)
101
84
 
102
 
    def test_remove_deleted(self):
 
85
    def test_empty_commit(self):
103
86
        self.runbzr("init")
104
 
        self.build_tree(['a'])
105
 
        self.runbzr(['add', 'a'])
106
 
        self.runbzr(['commit', '-m', 'added a'])
107
 
        os.unlink('a')
108
 
        self.runbzr(['remove', 'a'])
 
87
        self.build_tree(['hello.txt'])
 
88
        self.runbzr("commit -m empty", retcode=1)
 
89
        self.runbzr("add hello.txt")
 
90
        self.runbzr("commit -m added")
109
91
 
110
92
    def test_ignore_patterns(self):
111
 
        self.runbzr('init')
112
 
        self.assertEquals(self.capture('unknowns'), '')
 
93
        from bzrlib.branch import Branch
 
94
        
 
95
        b = Branch('.', init=True)
 
96
        self.assertEquals(list(b.unknowns()), [])
113
97
 
114
98
        file('foo.tmp', 'wt').write('tmp files are ignored')
115
 
        self.assertEquals(self.capture('unknowns'), '')
 
99
        self.assertEquals(list(b.unknowns()), [])
 
100
        assert self.backtick('bzr unknowns') == ''
116
101
 
117
102
        file('foo.c', 'wt').write('int main() {}')
118
 
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
 
103
        self.assertEquals(list(b.unknowns()), ['foo.c'])
 
104
        assert self.backtick('bzr unknowns') == 'foo.c\n'
119
105
 
120
106
        self.runbzr(['add', 'foo.c'])
121
 
        self.assertEquals(self.capture('unknowns'), '')
 
107
        assert self.backtick('bzr unknowns') == ''
122
108
 
123
109
        # 'ignore' works when creating the .bzignore file
124
110
        file('foo.blah', 'wt').write('blah')
125
 
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
 
111
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
126
112
        self.runbzr('ignore *.blah')
127
 
        self.assertEquals(self.capture('unknowns'), '')
128
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
 
113
        self.assertEquals(list(b.unknowns()), [])
 
114
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
129
115
 
130
116
        # 'ignore' works when then .bzrignore file already exists
131
117
        file('garh', 'wt').write('garh')
132
 
        self.assertEquals(self.capture('unknowns'), 'garh\n')
 
118
        self.assertEquals(list(b.unknowns()), ['garh'])
 
119
        assert self.backtick('bzr unknowns') == 'garh\n'
133
120
        self.runbzr('ignore garh')
134
 
        self.assertEquals(self.capture('unknowns'), '')
135
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
 
121
        self.assertEquals(list(b.unknowns()), [])
 
122
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
136
123
 
137
124
    def test_revert(self):
 
125
        import os
138
126
        self.runbzr('init')
139
127
 
140
128
        file('hello', 'wt').write('foo')
144
132
        file('goodbye', 'wt').write('baz')
145
133
        self.runbzr('add goodbye')
146
134
        self.runbzr('commit -m setup goodbye')
147
 
 
 
135
        
148
136
        file('hello', 'wt').write('bar')
149
137
        file('goodbye', 'wt').write('qux')
150
138
        self.runbzr('revert hello')
159
147
        os.rmdir('revertdir')
160
148
        self.runbzr('revert')
161
149
 
162
 
        if has_symlinks():
163
 
            os.symlink('/unlikely/to/exist', 'symlink')
164
 
            self.runbzr('add symlink')
165
 
            self.runbzr('commit -m f')
166
 
            os.unlink('symlink')
167
 
            self.runbzr('revert')
168
 
            self.failUnlessExists('symlink')
169
 
            os.unlink('symlink')
170
 
            os.symlink('a-different-path', 'symlink')
171
 
            self.runbzr('revert')
172
 
            self.assertEqual('/unlikely/to/exist',
173
 
                             os.readlink('symlink'))
174
 
        else:
175
 
            self.log("skipping revert symlink tests")
176
 
        
177
 
        file('hello', 'wt').write('xyz')
178
 
        self.runbzr('commit -m xyz hello')
179
 
        self.runbzr('revert -r 1 hello')
180
 
        self.check_file_contents('hello', 'foo')
181
 
        self.runbzr('revert hello')
182
 
        self.check_file_contents('hello', 'xyz')
183
 
        os.chdir('revertdir')
184
 
        self.runbzr('revert')
185
 
        os.chdir('..')
186
 
 
187
 
    def test_mv_modes(self):
 
150
    def skipped_test_mv_modes(self):
188
151
        """Test two modes of operation for mv"""
189
 
        self.runbzr('init')
 
152
        from bzrlib.branch import Branch
 
153
        b = Branch('.', init=True)
190
154
        self.build_tree(['a', 'c', 'subdir/'])
191
 
        self.run_bzr_captured(['add', self.test_dir])
192
 
        self.run_bzr_captured(['mv', 'a', 'b'])
193
 
        self.run_bzr_captured(['mv', 'b', 'subdir'])
194
 
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
195
 
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
196
 
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
 
155
        self.run_bzr('mv', 'a', 'b')
 
156
        self.run_bzr('mv', 'b', 'subdir')
 
157
        self.run_bzr('mv', 'subdir/b', 'a')
 
158
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
159
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
197
160
 
198
161
    def test_main_version(self):
199
162
        """Check output from version command and master option is reasonable"""
219
182
        test.runbzr('add goodbye')
220
183
        test.runbzr('commit -m setup goodbye')
221
184
 
222
 
    def test_export(self):
223
 
        os.mkdir('branch')
224
 
        os.chdir('branch')
225
 
        self.example_branch()
226
 
        self.runbzr('export ../latest')
227
 
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
228
 
        self.runbzr('export ../first -r 1')
229
 
        self.assert_(not os.path.exists('../first/goodbye'))
230
 
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
231
 
        self.runbzr('export ../first.gz -r 1')
232
 
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
233
 
        self.runbzr('export ../first.bz2 -r 1')
234
 
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
235
 
 
236
 
        from tarfile import TarFile
237
 
        self.runbzr('export ../first.tar -r 1')
238
 
        self.assert_(os.path.isfile('../first.tar'))
239
 
        tf = TarFile('../first.tar')
240
 
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
241
 
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
 
        self.runbzr('export ../first.tar.gz -r 1')
243
 
        self.assert_(os.path.isfile('../first.tar.gz'))
244
 
        self.runbzr('export ../first.tbz2 -r 1')
245
 
        self.assert_(os.path.isfile('../first.tbz2'))
246
 
        self.runbzr('export ../first.tar.bz2 -r 1')
247
 
        self.assert_(os.path.isfile('../first.tar.bz2'))
248
 
        self.runbzr('export ../first.tar.tbz2 -r 1')
249
 
        self.assert_(os.path.isfile('../first.tar.tbz2'))
250
 
 
251
 
        from bz2 import BZ2File
252
 
        tf = TarFile('../first.tar.tbz2', 
253
 
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
254
 
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
255
 
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
256
 
        self.runbzr('export ../first2.tar -r 1 --root pizza')
257
 
        tf = TarFile('../first2.tar')
258
 
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
259
 
 
260
 
        from zipfile import ZipFile
261
 
        self.runbzr('export ../first.zip -r 1')
262
 
        self.failUnlessExists('../first.zip')
263
 
        zf = ZipFile('../first.zip')
264
 
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
265
 
        self.assertEqual(zf.read('first/hello'), 'foo')
266
 
 
267
 
        self.runbzr('export ../first2.zip -r 1 --root pizza')
268
 
        zf = ZipFile('../first2.zip')
269
 
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
270
 
        
271
 
        self.runbzr('export ../first-zip --format=zip -r 1')
272
 
        zf = ZipFile('../first-zip')
273
 
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
274
 
 
275
 
    def test_branch(self):
276
 
        """Branch from one branch to another."""
277
 
        os.mkdir('a')
278
 
        os.chdir('a')
279
 
        self.example_branch()
280
 
        os.chdir('..')
281
 
        self.runbzr('branch a b')
282
 
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
283
 
        self.runbzr('branch a c -r 1')
284
 
        os.chdir('b')
285
 
        self.runbzr('commit -m foo --unchanged')
286
 
        os.chdir('..')
287
 
 
288
 
    def test_branch_basis(self):
289
 
        # ensure that basis really does grab from the basis by having incomplete source
290
 
        tree = self.make_branch_and_tree('commit_tree')
291
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
292
 
        tree.add('foo')
293
 
        tree.commit('revision 1', rev_id='1')
294
 
        source = self.make_branch_and_tree('source')
295
 
        # this gives us an incomplete repository
296
 
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
297
 
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
298
 
        tree.bzrdir.open_branch().copy_content_into(source.branch)
299
 
        tree.copy_content_into(source)
300
 
        self.assertFalse(source.branch.repository.has_revision('2'))
301
 
        dir = source.bzrdir
302
 
        self.runbzr('branch source target --basis commit_tree')
303
 
        target = bzrdir.BzrDir.open('target')
304
 
        self.assertEqual('2', target.open_branch().last_revision())
305
 
        self.assertEqual('2', target.open_workingtree().last_revision())
306
 
        self.assertTrue(target.open_branch().repository.has_revision('2'))
 
185
    def test_revert(self):
 
186
        self.example_branch()
 
187
        file('hello', 'wt').write('bar')
 
188
        file('goodbye', 'wt').write('qux')
 
189
        self.runbzr('revert hello')
 
190
        self.check_file_contents('hello', 'foo')
 
191
        self.check_file_contents('goodbye', 'qux')
 
192
        self.runbzr('revert')
 
193
        self.check_file_contents('goodbye', 'baz')
307
194
 
308
195
    def test_merge(self):
309
196
        from bzrlib.branch import Branch
 
197
        import os
310
198
        
311
199
        os.mkdir('a')
312
200
        os.chdir('a')
 
201
 
313
202
        self.example_branch()
314
203
        os.chdir('..')
315
204
        self.runbzr('branch a b')
320
209
        os.chdir('../a')
321
210
        file('hello', 'wt').write('quuux')
322
211
        # We can't merge when there are in-tree changes
323
 
        self.runbzr('merge ../b', retcode=3)
 
212
        self.runbzr('merge ../b', retcode=1)
324
213
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
325
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
326
 
                    retcode=3)
327
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
328
 
        self.runbzr('revert --no-backup')
329
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
330
 
        self.runbzr('revert --no-backup')
331
 
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
332
 
        self.runbzr('revert --no-backup')
333
 
        self.runbzr('merge ../b -r last:1')
 
214
        self.runbzr('merge ../b')
334
215
        self.check_file_contents('goodbye', 'quux')
335
216
        # Merging a branch pulls its revision into the tree
336
 
        a = WorkingTree.open('.')
337
 
        b = Branch.open('../b')
338
 
        a.branch.repository.get_revision_xml(b.last_revision())
 
217
        a = Branch('.')
 
218
        b = Branch('../b')
 
219
        a.get_revision_xml(b.last_patch())
 
220
 
339
221
        self.log('pending merges: %s', a.pending_merges())
340
 
        self.assertEquals(a.pending_merges(),
341
 
                          [b.last_revision()])
342
 
        self.runbzr('commit -m merged')
343
 
        self.runbzr('merge ../b -r last:1')
344
 
        self.assertEqual(a.pending_merges(), [])
345
 
 
346
 
    def test_merge_with_missing_file(self):
347
 
        """Merge handles missing file conflicts"""
348
 
        os.mkdir('a')
349
 
        os.chdir('a')
350
 
        os.mkdir('sub')
351
 
        print >> file('sub/a.txt', 'wb'), "hello"
352
 
        print >> file('b.txt', 'wb'), "hello"
353
 
        print >> file('sub/c.txt', 'wb'), "hello"
354
 
        self.runbzr('init')
355
 
        self.runbzr('add')
356
 
        self.runbzr(('commit', '-m', 'added a'))
357
 
        self.runbzr('branch . ../b')
358
 
        print >> file('sub/a.txt', 'ab'), "there"
359
 
        print >> file('b.txt', 'ab'), "there"
360
 
        print >> file('sub/c.txt', 'ab'), "there"
361
 
        self.runbzr(('commit', '-m', 'Added there'))
362
 
        os.unlink('sub/a.txt')
363
 
        os.unlink('sub/c.txt')
364
 
        os.rmdir('sub')
365
 
        os.unlink('b.txt')
366
 
        self.runbzr(('commit', '-m', 'Removed a.txt'))
367
 
        os.chdir('../b')
368
 
        print >> file('sub/a.txt', 'ab'), "something"
369
 
        print >> file('b.txt', 'ab'), "something"
370
 
        print >> file('sub/c.txt', 'ab'), "something"
371
 
        self.runbzr(('commit', '-m', 'Modified a.txt'))
372
 
        self.runbzr('merge ../a/', retcode=1)
373
 
        self.assert_(os.path.exists('sub/a.txt.THIS'))
374
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
375
 
        os.chdir('../a')
376
 
        self.runbzr('merge ../b/', retcode=1)
377
 
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
378
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
379
 
 
380
 
    def test_inventory(self):
381
 
        bzr = self.runbzr
382
 
        def output_equals(value, *args):
383
 
            out = self.runbzr(['inventory'] + list(args), backtick=True)
384
 
            self.assertEquals(out, value)
385
 
 
386
 
        bzr('init')
387
 
        open('a', 'wb').write('hello\n')
388
 
        os.mkdir('b')
389
 
 
390
 
        bzr('add a b')
391
 
        bzr('commit -m add')
392
 
 
393
 
        output_equals('a\n', '--kind', 'file')
394
 
        output_equals('b\n', '--kind', 'directory')        
395
 
 
396
 
    def test_ls(self):
397
 
        """Test the abilities of 'bzr ls'"""
398
 
        bzr = self.runbzr
399
 
        def bzrout(*args, **kwargs):
400
 
            kwargs['backtick'] = True
401
 
            return self.runbzr(*args, **kwargs)
402
 
 
403
 
        def ls_equals(value, *args):
404
 
            out = self.runbzr(['ls'] + list(args), backtick=True)
405
 
            self.assertEquals(out, value)
406
 
 
407
 
        bzr('init')
408
 
        open('a', 'wb').write('hello\n')
409
 
 
410
 
        # Can't supply both
411
 
        bzr('ls --verbose --null', retcode=3)
412
 
 
413
 
        ls_equals('a\n')
414
 
        ls_equals('?        a\n', '--verbose')
415
 
        ls_equals('a\n', '--unknown')
416
 
        ls_equals('', '--ignored')
417
 
        ls_equals('', '--versioned')
418
 
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
419
 
        ls_equals('', '--ignored', '--versioned')
420
 
        ls_equals('a\0', '--null')
421
 
 
422
 
        bzr('add a')
423
 
        ls_equals('V        a\n', '--verbose')
424
 
        bzr('commit -m add')
425
 
        
426
 
        os.mkdir('subdir')
427
 
        ls_equals('V        a\n'
428
 
                  '?        subdir/\n'
429
 
                  , '--verbose')
430
 
        open('subdir/b', 'wb').write('b\n')
431
 
        bzr('add')
432
 
        ls_equals('V        a\n'
433
 
                  'V        subdir/\n'
434
 
                  'V        subdir/b\n'
435
 
                  , '--verbose')
436
 
        bzr('commit -m subdir')
437
 
 
438
 
        ls_equals('a\n'
439
 
                  'subdir\n'
440
 
                  , '--non-recursive')
441
 
 
442
 
        ls_equals('V        a\n'
443
 
                  'V        subdir/\n'
444
 
                  , '--verbose', '--non-recursive')
445
 
 
446
 
        # Check what happens in a sub-directory
447
 
        os.chdir('subdir')
448
 
        ls_equals('b\n')
449
 
        ls_equals('b\0'
450
 
                  , '--null')
451
 
        ls_equals('a\n'
452
 
                  'subdir\n'
453
 
                  'subdir/b\n'
454
 
                  , '--from-root')
455
 
        ls_equals('a\0'
456
 
                  'subdir\0'
457
 
                  'subdir/b\0'
458
 
                  , '--from-root', '--null')
459
 
        ls_equals('a\n'
460
 
                  'subdir\n'
461
 
                  , '--from-root', '--non-recursive')
462
 
 
463
 
        os.chdir('..')
464
 
 
465
 
        # Check what happens when we supply a specific revision
466
 
        ls_equals('a\n', '--revision', '1')
467
 
        ls_equals('V        a\n'
468
 
                  , '--verbose', '--revision', '1')
469
 
 
470
 
        os.chdir('subdir')
471
 
        ls_equals('', '--revision', '1')
472
 
 
473
 
        # Now try to do ignored files.
474
 
        os.chdir('..')
475
 
        open('blah.py', 'wb').write('unknown\n')
476
 
        open('blah.pyo', 'wb').write('ignored\n')
477
 
        ls_equals('a\n'
478
 
                  'blah.py\n'
479
 
                  'blah.pyo\n'
480
 
                  'subdir\n'
481
 
                  'subdir/b\n')
482
 
        ls_equals('V        a\n'
483
 
                  '?        blah.py\n'
484
 
                  'I        blah.pyo\n'
485
 
                  'V        subdir/\n'
486
 
                  'V        subdir/b\n'
487
 
                  , '--verbose')
488
 
        ls_equals('blah.pyo\n'
489
 
                  , '--ignored')
490
 
        ls_equals('blah.py\n'
491
 
                  , '--unknown')
492
 
        ls_equals('a\n'
493
 
                  'subdir\n'
494
 
                  'subdir/b\n'
495
 
                  , '--versioned')
496
 
 
497
 
    def test_cat(self):
498
 
        self.runbzr('init')
499
 
        file("myfile", "wb").write("My contents\n")
500
 
        self.runbzr('add')
501
 
        self.runbzr('commit -m myfile')
502
 
        self.run_bzr_captured('cat -r 1 myfile'.split(' '))
503
 
 
504
 
    def test_pull_verbose(self):
505
 
        """Pull changes from one branch to another and watch the output."""
506
 
 
507
 
        os.mkdir('a')
508
 
        os.chdir('a')
509
 
 
510
 
        bzr = self.runbzr
511
 
        self.example_branch()
512
 
 
513
 
        os.chdir('..')
514
 
        bzr('branch a b')
515
 
        os.chdir('b')
516
 
        open('b', 'wb').write('else\n')
517
 
        bzr('add b')
518
 
        bzr(['commit', '-m', 'added b'])
519
 
 
520
 
        os.chdir('../a')
521
 
        out = bzr('pull --verbose ../b', backtick=True)
522
 
        self.failIfEqual(out.find('Added Revisions:'), -1)
523
 
        self.failIfEqual(out.find('message:\n  added b'), -1)
524
 
        self.failIfEqual(out.find('added b'), -1)
525
 
 
526
 
        # Check that --overwrite --verbose prints out the removed entries
527
 
        bzr('commit -m foo --unchanged')
528
 
        os.chdir('../b')
529
 
        bzr('commit -m baz --unchanged')
530
 
        bzr('pull ../a', retcode=3)
531
 
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
532
 
 
533
 
        remove_loc = out.find('Removed Revisions:')
534
 
        self.failIfEqual(remove_loc, -1)
535
 
        added_loc = out.find('Added Revisions:')
536
 
        self.failIfEqual(added_loc, -1)
537
 
 
538
 
        removed_message = out.find('message:\n  baz')
539
 
        self.failIfEqual(removed_message, -1)
540
 
        self.failUnless(remove_loc < removed_message < added_loc)
541
 
 
542
 
        added_message = out.find('message:\n  foo')
543
 
        self.failIfEqual(added_message, -1)
544
 
        self.failUnless(added_loc < added_message)
545
 
        
546
 
    def test_locations(self):
547
 
        """Using and remembering different locations"""
548
 
        os.mkdir('a')
549
 
        os.chdir('a')
550
 
        self.runbzr('init')
551
 
        self.runbzr('commit -m unchanged --unchanged')
552
 
        self.runbzr('pull', retcode=3)
553
 
        self.runbzr('merge', retcode=3)
554
 
        self.runbzr('branch . ../b')
555
 
        os.chdir('../b')
556
 
        self.runbzr('pull')
557
 
        self.runbzr('branch . ../c')
558
 
        self.runbzr('pull ../c')
559
 
        self.runbzr('merge')
560
 
        os.chdir('../a')
561
 
        self.runbzr('pull ../b')
562
 
        self.runbzr('pull')
563
 
        self.runbzr('pull ../c')
564
 
        self.runbzr('branch ../c ../d')
565
 
        shutil.rmtree('../c')
566
 
        self.runbzr('pull')
567
 
        os.chdir('../b')
568
 
        self.runbzr('pull')
569
 
        os.chdir('../d')
570
 
        self.runbzr('pull', retcode=3)
571
 
        self.runbzr('pull ../a --remember')
572
 
        self.runbzr('pull')
573
 
        
 
222
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
 
223
        #        % (a.pending_merges(), b.last_patch())
 
224
 
 
225
 
574
226
    def test_add_reports(self):
575
227
        """add command prints the names of added files."""
576
 
        self.runbzr('init')
577
 
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
578
 
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
228
        b = Branch('.', init=True)
 
229
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
230
 
 
231
        from cStringIO import StringIO
 
232
        out = StringIO()
 
233
 
 
234
        ret = self.apply_redirected(None, out, None,
 
235
                                    run_bzr,
 
236
                                    ['add'])
 
237
        self.assertEquals(ret, 0)
 
238
 
579
239
        # the ordering is not defined at the moment
580
 
        results = sorted(out.rstrip('\n').split('\n'))
581
 
        self.assertEquals(['If you wish to add some of these files, please'\
582
 
                           ' add them by name.',
583
 
                           'added dir',
 
240
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
 
241
        self.assertEquals(['added dir',
584
242
                           'added dir/sub.txt',
585
 
                           'added top.txt',
586
 
                           'ignored 1 file(s) matching "CVS"'],
587
 
                          results)
588
 
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
589
 
        results = sorted(out.rstrip('\n').split('\n'))
590
 
        self.assertEquals(['If you wish to add some of these files, please'\
591
 
                           ' add them by name.',
592
 
                           'ignored CVS matching "CVS"'],
593
 
                          results)
594
 
 
595
 
    def test_add_quiet_is(self):
596
 
        """add -q does not print the names of added files."""
597
 
        self.runbzr('init')
598
 
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
599
 
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
600
 
        # the ordering is not defined at the moment
601
 
        results = sorted(out.rstrip('\n').split('\n'))
602
 
        self.assertEquals([''], results)
603
 
 
604
 
    def test_add_in_unversioned(self):
605
 
        """Try to add a file in an unversioned directory.
606
 
 
607
 
        "bzr add" should add the parent(s) as necessary.
608
 
        """
609
 
        self.runbzr('init')
610
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
611
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
612
 
        self.run_bzr('add', 'inertiatic/esp')
613
 
        self.assertEquals(self.capture('unknowns'), '')
614
 
 
615
 
        # Multiple unversioned parents
616
 
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
617
 
        self.assertEquals(self.capture('unknowns'), 'veil\n')
618
 
        self.run_bzr('add', 'veil/cerpin/taxt')
619
 
        self.assertEquals(self.capture('unknowns'), '')
620
 
 
621
 
        # Check whacky paths work
622
 
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
623
 
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
624
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
625
 
        self.assertEquals(self.capture('unknowns'), '')
626
 
 
627
 
    def test_add_in_versioned(self):
628
 
        """Try to add a file in a versioned directory.
629
 
 
630
 
        "bzr add" should do this happily.
631
 
        """
632
 
        self.runbzr('init')
633
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
634
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
635
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
636
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
637
 
        self.run_bzr('add', 'inertiatic/esp')
638
 
        self.assertEquals(self.capture('unknowns'), '')
639
 
 
640
 
    def test_subdir_add(self):
641
 
        """Add in subdirectory should add only things from there down"""
642
 
        from bzrlib.workingtree import WorkingTree
643
 
        
644
 
        eq = self.assertEqual
645
 
        ass = self.assert_
646
 
        chdir = os.chdir
647
 
        
648
 
        t = self.make_branch_and_tree('.')
649
 
        b = t.branch
650
 
        self.build_tree(['src/', 'README'])
651
 
        
652
 
        eq(sorted(t.unknowns()),
653
 
           ['README', 'src'])
654
 
        
655
 
        self.run_bzr('add', 'src')
656
 
        
657
 
        self.build_tree(['src/foo.c'])
658
 
        
659
 
        chdir('src')
660
 
        self.run_bzr('add')
661
 
        
662
 
        self.assertEquals(self.capture('unknowns'), 'README\n')
663
 
        eq(len(t.read_working_inventory()), 3)
664
 
                
665
 
        chdir('..')
666
 
        self.run_bzr('add')
667
 
        self.assertEquals(self.capture('unknowns'), '')
668
 
        self.run_bzr('check')
669
 
 
670
 
    def test_unknown_command(self):
671
 
        """Handling of unknown command."""
672
 
        out, err = self.run_bzr_captured(['fluffy-badger'],
673
 
                                         retcode=3)
674
 
        self.assertEquals(out, '')
675
 
        err.index('unknown command')
676
 
 
677
 
    def create_conflicts(self):
678
 
        """Create a conflicted tree"""
679
 
        os.mkdir('base')
680
 
        os.chdir('base')
681
 
        file('hello', 'wb').write("hi world")
682
 
        file('answer', 'wb').write("42")
683
 
        self.runbzr('init')
684
 
        self.runbzr('add')
685
 
        self.runbzr('commit -m base')
686
 
        self.runbzr('branch . ../other')
687
 
        self.runbzr('branch . ../this')
688
 
        os.chdir('../other')
689
 
        file('hello', 'wb').write("Hello.")
690
 
        file('answer', 'wb').write("Is anyone there?")
691
 
        self.runbzr('commit -m other')
692
 
        os.chdir('../this')
693
 
        file('hello', 'wb').write("Hello, world")
694
 
        self.runbzr('mv answer question')
695
 
        file('question', 'wb').write("What do you get when you multiply six"
696
 
                                   "times nine?")
697
 
        self.runbzr('commit -m this')
698
 
 
699
 
    def test_remerge(self):
700
 
        """Remerge command works as expected"""
701
 
        self.create_conflicts()
702
 
        self.runbzr('merge ../other --show-base', retcode=1)
703
 
        conflict_text = file('hello').read()
704
 
        assert '|||||||' in conflict_text
705
 
        assert 'hi world' in conflict_text
706
 
        self.runbzr('remerge', retcode=1)
707
 
        conflict_text = file('hello').read()
708
 
        assert '|||||||' not in conflict_text
709
 
        assert 'hi world' not in conflict_text
710
 
        os.unlink('hello.OTHER')
711
 
        os.unlink('question.OTHER')
712
 
        self.runbzr('remerge jello --merge-type weave', retcode=3)
713
 
        self.runbzr('remerge hello --merge-type weave', retcode=1)
714
 
        assert os.path.exists('hello.OTHER')
715
 
        self.assertIs(False, os.path.exists('question.OTHER'))
716
 
        file_id = self.runbzr('file-id hello')
717
 
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
718
 
        self.runbzr('remerge --merge-type weave', retcode=1)
719
 
        assert os.path.exists('hello.OTHER')
720
 
        assert not os.path.exists('hello.BASE')
721
 
        assert '|||||||' not in conflict_text
722
 
        assert 'hi world' not in conflict_text
723
 
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
724
 
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
725
 
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
726
 
        self.runbzr('remerge hello --show-base', retcode=1)
727
 
        self.runbzr('remerge hello --reprocess', retcode=1)
728
 
        self.runbzr('resolve --all')
729
 
        self.runbzr('commit -m done',)
730
 
        self.runbzr('remerge', retcode=3)
731
 
 
732
 
    def test_status(self):
733
 
        os.mkdir('branch1')
734
 
        os.chdir('branch1')
735
 
        self.runbzr('init')
736
 
        self.runbzr('commit --unchanged --message f')
737
 
        self.runbzr('branch . ../branch2')
738
 
        self.runbzr('branch . ../branch3')
739
 
        self.runbzr('commit --unchanged --message peter')
740
 
        os.chdir('../branch2')
741
 
        self.runbzr('merge ../branch1')
742
 
        self.runbzr('commit --unchanged --message pumpkin')
743
 
        os.chdir('../branch3')
744
 
        self.runbzr('merge ../branch2')
745
 
        message = self.capture('status')
746
 
 
747
 
 
748
 
    def test_conflicts(self):
749
 
        """Handling of merge conflicts"""
750
 
        self.create_conflicts()
751
 
        self.runbzr('merge ../other --show-base', retcode=1)
752
 
        conflict_text = file('hello').read()
753
 
        self.assert_('<<<<<<<' in conflict_text)
754
 
        self.assert_('>>>>>>>' in conflict_text)
755
 
        self.assert_('=======' in conflict_text)
756
 
        self.assert_('|||||||' in conflict_text)
757
 
        self.assert_('hi world' in conflict_text)
758
 
        self.runbzr('revert')
759
 
        self.runbzr('resolve --all')
760
 
        self.runbzr('merge ../other', retcode=1)
761
 
        conflict_text = file('hello').read()
762
 
        self.assert_('|||||||' not in conflict_text)
763
 
        self.assert_('hi world' not in conflict_text)
764
 
        result = self.runbzr('conflicts', backtick=1)
765
 
        self.assertEquals(result, "Text conflict in hello\nText conflict in"
766
 
                                  " question\n")
767
 
        result = self.runbzr('status', backtick=1)
768
 
        self.assert_("conflicts:\n  Text conflict in hello\n"
769
 
                     "  Text conflict in question\n" in result, result)
770
 
        self.runbzr('resolve hello')
771
 
        result = self.runbzr('conflicts', backtick=1)
772
 
        self.assertEquals(result, "Text conflict in question\n")
773
 
        self.runbzr('commit -m conflicts', retcode=3)
774
 
        self.runbzr('resolve --all')
775
 
        result = self.runbzr('conflicts', backtick=1)
776
 
        self.runbzr('commit -m conflicts')
777
 
        self.assertEquals(result, "")
778
 
 
779
 
    def test_push(self):
780
 
        # create a source branch
781
 
        os.mkdir('my-branch')
782
 
        os.chdir('my-branch')
783
 
        self.example_branch()
784
 
 
785
 
        # with no push target, fail
786
 
        self.runbzr('push', retcode=3)
787
 
        # with an explicit target work
788
 
        self.runbzr('push ../output-branch')
789
 
        # with an implicit target work
790
 
        self.runbzr('push')
791
 
        # nothing missing
792
 
        self.runbzr('missing ../output-branch')
793
 
        # advance this branch
794
 
        self.runbzr('commit --unchanged -m unchanged')
795
 
 
796
 
        os.chdir('../output-branch')
797
 
        # There is no longer a difference as long as we have
798
 
        # access to the working tree
799
 
        self.runbzr('diff')
800
 
 
801
 
        # But we should be missing a revision
802
 
        self.runbzr('missing ../my-branch', retcode=1)
803
 
 
804
 
        # diverge the branches
805
 
        self.runbzr('commit --unchanged -m unchanged')
806
 
        os.chdir('../my-branch')
807
 
        # cannot push now
808
 
        self.runbzr('push', retcode=3)
809
 
        # and there are difference
810
 
        self.runbzr('missing ../output-branch', retcode=1)
811
 
        self.runbzr('missing --verbose ../output-branch', retcode=1)
812
 
        # but we can force a push
813
 
        self.runbzr('push --overwrite')
814
 
        # nothing missing
815
 
        self.runbzr('missing ../output-branch')
816
 
        
817
 
        # pushing to a new dir with no parent should fail
818
 
        self.runbzr('push ../missing/new-branch', retcode=3)
819
 
        # unless we provide --create-prefix
820
 
        self.runbzr('push --create-prefix ../missing/new-branch')
821
 
        # nothing missing
822
 
        self.runbzr('missing ../missing/new-branch')
823
 
 
824
 
    def test_external_command(self):
825
 
        """Test that external commands can be run by setting the path
826
 
        """
827
 
        # We don't at present run bzr in a subprocess for blackbox tests, and so 
828
 
        # don't really capture stdout, only the internal python stream.
829
 
        # Therefore we don't use a subcommand that produces any output or does
830
 
        # anything -- we just check that it can be run successfully.  
831
 
        cmd_name = 'test-command'
832
 
        if sys.platform == 'win32':
833
 
            cmd_name += '.bat'
834
 
        oldpath = os.environ.get('BZRPATH', None)
835
 
        bzr = self.capture
836
 
        try:
837
 
            if os.environ.has_key('BZRPATH'):
838
 
                del os.environ['BZRPATH']
839
 
 
840
 
            f = file(cmd_name, 'wb')
841
 
            if sys.platform == 'win32':
842
 
                f.write('@echo off\n')
843
 
            else:
844
 
                f.write('#!/bin/sh\n')
845
 
            # f.write('echo Hello from test-command')
846
 
            f.close()
847
 
            os.chmod(cmd_name, 0755)
848
 
 
849
 
            # It should not find the command in the local 
850
 
            # directory by default, since it is not in my path
851
 
            bzr(cmd_name, retcode=3)
852
 
 
853
 
            # Now put it into my path
854
 
            os.environ['BZRPATH'] = '.'
855
 
 
856
 
            bzr(cmd_name)
857
 
 
858
 
            # Make sure empty path elements are ignored
859
 
            os.environ['BZRPATH'] = os.pathsep
860
 
 
861
 
            bzr(cmd_name, retcode=3)
862
 
 
863
 
        finally:
864
 
            if oldpath:
865
 
                os.environ['BZRPATH'] = oldpath
866
 
 
867
 
 
868
 
def listdir_sorted(dir):
869
 
    L = os.listdir(dir)
870
 
    L.sort()
871
 
    return L
 
243
                           'added top.txt',],
 
244
                          results)
872
245
 
873
246
 
874
247
class OldTests(ExternalBase):
877
250
    def test_bzr(self):
878
251
        from os import chdir, mkdir
879
252
        from os.path import exists
 
253
        import os
880
254
 
881
255
        runbzr = self.runbzr
882
 
        capture = self.capture
 
256
        backtick = self.backtick
883
257
        progress = self.log
884
258
 
885
259
        progress("basic branch creation")
887
261
        chdir('branch1')
888
262
        runbzr('init')
889
263
 
890
 
        self.assertEquals(capture('root').rstrip(),
891
 
                          pathjoin(self.test_dir, 'branch1'))
 
264
        self.assertEquals(backtick('bzr root').rstrip(),
 
265
                          os.path.join(self.test_dir, 'branch1'))
892
266
 
893
267
        progress("status of new file")
894
268
 
896
270
        f.write('hello world!\n')
897
271
        f.close()
898
272
 
899
 
        self.assertEquals(capture('unknowns'), 'test.txt\n')
900
 
 
901
 
        out = capture("status")
902
 
        self.assertEquals(out, 'unknown:\n  test.txt\n')
903
 
 
904
 
        out = capture("status --all")
905
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
906
 
 
907
 
        out = capture("status test.txt --all")
908
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
273
        out = backtick("bzr unknowns")
 
274
        self.assertEquals(out, 'test.txt\n')
 
275
 
 
276
        out = backtick("bzr status")
 
277
        assert out == 'unknown:\n  test.txt\n'
 
278
 
 
279
        out = backtick("bzr status --all")
 
280
        assert out == "unknown:\n  test.txt\n"
 
281
 
 
282
        out = backtick("bzr status test.txt --all")
 
283
        assert out == "unknown:\n  test.txt\n"
909
284
 
910
285
        f = file('test2.txt', 'wt')
911
286
        f.write('goodbye cruel world...\n')
912
287
        f.close()
913
288
 
914
 
        out = capture("status test.txt")
915
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
289
        out = backtick("bzr status test.txt")
 
290
        assert out == "unknown:\n  test.txt\n"
916
291
 
917
 
        out = capture("status")
918
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
 
292
        out = backtick("bzr status")
 
293
        assert out == ("unknown:\n"
 
294
                       "  test.txt\n"
 
295
                       "  test2.txt\n")
919
296
 
920
297
        os.unlink('test2.txt')
921
298
 
922
299
        progress("command aliases")
923
 
        out = capture("st --all")
924
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
300
        out = backtick("bzr st --all")
 
301
        assert out == ("unknown:\n"
 
302
                       "  test.txt\n")
925
303
 
926
 
        out = capture("stat")
927
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
304
        out = backtick("bzr stat")
 
305
        assert out == ("unknown:\n"
 
306
                       "  test.txt\n")
928
307
 
929
308
        progress("command help")
930
309
        runbzr("help st")
931
310
        runbzr("help")
932
311
        runbzr("help commands")
933
 
        runbzr("help slartibartfast", 3)
 
312
        runbzr("help slartibartfast", 1)
934
313
 
935
 
        out = capture("help ci")
 
314
        out = backtick("bzr help ci")
936
315
        out.index('aliases: ')
937
316
 
938
317
        progress("can't rename unversioned file")
939
 
        runbzr("rename test.txt new-test.txt", 3)
 
318
        runbzr("rename test.txt new-test.txt", 1)
940
319
 
941
320
        progress("adding a file")
942
321
 
943
322
        runbzr("add test.txt")
944
 
        self.assertEquals(capture("unknowns"), '')
945
 
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
 
323
        assert backtick("bzr unknowns") == ''
 
324
        assert backtick("bzr status --all") == ("added:\n"
 
325
                                                "  test.txt\n")
946
326
 
947
327
        progress("rename newly-added file")
948
328
        runbzr("rename test.txt hello.txt")
949
 
        self.assert_(os.path.exists("hello.txt"))
950
 
        self.assert_(not os.path.exists("test.txt"))
 
329
        assert os.path.exists("hello.txt")
 
330
        assert not os.path.exists("test.txt")
951
331
 
952
 
        self.assertEquals(capture("revno"), '0\n')
 
332
        assert backtick("bzr revno") == '0\n'
953
333
 
954
334
        progress("add first revision")
955
335
        runbzr(['commit', '-m', 'add first revision'])
956
336
 
957
337
        progress("more complex renames")
958
338
        os.mkdir("sub1")
959
 
        runbzr("rename hello.txt sub1", 3)
960
 
        runbzr("rename hello.txt sub1/hello.txt", 3)
961
 
        runbzr("move hello.txt sub1", 3)
 
339
        runbzr("rename hello.txt sub1", 1)
 
340
        runbzr("rename hello.txt sub1/hello.txt", 1)
 
341
        runbzr("move hello.txt sub1", 1)
962
342
 
963
343
        runbzr("add sub1")
964
344
        runbzr("rename sub1 sub2")
965
345
        runbzr("move hello.txt sub2")
966
 
        self.assertEqual(capture("relpath sub2/hello.txt"),
967
 
                         pathjoin("sub2", "hello.txt\n"))
 
346
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
968
347
 
969
 
        self.assert_(exists("sub2"))
970
 
        self.assert_(exists("sub2/hello.txt"))
971
 
        self.assert_(not exists("sub1"))
972
 
        self.assert_(not exists("hello.txt"))
 
348
        assert exists("sub2")
 
349
        assert exists("sub2/hello.txt")
 
350
        assert not exists("sub1")
 
351
        assert not exists("hello.txt")
973
352
 
974
353
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
975
354
 
976
355
        mkdir("sub1")
977
356
        runbzr('add sub1')
978
357
        runbzr('move sub2/hello.txt sub1')
979
 
        self.assert_(not exists('sub2/hello.txt'))
980
 
        self.assert_(exists('sub1/hello.txt'))
 
358
        assert not exists('sub2/hello.txt')
 
359
        assert exists('sub1/hello.txt')
981
360
        runbzr('move sub2 sub1')
982
 
        self.assert_(not exists('sub2'))
983
 
        self.assert_(exists('sub1/sub2'))
 
361
        assert not exists('sub2')
 
362
        assert exists('sub1/sub2')
984
363
 
985
364
        runbzr(['commit', '-m', 'rename nested subdirectories'])
986
365
 
987
366
        chdir('sub1/sub2')
988
 
        self.assertEquals(capture('root')[:-1],
989
 
                          pathjoin(self.test_dir, 'branch1'))
 
367
        self.assertEquals(backtick('bzr root')[:-1],
 
368
                          os.path.join(self.test_dir, 'branch1'))
990
369
        runbzr('move ../hello.txt .')
991
 
        self.assert_(exists('./hello.txt'))
992
 
        self.assertEquals(capture('relpath hello.txt'),
993
 
                          pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
994
 
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
 
370
        assert exists('./hello.txt')
 
371
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
372
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
995
373
        runbzr(['commit', '-m', 'move to parent directory'])
996
374
        chdir('..')
997
 
        self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
 
375
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
998
376
 
999
377
        runbzr('move sub2/hello.txt .')
1000
 
        self.assert_(exists('hello.txt'))
 
378
        assert exists('hello.txt')
1001
379
 
1002
380
        f = file('hello.txt', 'wt')
1003
381
        f.write('some nice new content\n')
1004
382
        f.close()
1005
383
 
1006
384
        f = file('msg.tmp', 'wt')
1007
 
        f.write('this is my new commit\nand it has multiple lines, for fun')
 
385
        f.write('this is my new commit\n')
1008
386
        f.close()
1009
387
 
1010
388
        runbzr('commit -F msg.tmp')
1011
389
 
1012
 
        self.assertEquals(capture('revno'), '5\n')
 
390
        assert backtick('bzr revno') == '5\n'
1013
391
        runbzr('export -r 5 export-5.tmp')
1014
392
        runbzr('export export.tmp')
1015
393
 
1016
394
        runbzr('log')
1017
395
        runbzr('log -v')
1018
396
        runbzr('log -v --forward')
1019
 
        runbzr('log -m', retcode=3)
1020
 
        log_out = capture('log -m commit')
1021
 
        self.assert_("this is my new commit\n  and" in log_out)
1022
 
        self.assert_("rename nested" not in log_out)
1023
 
        self.assert_('revision-id' not in log_out)
1024
 
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
1025
 
 
1026
 
        log_out = capture('log --line')
1027
 
        for line in log_out.splitlines():
1028
 
            self.assert_(len(line) <= 79, len(line))
1029
 
        self.assert_("this is my new commit and" in log_out)
 
397
        runbzr('log -m', retcode=1)
 
398
        log_out = backtick('bzr log -m commit')
 
399
        assert "this is my new commit" in log_out
 
400
        assert "rename nested" not in log_out
 
401
        assert 'revision-id' not in log_out
 
402
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1030
403
 
1031
404
 
1032
405
        progress("file with spaces in name")
1033
406
        mkdir('sub directory')
1034
407
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1035
408
        runbzr('add .')
1036
 
        runbzr('diff', retcode=1)
 
409
        runbzr('diff')
1037
410
        runbzr('commit -m add-spaces')
1038
411
        runbzr('check')
1039
412
 
1042
415
 
1043
416
        runbzr('info')
1044
417
 
1045
 
        if has_symlinks():
1046
 
            progress("symlinks")
1047
 
            mkdir('symlinks')
1048
 
            chdir('symlinks')
1049
 
            runbzr('init')
1050
 
            os.symlink("NOWHERE1", "link1")
1051
 
            runbzr('add link1')
1052
 
            self.assertEquals(self.capture('unknowns'), '')
1053
 
            runbzr(['commit', '-m', '1: added symlink link1'])
1054
 
    
1055
 
            mkdir('d1')
1056
 
            runbzr('add d1')
1057
 
            self.assertEquals(self.capture('unknowns'), '')
1058
 
            os.symlink("NOWHERE2", "d1/link2")
1059
 
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1060
 
            # is d1/link2 found when adding d1
1061
 
            runbzr('add d1')
1062
 
            self.assertEquals(self.capture('unknowns'), '')
1063
 
            os.symlink("NOWHERE3", "d1/link3")
1064
 
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1065
 
            runbzr(['commit', '-m', '2: added dir, symlink'])
1066
 
    
1067
 
            runbzr('rename d1 d2')
1068
 
            runbzr('move d2/link2 .')
1069
 
            runbzr('move link1 d2')
1070
 
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1071
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1072
 
            runbzr('add d2/link3')
1073
 
            runbzr('diff', retcode=1)
1074
 
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1075
 
    
1076
 
            os.unlink("link2")
1077
 
            os.symlink("TARGET 2", "link2")
1078
 
            os.unlink("d2/link1")
1079
 
            os.symlink("TARGET 1", "d2/link1")
1080
 
            runbzr('diff', retcode=1)
1081
 
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1082
 
            runbzr(['commit', '-m', '4: retarget of two links'])
1083
 
    
1084
 
            runbzr('remove d2/link1')
1085
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1086
 
            runbzr(['commit', '-m', '5: remove d2/link1'])
1087
 
            # try with the rm alias
1088
 
            runbzr('add d2/link1')
1089
 
            runbzr(['commit', '-m', '6: add d2/link1'])
1090
 
            runbzr('rm d2/link1')
1091
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1092
 
            runbzr(['commit', '-m', '7: remove d2/link1'])
1093
 
    
1094
 
            os.mkdir("d1")
1095
 
            runbzr('add d1')
1096
 
            runbzr('rename d2/link3 d1/link3new')
1097
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1098
 
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1099
 
            
1100
 
            runbzr(['check'])
1101
 
            
1102
 
            runbzr(['export', '-r', '1', 'exp1.tmp'])
1103
 
            chdir("exp1.tmp")
1104
 
            self.assertEquals(listdir_sorted("."), [ "link1" ])
1105
 
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
1106
 
            chdir("..")
1107
 
            
1108
 
            runbzr(['export', '-r', '2', 'exp2.tmp'])
1109
 
            chdir("exp2.tmp")
1110
 
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1111
 
            chdir("..")
1112
 
            
1113
 
            runbzr(['export', '-r', '3', 'exp3.tmp'])
1114
 
            chdir("exp3.tmp")
1115
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1116
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1117
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1118
 
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
1119
 
            chdir("..")
1120
 
            
1121
 
            runbzr(['export', '-r', '4', 'exp4.tmp'])
1122
 
            chdir("exp4.tmp")
1123
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1124
 
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1125
 
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
1126
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1127
 
            chdir("..")
1128
 
            
1129
 
            runbzr(['export', '-r', '5', 'exp5.tmp'])
1130
 
            chdir("exp5.tmp")
1131
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1132
 
            self.assert_(os.path.islink("link2"))
1133
 
            self.assert_(listdir_sorted("d2")== [ "link3" ])
1134
 
            chdir("..")
1135
 
            
1136
 
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1137
 
            chdir("exp6.tmp")
1138
 
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1139
 
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1140
 
            self.assertEquals(listdir_sorted("d2"), [])
1141
 
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1142
 
            chdir("..")
1143
 
        else:
1144
 
            progress("skipping symlink tests")
1145
 
 
1146
 
 
1147
 
class RemoteTests(object):
1148
 
    """Test bzr ui commands against remote branches."""
1149
 
 
1150
 
    def test_branch(self):
1151
 
        os.mkdir('from')
1152
 
        wt = self.make_branch_and_tree('from')
1153
 
        branch = wt.branch
1154
 
        wt.commit('empty commit for nonsense', allow_pointless=True)
1155
 
        url = self.get_readonly_url('from')
1156
 
        self.run_bzr('branch', url, 'to')
1157
 
        branch = Branch.open('to')
1158
 
        self.assertEqual(1, len(branch.revision_history()))
1159
 
        # the branch should be set in to to from
1160
 
        self.assertEqual(url + '/', branch.get_parent())
1161
 
 
1162
 
    def test_log(self):
1163
 
        self.build_tree(['branch/', 'branch/file'])
1164
 
        self.capture('init branch')
1165
 
        self.capture('add branch/file')
1166
 
        self.capture('commit -m foo branch')
1167
 
        url = self.get_readonly_url('branch/file')
1168
 
        output = self.capture('log %s' % url)
1169
 
        self.assertEqual(8, len(output.split('\n')))
1170
 
        
1171
 
    def test_check(self):
1172
 
        self.build_tree(['branch/', 'branch/file'])
1173
 
        self.capture('init branch')
1174
 
        self.capture('add branch/file')
1175
 
        self.capture('commit -m foo branch')
1176
 
        url = self.get_readonly_url('branch/')
1177
 
        self.run_bzr('check', url)
1178
 
    
1179
 
    def test_push(self):
1180
 
        # create a source branch
1181
 
        os.mkdir('my-branch')
1182
 
        os.chdir('my-branch')
1183
 
        self.run_bzr('init')
1184
 
        file('hello', 'wt').write('foo')
1185
 
        self.run_bzr('add', 'hello')
1186
 
        self.run_bzr('commit', '-m', 'setup')
1187
 
 
1188
 
        # with an explicit target work
1189
 
        self.run_bzr('push', self.get_url('output-branch'))
1190
 
 
1191
 
    
1192
 
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1193
 
    """Test various commands against a HTTP server."""
1194
 
    
1195
 
    
1196
 
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1197
 
    """Test various commands against a SFTP server using abs paths."""
1198
 
 
1199
 
    
1200
 
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1201
 
    """Test various commands against a SFTP server using abs paths."""
1202
 
 
1203
 
    def setUp(self):
1204
 
        super(SFTPTestsAbsoluteSibling, self).setUp()
1205
 
        self._override_home = '/dev/noone/runs/tests/here'
1206
 
 
1207
 
    
1208
 
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1209
 
    """Test various commands against a SFTP server using homedir rel paths."""
1210
 
 
1211
 
    def setUp(self):
1212
 
        super(SFTPTestsRelative, self).setUp()
1213
 
        self._get_remote_is_absolute = False