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
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
23
19
"""Black-box tests for bzr.
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.
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.
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.
37
from cStringIO import StringIO
43
from bzrlib.branch import Branch
44
import bzrlib.bzrdir as bzrdir
45
from bzrlib.errors import BzrCommandError
46
from bzrlib.osutils import (
52
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
53
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
54
from bzrlib.tests.blackbox import ExternalBase
55
from bzrlib.workingtree import WorkingTree
58
class TestCommands(ExternalBase):
60
def test_whoami(self):
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
36
class ExternalBase(InTempDir):
37
def runbzr(self, args, retcode=0):
40
from subprocess import call
41
except ImportError, e:
45
if isinstance(args, basestring):
48
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestVersion(ExternalBase):
55
# output is intentionally passed through to stdout so that we
56
# can see the version being tested
57
self.runbzr(['version'])
61
class HelpCommands(ExternalBase):
65
self.runbzr('help commands')
66
self.runbzr('help help')
67
self.runbzr('commit -h')
70
class InitBranch(ExternalBase):
77
class UserIdentity(ExternalBase):
61
79
# this should always identify something, if only "john@localhost"
62
80
self.runbzr("whoami")
63
81
self.runbzr("whoami --email")
65
self.assertEquals(self.runbzr("whoami --email",
66
backtick=True).count('@'), 1)
82
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
86
class InvalidCommands(ExternalBase):
88
self.runbzr("pants", retcode=1)
89
self.runbzr("--pants off", retcode=1)
90
self.runbzr("diff --message foo", retcode=1)
94
class EmptyCommit(ExternalBase):
97
self.build_tree(['hello.txt'])
98
self.runbzr("commit -m empty", retcode=1)
99
self.runbzr("add hello.txt")
100
self.runbzr("commit -m added")
104
class IgnorePatterns(ExternalBase):
106
from bzrlib.branch import Branch
68
def test_whoami_branch(self):
69
"""branch specific user identity works."""
71
b = bzrlib.branch.Branch.open('.')
72
b.control_files.put_utf8('email', 'Branch Identity <branch@identi.ty>')
73
bzr_email = os.environ.get('BZREMAIL')
74
if bzr_email is not None:
75
del os.environ['BZREMAIL']
76
whoami = self.runbzr("whoami",backtick=True)
77
whoami_email = self.runbzr("whoami --email",backtick=True)
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
80
# Verify that the environment variable overrides the value
82
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
83
whoami = self.runbzr("whoami",backtick=True)
84
whoami_email = self.runbzr("whoami --email",backtick=True)
85
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
86
self.assertTrue(whoami_email.startswith('other@environ.ment'))
87
if bzr_email is not None:
88
os.environ['BZREMAIL'] = bzr_email
90
def test_nick_command(self):
91
"""bzr nick for viewing, setting nicknames"""
95
nick = self.runbzr("nick",backtick=True)
96
self.assertEqual(nick, 'me.dev\n')
97
nick = self.runbzr("nick moo")
98
nick = self.runbzr("nick",backtick=True)
99
self.assertEqual(nick, 'moo\n')
101
def test_invalid_commands(self):
102
self.runbzr("pants", retcode=3)
103
self.runbzr("--pants off", retcode=3)
104
self.runbzr("diff --message foo", retcode=3)
106
def test_ignore_patterns(self):
108
self.assertEquals(self.capture('unknowns'), '')
108
b = Branch('.', init=True)
109
self.assertEquals(list(b.unknowns()), [])
110
111
file('foo.tmp', 'wt').write('tmp files are ignored')
111
self.assertEquals(self.capture('unknowns'), '')
112
self.assertEquals(list(b.unknowns()), [])
113
assert self.backtick('bzr unknowns') == ''
113
115
file('foo.c', 'wt').write('int main() {}')
114
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
116
self.assertEquals(list(b.unknowns()), ['foo.c'])
117
assert self.backtick('bzr unknowns') == 'foo.c\n'
116
119
self.runbzr(['add', 'foo.c'])
117
self.assertEquals(self.capture('unknowns'), '')
120
assert self.backtick('bzr unknowns') == ''
119
122
# 'ignore' works when creating the .bzignore file
120
123
file('foo.blah', 'wt').write('blah')
121
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
124
self.assertEquals(list(b.unknowns()), ['foo.blah'])
122
125
self.runbzr('ignore *.blah')
123
self.assertEquals(self.capture('unknowns'), '')
124
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
126
self.assertEquals(list(b.unknowns()), [])
127
assert file('.bzrignore', 'rb').read() == '*.blah\n'
126
129
# 'ignore' works when then .bzrignore file already exists
127
130
file('garh', 'wt').write('garh')
128
self.assertEquals(self.capture('unknowns'), 'garh\n')
131
self.assertEquals(list(b.unknowns()), ['garh'])
132
assert self.backtick('bzr unknowns') == 'garh\n'
129
133
self.runbzr('ignore garh')
130
self.assertEquals(self.capture('unknowns'), '')
131
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
133
def test_revert(self):
136
file('hello', 'wt').write('foo')
137
self.runbzr('add hello')
138
self.runbzr('commit -m setup hello')
140
file('goodbye', 'wt').write('baz')
141
self.runbzr('add goodbye')
142
self.runbzr('commit -m setup goodbye')
144
file('hello', 'wt').write('bar')
145
file('goodbye', 'wt').write('qux')
146
self.runbzr('revert hello')
147
self.check_file_contents('hello', 'foo')
148
self.check_file_contents('goodbye', 'qux')
149
self.runbzr('revert')
150
self.check_file_contents('goodbye', 'baz')
152
os.mkdir('revertdir')
153
self.runbzr('add revertdir')
154
self.runbzr('commit -m f')
155
os.rmdir('revertdir')
156
self.runbzr('revert')
159
os.symlink('/unlikely/to/exist', 'symlink')
160
self.runbzr('add symlink')
161
self.runbzr('commit -m f')
163
self.runbzr('revert')
164
self.failUnlessExists('symlink')
166
os.symlink('a-different-path', 'symlink')
167
self.runbzr('revert')
168
self.assertEqual('/unlikely/to/exist',
169
os.readlink('symlink'))
171
self.log("skipping revert symlink tests")
173
file('hello', 'wt').write('xyz')
174
self.runbzr('commit -m xyz hello')
175
self.runbzr('revert -r 1 hello')
176
self.check_file_contents('hello', 'foo')
177
self.runbzr('revert hello')
178
self.check_file_contents('hello', 'xyz')
179
os.chdir('revertdir')
180
self.runbzr('revert')
183
def test_mv_modes(self):
184
"""Test two modes of operation for mv"""
186
self.build_tree(['a', 'c', 'subdir/'])
187
self.run_bzr_captured(['add', self.test_dir])
188
self.run_bzr_captured(['mv', 'a', 'b'])
189
self.run_bzr_captured(['mv', 'b', 'subdir'])
190
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
191
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
192
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
194
def test_main_version(self):
195
"""Check output from version command and master option is reasonable"""
196
# output is intentionally passed through to stdout so that we
197
# can see the version being tested
198
output = self.runbzr('version', backtick=1)
199
self.log('bzr version output:')
201
self.assert_(output.startswith('bzr (bazaar-ng) '))
202
self.assertNotEqual(output.index('Canonical'), -1)
203
# make sure --version is consistent
204
tmp_output = self.runbzr('--version', backtick=1)
205
self.log('bzr --version output:')
207
self.assertEquals(output, tmp_output)
209
def example_branch(test):
211
file('hello', 'wt').write('foo')
212
test.runbzr('add hello')
213
test.runbzr('commit -m setup hello')
214
file('goodbye', 'wt').write('baz')
215
test.runbzr('add goodbye')
216
test.runbzr('commit -m setup goodbye')
218
def test_export(self):
221
self.example_branch()
222
self.runbzr('export ../latest')
223
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
224
self.runbzr('export ../first -r 1')
225
self.assert_(not os.path.exists('../first/goodbye'))
226
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
227
self.runbzr('export ../first.gz -r 1')
228
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
229
self.runbzr('export ../first.bz2 -r 1')
230
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
232
from tarfile import TarFile
233
self.runbzr('export ../first.tar -r 1')
234
self.assert_(os.path.isfile('../first.tar'))
235
tf = TarFile('../first.tar')
236
self.assert_('first/hello' in tf.getnames(), tf.getnames())
237
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
238
self.runbzr('export ../first.tar.gz -r 1')
239
self.assert_(os.path.isfile('../first.tar.gz'))
240
self.runbzr('export ../first.tbz2 -r 1')
241
self.assert_(os.path.isfile('../first.tbz2'))
242
self.runbzr('export ../first.tar.bz2 -r 1')
243
self.assert_(os.path.isfile('../first.tar.bz2'))
244
self.runbzr('export ../first.tar.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tar.tbz2'))
247
from bz2 import BZ2File
248
tf = TarFile('../first.tar.tbz2',
249
fileobj=BZ2File('../first.tar.tbz2', 'r'))
250
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
251
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
252
self.runbzr('export ../first2.tar -r 1 --root pizza')
253
tf = TarFile('../first2.tar')
254
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
256
from zipfile import ZipFile
257
self.runbzr('export ../first.zip -r 1')
258
self.failUnlessExists('../first.zip')
259
zf = ZipFile('../first.zip')
260
self.assert_('first/hello' in zf.namelist(), zf.namelist())
261
self.assertEqual(zf.read('first/hello'), 'foo')
263
self.runbzr('export ../first2.zip -r 1 --root pizza')
264
zf = ZipFile('../first2.zip')
265
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
267
self.runbzr('export ../first-zip --format=zip -r 1')
268
zf = ZipFile('../first-zip')
269
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
271
def test_inventory(self):
273
def output_equals(value, *args):
274
out = self.runbzr(['inventory'] + list(args), backtick=True)
275
self.assertEquals(out, value)
278
open('a', 'wb').write('hello\n')
284
output_equals('a\n', '--kind', 'file')
285
output_equals('b\n', '--kind', 'directory')
288
"""Test the abilities of 'bzr ls'"""
290
def bzrout(*args, **kwargs):
291
kwargs['backtick'] = True
292
return self.runbzr(*args, **kwargs)
294
def ls_equals(value, *args):
295
out = self.runbzr(['ls'] + list(args), backtick=True)
296
self.assertEquals(out, value)
299
open('a', 'wb').write('hello\n')
302
bzr('ls --verbose --null', retcode=3)
305
ls_equals('? a\n', '--verbose')
306
ls_equals('a\n', '--unknown')
307
ls_equals('', '--ignored')
308
ls_equals('', '--versioned')
309
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
310
ls_equals('', '--ignored', '--versioned')
311
ls_equals('a\0', '--null')
314
ls_equals('V a\n', '--verbose')
321
open('subdir/b', 'wb').write('b\n')
327
bzr('commit -m subdir')
335
, '--verbose', '--non-recursive')
337
# Check what happens in a sub-directory
349
, '--from-root', '--null')
352
, '--from-root', '--non-recursive')
356
# Check what happens when we supply a specific revision
357
ls_equals('a\n', '--revision', '1')
359
, '--verbose', '--revision', '1')
362
ls_equals('', '--revision', '1')
364
# Now try to do ignored files.
366
open('blah.py', 'wb').write('unknown\n')
367
open('blah.pyo', 'wb').write('ignored\n')
379
ls_equals('blah.pyo\n'
381
ls_equals('blah.py\n'
390
file("myfile", "wb").write("My contents\n")
392
self.runbzr('commit -m myfile')
393
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
395
def test_pull_verbose(self):
396
"""Pull changes from one branch to another and watch the output."""
402
self.example_branch()
407
open('b', 'wb').write('else\n')
409
bzr(['commit', '-m', 'added b'])
412
out = bzr('pull --verbose ../b', backtick=True)
413
self.failIfEqual(out.find('Added Revisions:'), -1)
414
self.failIfEqual(out.find('message:\n added b'), -1)
415
self.failIfEqual(out.find('added b'), -1)
417
# Check that --overwrite --verbose prints out the removed entries
418
bzr('commit -m foo --unchanged')
420
bzr('commit -m baz --unchanged')
421
bzr('pull ../a', retcode=3)
422
out = bzr('pull --overwrite --verbose ../a', backtick=1)
424
remove_loc = out.find('Removed Revisions:')
425
self.failIfEqual(remove_loc, -1)
426
added_loc = out.find('Added Revisions:')
427
self.failIfEqual(added_loc, -1)
429
removed_message = out.find('message:\n baz')
430
self.failIfEqual(removed_message, -1)
431
self.failUnless(remove_loc < removed_message < added_loc)
433
added_message = out.find('message:\n foo')
434
self.failIfEqual(added_message, -1)
435
self.failUnless(added_loc < added_message)
437
def test_locations(self):
438
"""Using and remembering different locations"""
442
self.runbzr('commit -m unchanged --unchanged')
443
self.runbzr('pull', retcode=3)
444
self.runbzr('merge', retcode=3)
445
self.runbzr('branch . ../b')
448
self.runbzr('branch . ../c')
449
self.runbzr('pull ../c')
452
self.runbzr('pull ../b')
454
self.runbzr('pull ../c')
455
self.runbzr('branch ../c ../d')
461
self.runbzr('pull', retcode=3)
462
self.runbzr('pull ../a --remember')
465
def test_unknown_command(self):
466
"""Handling of unknown command."""
467
out, err = self.run_bzr_captured(['fluffy-badger'],
469
self.assertEquals(out, '')
470
err.index('unknown command')
472
def create_conflicts(self):
473
"""Create a conflicted tree"""
476
file('hello', 'wb').write("hi world")
477
file('answer', 'wb').write("42")
480
self.runbzr('commit -m base')
481
self.runbzr('branch . ../other')
482
self.runbzr('branch . ../this')
484
file('hello', 'wb').write("Hello.")
485
file('answer', 'wb').write("Is anyone there?")
486
self.runbzr('commit -m other')
488
file('hello', 'wb').write("Hello, world")
489
self.runbzr('mv answer question')
490
file('question', 'wb').write("What do you get when you multiply six"
492
self.runbzr('commit -m this')
494
def test_remerge(self):
495
"""Remerge command works as expected"""
496
self.create_conflicts()
497
self.runbzr('merge ../other --show-base', retcode=1)
498
conflict_text = file('hello').read()
499
assert '|||||||' in conflict_text
500
assert 'hi world' in conflict_text
501
self.runbzr('remerge', retcode=1)
502
conflict_text = file('hello').read()
503
assert '|||||||' not in conflict_text
504
assert 'hi world' not in conflict_text
505
os.unlink('hello.OTHER')
506
os.unlink('question.OTHER')
507
self.runbzr('remerge jello --merge-type weave', retcode=3)
508
self.runbzr('remerge hello --merge-type weave', retcode=1)
509
assert os.path.exists('hello.OTHER')
510
self.assertIs(False, os.path.exists('question.OTHER'))
511
file_id = self.runbzr('file-id hello')
512
file_id = self.runbzr('file-id hello.THIS', retcode=3)
513
self.runbzr('remerge --merge-type weave', retcode=1)
514
assert os.path.exists('hello.OTHER')
515
assert not os.path.exists('hello.BASE')
516
assert '|||||||' not in conflict_text
517
assert 'hi world' not in conflict_text
518
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
519
self.runbzr('remerge . --show-base --reprocess', retcode=3)
520
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
521
self.runbzr('remerge hello --show-base', retcode=1)
522
self.runbzr('remerge hello --reprocess', retcode=1)
523
self.runbzr('resolve --all')
524
self.runbzr('commit -m done',)
525
self.runbzr('remerge', retcode=3)
527
def test_status(self):
531
self.runbzr('commit --unchanged --message f')
532
self.runbzr('branch . ../branch2')
533
self.runbzr('branch . ../branch3')
534
self.runbzr('commit --unchanged --message peter')
535
os.chdir('../branch2')
536
self.runbzr('merge ../branch1')
537
self.runbzr('commit --unchanged --message pumpkin')
538
os.chdir('../branch3')
539
self.runbzr('merge ../branch2')
540
message = self.capture('status')
543
def test_conflicts(self):
544
"""Handling of merge conflicts"""
545
self.create_conflicts()
546
self.runbzr('merge ../other --show-base', retcode=1)
547
conflict_text = file('hello').read()
548
self.assert_('<<<<<<<' in conflict_text)
549
self.assert_('>>>>>>>' in conflict_text)
550
self.assert_('=======' in conflict_text)
551
self.assert_('|||||||' in conflict_text)
552
self.assert_('hi world' in conflict_text)
553
self.runbzr('revert')
554
self.runbzr('resolve --all')
555
self.runbzr('merge ../other', retcode=1)
556
conflict_text = file('hello').read()
557
self.assert_('|||||||' not in conflict_text)
558
self.assert_('hi world' not in conflict_text)
559
result = self.runbzr('conflicts', backtick=1)
560
self.assertEquals(result, "Text conflict in hello\nText conflict in"
562
result = self.runbzr('status', backtick=1)
563
self.assert_("conflicts:\n Text conflict in hello\n"
564
" Text conflict in question\n" in result, result)
565
self.runbzr('resolve hello')
566
result = self.runbzr('conflicts', backtick=1)
567
self.assertEquals(result, "Text conflict in question\n")
568
self.runbzr('commit -m conflicts', retcode=3)
569
self.runbzr('resolve --all')
570
result = self.runbzr('conflicts', backtick=1)
571
self.runbzr('commit -m conflicts')
572
self.assertEquals(result, "")
575
# create a source branch
576
os.mkdir('my-branch')
577
os.chdir('my-branch')
578
self.example_branch()
580
# with no push target, fail
581
self.runbzr('push', retcode=3)
582
# with an explicit target work
583
self.runbzr('push ../output-branch')
584
# with an implicit target work
587
self.runbzr('missing ../output-branch')
588
# advance this branch
589
self.runbzr('commit --unchanged -m unchanged')
591
os.chdir('../output-branch')
592
# There is no longer a difference as long as we have
593
# access to the working tree
596
# But we should be missing a revision
597
self.runbzr('missing ../my-branch', retcode=1)
599
# diverge the branches
600
self.runbzr('commit --unchanged -m unchanged')
601
os.chdir('../my-branch')
603
self.runbzr('push', retcode=3)
604
# and there are difference
605
self.runbzr('missing ../output-branch', retcode=1)
606
self.runbzr('missing --verbose ../output-branch', retcode=1)
607
# but we can force a push
608
self.runbzr('push --overwrite')
610
self.runbzr('missing ../output-branch')
612
# pushing to a new dir with no parent should fail
613
self.runbzr('push ../missing/new-branch', retcode=3)
614
# unless we provide --create-prefix
615
self.runbzr('push --create-prefix ../missing/new-branch')
617
self.runbzr('missing ../missing/new-branch')
619
def test_external_command(self):
620
"""Test that external commands can be run by setting the path
622
# We don't at present run bzr in a subprocess for blackbox tests, and so
623
# don't really capture stdout, only the internal python stream.
624
# Therefore we don't use a subcommand that produces any output or does
625
# anything -- we just check that it can be run successfully.
626
cmd_name = 'test-command'
627
if sys.platform == 'win32':
629
oldpath = os.environ.get('BZRPATH', None)
632
if os.environ.has_key('BZRPATH'):
633
del os.environ['BZRPATH']
635
f = file(cmd_name, 'wb')
636
if sys.platform == 'win32':
637
f.write('@echo off\n')
639
f.write('#!/bin/sh\n')
640
# f.write('echo Hello from test-command')
642
os.chmod(cmd_name, 0755)
644
# It should not find the command in the local
645
# directory by default, since it is not in my path
646
bzr(cmd_name, retcode=3)
648
# Now put it into my path
649
os.environ['BZRPATH'] = '.'
653
# Make sure empty path elements are ignored
654
os.environ['BZRPATH'] = os.pathsep
656
bzr(cmd_name, retcode=3)
660
os.environ['BZRPATH'] = oldpath
663
def listdir_sorted(dir):
134
self.assertEquals(list(b.unknowns()), [])
135
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
669
140
class OldTests(ExternalBase):
670
"""old tests moved from ./testbzr."""
141
# old tests moved from ./testbzr
673
143
from os import chdir, mkdir
674
144
from os.path import exists
676
147
runbzr = self.runbzr
677
capture = self.capture
148
backtick = self.backtick
678
149
progress = self.log
680
151
progress("basic branch creation")
691
162
f.write('hello world!\n')
694
self.assertEquals(capture('unknowns'), 'test.txt\n')
696
out = capture("status")
697
self.assertEquals(out, 'unknown:\n test.txt\n')
165
out = backtick("bzr unknowns")
166
self.assertEquals(out, 'test.txt\n')
168
out = backtick("bzr status")
169
assert out == 'unknown:\n test.txt\n'
171
out = backtick("bzr status --all")
172
assert out == "unknown:\n test.txt\n"
174
out = backtick("bzr status test.txt --all")
175
assert out == "unknown:\n test.txt\n"
699
177
f = file('test2.txt', 'wt')
700
178
f.write('goodbye cruel world...\n')
703
out = capture("status test.txt")
704
self.assertEquals(out, "unknown:\n test.txt\n")
181
out = backtick("bzr status test.txt")
182
assert out == "unknown:\n test.txt\n"
706
out = capture("status")
707
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
184
out = backtick("bzr status")
185
assert out == ("unknown:\n"
709
189
os.unlink('test2.txt')
711
191
progress("command aliases")
713
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
192
out = backtick("bzr st --all")
193
assert out == ("unknown:\n"
715
out = capture("stat")
716
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
196
out = backtick("bzr stat")
197
assert out == ("unknown:\n"
718
200
progress("command help")
719
201
runbzr("help st")
721
203
runbzr("help commands")
722
runbzr("help slartibartfast", 3)
204
runbzr("help slartibartfast", 1)
724
out = capture("help ci")
206
out = backtick("bzr help ci")
725
207
out.index('aliases: ')
727
209
progress("can't rename unversioned file")
728
runbzr("rename test.txt new-test.txt", 3)
210
runbzr("rename test.txt new-test.txt", 1)
730
212
progress("adding a file")
732
214
runbzr("add test.txt")
733
self.assertEquals(capture("unknowns"), '')
215
assert backtick("bzr unknowns") == ''
216
assert backtick("bzr status --all") == ("added:\n"
735
219
progress("rename newly-added file")
736
220
runbzr("rename test.txt hello.txt")
737
self.assert_(os.path.exists("hello.txt"))
738
self.assert_(not os.path.exists("test.txt"))
221
assert os.path.exists("hello.txt")
222
assert not os.path.exists("test.txt")
740
self.assertEquals(capture("revno"), '0\n')
224
assert backtick("bzr revno") == '0\n'
742
226
progress("add first revision")
743
227
runbzr(['commit', '-m', 'add first revision'])
745
229
progress("more complex renames")
747
runbzr("rename hello.txt sub1", 3)
748
runbzr("rename hello.txt sub1/hello.txt", 3)
749
runbzr("move hello.txt sub1", 3)
231
runbzr("rename hello.txt sub1", 1)
232
runbzr("rename hello.txt sub1/hello.txt", 1)
233
runbzr("move hello.txt sub1", 1)
751
235
runbzr("add sub1")
752
236
runbzr("rename sub1 sub2")
753
237
runbzr("move hello.txt sub2")
754
self.assertEqual(capture("relpath sub2/hello.txt"),
755
pathjoin("sub2", "hello.txt\n"))
238
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
757
self.assert_(exists("sub2"))
758
self.assert_(exists("sub2/hello.txt"))
759
self.assert_(not exists("sub1"))
760
self.assert_(not exists("hello.txt"))
240
assert exists("sub2")
241
assert exists("sub2/hello.txt")
242
assert not exists("sub1")
243
assert not exists("hello.txt")
762
245
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
765
248
runbzr('add sub1')
766
249
runbzr('move sub2/hello.txt sub1')
767
self.assert_(not exists('sub2/hello.txt'))
768
self.assert_(exists('sub1/hello.txt'))
250
assert not exists('sub2/hello.txt')
251
assert exists('sub1/hello.txt')
769
252
runbzr('move sub2 sub1')
770
self.assert_(not exists('sub2'))
771
self.assert_(exists('sub1/sub2'))
253
assert not exists('sub2')
254
assert exists('sub1/sub2')
773
256
runbzr(['commit', '-m', 'rename nested subdirectories'])
775
258
chdir('sub1/sub2')
776
self.assertEquals(capture('root')[:-1],
777
pathjoin(self.test_dir, 'branch1'))
259
self.assertEquals(backtick('bzr root')[:-1],
260
os.path.join(self.test_dir, 'branch1'))
778
261
runbzr('move ../hello.txt .')
779
self.assert_(exists('./hello.txt'))
780
self.assertEquals(capture('relpath hello.txt'),
781
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
782
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
262
assert exists('./hello.txt')
263
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
264
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
783
265
runbzr(['commit', '-m', 'move to parent directory'])
785
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
267
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
787
269
runbzr('move sub2/hello.txt .')
788
self.assert_(exists('hello.txt'))
270
assert exists('hello.txt')
790
272
f = file('hello.txt', 'wt')
791
273
f.write('some nice new content\n')
794
276
f = file('msg.tmp', 'wt')
795
f.write('this is my new commit\nand it has multiple lines, for fun')
277
f.write('this is my new commit\n')
798
280
runbzr('commit -F msg.tmp')
800
self.assertEquals(capture('revno'), '5\n')
282
assert backtick('bzr revno') == '5\n'
801
283
runbzr('export -r 5 export-5.tmp')
802
284
runbzr('export export.tmp')
806
runbzr('log -v --forward')
807
runbzr('log -m', retcode=3)
808
log_out = capture('log -m commit')
809
self.assert_("this is my new commit\n and" in log_out)
810
self.assert_("rename nested" not in log_out)
811
self.assert_('revision-id' not in log_out)
812
self.assert_('revision-id' in capture('log --show-ids -m commit'))
814
log_out = capture('log --line')
815
# determine the widest line we want
816
max_width = terminal_width() - 1
817
for line in log_out.splitlines():
818
self.assert_(len(line) <= max_width, len(line))
819
self.assert_("this is my new commit and" not in log_out)
820
self.assert_("this is my new commit" in log_out)
822
291
progress("file with spaces in name")
823
292
mkdir('sub directory')
824
293
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
826
runbzr('diff', retcode=1)
827
296
runbzr('commit -m add-spaces')
840
os.symlink("NOWHERE1", "link1")
842
self.assertEquals(self.capture('unknowns'), '')
843
runbzr(['commit', '-m', '1: added symlink link1'])
847
self.assertEquals(self.capture('unknowns'), '')
848
os.symlink("NOWHERE2", "d1/link2")
849
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
850
# is d1/link2 found when adding d1
852
self.assertEquals(self.capture('unknowns'), '')
853
os.symlink("NOWHERE3", "d1/link3")
854
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
855
runbzr(['commit', '-m', '2: added dir, symlink'])
857
runbzr('rename d1 d2')
858
runbzr('move d2/link2 .')
859
runbzr('move link1 d2')
860
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
861
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
862
runbzr('add d2/link3')
863
runbzr('diff', retcode=1)
864
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
867
os.symlink("TARGET 2", "link2")
868
os.unlink("d2/link1")
869
os.symlink("TARGET 1", "d2/link1")
870
runbzr('diff', retcode=1)
871
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
872
runbzr(['commit', '-m', '4: retarget of two links'])
874
runbzr('remove d2/link1')
875
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
876
runbzr(['commit', '-m', '5: remove d2/link1'])
877
# try with the rm alias
878
runbzr('add d2/link1')
879
runbzr(['commit', '-m', '6: add d2/link1'])
880
runbzr('rm d2/link1')
881
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
882
runbzr(['commit', '-m', '7: remove d2/link1'])
886
runbzr('rename d2/link3 d1/link3new')
887
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
888
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
892
runbzr(['export', '-r', '1', 'exp1.tmp'])
894
self.assertEquals(listdir_sorted("."), [ "link1" ])
895
self.assertEquals(os.readlink("link1"), "NOWHERE1")
898
runbzr(['export', '-r', '2', 'exp2.tmp'])
900
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
903
runbzr(['export', '-r', '3', 'exp3.tmp'])
905
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
906
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
907
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
908
self.assertEquals(os.readlink("link2") , "NOWHERE2")
911
runbzr(['export', '-r', '4', 'exp4.tmp'])
913
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
914
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
915
self.assertEquals(os.readlink("link2") , "TARGET 2")
916
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
919
runbzr(['export', '-r', '5', 'exp5.tmp'])
921
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
922
self.assert_(os.path.islink("link2"))
923
self.assert_(listdir_sorted("d2")== [ "link3" ])
926
runbzr(['export', '-r', '8', 'exp6.tmp'])
928
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
929
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
930
self.assertEquals(listdir_sorted("d2"), [])
931
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
934
progress("skipping symlink tests")
937
class RemoteTests(object):
938
"""Test bzr ui commands against remote branches."""
940
def test_branch(self):
942
wt = self.make_branch_and_tree('from')
944
wt.commit('empty commit for nonsense', allow_pointless=True)
945
url = self.get_readonly_url('from')
946
self.run_bzr('branch', url, 'to')
947
branch = Branch.open('to')
948
self.assertEqual(1, len(branch.revision_history()))
949
# the branch should be set in to to from
950
self.assertEqual(url + '/', branch.get_parent())
953
self.build_tree(['branch/', 'branch/file'])
954
self.capture('init branch')
955
self.capture('add branch/file')
956
self.capture('commit -m foo branch')
957
url = self.get_readonly_url('branch/file')
958
output = self.capture('log %s' % url)
959
self.assertEqual(8, len(output.split('\n')))
312
assert os.path.exists('branch1')
313
assert not os.path.exists('branch2')
314
# Can't create a branch if it already exists
315
runbzr('branch branch1', retcode=1)
316
# Can't create a branch if its parent doesn't exist
317
runbzr('branch /unlikely/to/exist', retcode=1)
318
runbzr('branch branch1 branch2')
322
runbzr('pull', retcode=1)
323
runbzr('pull ../branch2')
326
runbzr('commit --unchanged -m empty')
328
chdir('../../branch2')
330
runbzr('commit --unchanged -m empty')
332
runbzr('commit --unchanged -m empty')
333
runbzr('pull', retcode=1)
336
progress('status after remove')
337
mkdir('status-after-remove')
338
# see mail from William Dodé, 2005-05-25
339
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
340
# * looking for changes...
345
# bzr: local variable 'kind' referenced before assignment
346
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
347
# see ~/.bzr.log for debug information
348
chdir('status-after-remove')
350
file('a', 'w').write('foo')
352
runbzr(['commit', '-m', 'add a'])
360
progress("recursive and non-recursive add")
365
fp = os.path.join('foo', 'test.txt')
369
runbzr('add --no-recurse foo')
370
runbzr('file-id foo')
371
runbzr('file-id ' + fp, 1) # not versioned yet
372
runbzr('commit -m add-dir-only')
374
self.runbzr('file-id ' + fp, 1) # still not versioned
376
self.runbzr('add foo')
377
self.runbzr('file-id ' + fp)
378
self.runbzr('commit -m add-sub-file')
384
class RevertCommand(ExternalBase):
388
file('hello', 'wt').write('foo')
389
self.runbzr('add hello')
390
self.runbzr('commit -m setup hello')
961
def test_check(self):
962
self.build_tree(['branch/', 'branch/file'])
963
self.capture('init branch')
964
self.capture('add branch/file')
965
self.capture('commit -m foo branch')
966
url = self.get_readonly_url('branch/')
967
self.run_bzr('check', url)
970
# create a source branch
971
os.mkdir('my-branch')
972
os.chdir('my-branch')
974
file('hello', 'wt').write('foo')
975
self.run_bzr('add', 'hello')
976
self.run_bzr('commit', '-m', 'setup')
978
# with an explicit target work
979
self.run_bzr('push', self.get_url('output-branch'))
982
class HTTPTests(TestCaseWithWebserver, RemoteTests):
983
"""Test various commands against a HTTP server."""
986
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
987
"""Test various commands against a SFTP server using abs paths."""
990
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
991
"""Test various commands against a SFTP server using abs paths."""
994
super(SFTPTestsAbsoluteSibling, self).setUp()
995
self._override_home = '/dev/noone/runs/tests/here'
998
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
999
"""Test various commands against a SFTP server using homedir rel paths."""
1002
super(SFTPTestsRelative, self).setUp()
1003
self._get_remote_is_absolute = False
392
file('hello', 'wt').write('bar')
393
self.runbzr('revert hello')
394
self.check_file_contents('hello', 'foo')