/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] refactoring of branch vs working tree, etc (robertc)

Show diffs side-by-side

added added

removed removed

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