64
74
def test_whoami_branch(self):
65
75
"""branch specific user identity works."""
66
76
self.runbzr('init')
67
b = bzrlib.branch.Branch.open('.')
68
b.control_files.put_utf8('email', 'Branch Identity <branch@identi.ty>')
69
bzr_email = os.environ.get('BZREMAIL')
70
if bzr_email is not None:
71
del os.environ['BZREMAIL']
77
f = file('.bzr/email', 'wt')
78
f.write('Branch Identity <branch@identi.ty>')
72
80
whoami = self.runbzr("whoami",backtick=True)
73
81
whoami_email = self.runbzr("whoami --email",backtick=True)
74
82
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
75
83
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
76
# Verify that the environment variable overrides the value
78
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
79
whoami = self.runbzr("whoami",backtick=True)
80
whoami_email = self.runbzr("whoami --email",backtick=True)
81
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
82
self.assertTrue(whoami_email.startswith('other@environ.ment'))
83
if bzr_email is not None:
84
os.environ['BZREMAIL'] = bzr_email
86
def test_nick_command(self):
87
"""bzr nick for viewing, setting nicknames"""
91
nick = self.runbzr("nick",backtick=True)
92
self.assertEqual(nick, 'me.dev\n')
93
nick = self.runbzr("nick moo")
94
nick = self.runbzr("nick",backtick=True)
95
self.assertEqual(nick, 'moo\n')
97
85
def test_invalid_commands(self):
98
self.runbzr("pants", retcode=3)
99
self.runbzr("--pants off", retcode=3)
100
self.runbzr("diff --message foo", retcode=3)
86
self.runbzr("pants", retcode=1)
87
self.runbzr("--pants off", retcode=1)
88
self.runbzr("diff --message foo", retcode=1)
102
def test_remove_deleted(self):
90
def test_empty_commit(self):
103
91
self.runbzr("init")
104
self.build_tree(['a'])
105
self.runbzr(['add', 'a'])
106
self.runbzr(['commit', '-m', 'added a'])
108
self.runbzr(['remove', 'a'])
92
self.build_tree(['hello.txt'])
93
self.runbzr("commit -m empty", retcode=1)
94
self.runbzr("add hello.txt")
95
self.runbzr("commit -m added")
110
97
def test_ignore_patterns(self):
112
self.assertEquals(self.capture('unknowns'), '')
98
from bzrlib.branch import Branch
100
b = Branch('.', init=True)
101
self.assertEquals(list(b.unknowns()), [])
114
103
file('foo.tmp', 'wt').write('tmp files are ignored')
115
self.assertEquals(self.capture('unknowns'), '')
104
self.assertEquals(list(b.unknowns()), [])
105
assert self.backtick('bzr unknowns') == ''
117
107
file('foo.c', 'wt').write('int main() {}')
118
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
108
self.assertEquals(list(b.unknowns()), ['foo.c'])
109
assert self.backtick('bzr unknowns') == 'foo.c\n'
120
111
self.runbzr(['add', 'foo.c'])
121
self.assertEquals(self.capture('unknowns'), '')
112
assert self.backtick('bzr unknowns') == ''
123
114
# 'ignore' works when creating the .bzignore file
124
115
file('foo.blah', 'wt').write('blah')
125
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
116
self.assertEquals(list(b.unknowns()), ['foo.blah'])
126
117
self.runbzr('ignore *.blah')
127
self.assertEquals(self.capture('unknowns'), '')
128
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
118
self.assertEquals(list(b.unknowns()), [])
119
assert file('.bzrignore', 'rb').read() == '*.blah\n'
130
121
# 'ignore' works when then .bzrignore file already exists
131
122
file('garh', 'wt').write('garh')
132
self.assertEquals(self.capture('unknowns'), 'garh\n')
123
self.assertEquals(list(b.unknowns()), ['garh'])
124
assert self.backtick('bzr unknowns') == 'garh\n'
133
125
self.runbzr('ignore garh')
134
self.assertEquals(self.capture('unknowns'), '')
135
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
126
self.assertEquals(list(b.unknowns()), [])
127
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
137
129
def test_revert(self):
138
131
self.runbzr('init')
140
133
file('hello', 'wt').write('foo')
210
178
self.log(tmp_output)
211
179
self.assertEquals(output, tmp_output)
213
def example_branch(test):
215
file('hello', 'wt').write('foo')
216
test.runbzr('add hello')
217
test.runbzr('commit -m setup hello')
218
file('goodbye', 'wt').write('baz')
219
test.runbzr('add goodbye')
220
test.runbzr('commit -m setup goodbye')
222
def test_export(self):
225
self.example_branch()
226
self.runbzr('export ../latest')
227
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
228
self.runbzr('export ../first -r 1')
229
self.assert_(not os.path.exists('../first/goodbye'))
230
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
231
self.runbzr('export ../first.gz -r 1')
232
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
233
self.runbzr('export ../first.bz2 -r 1')
234
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
236
from tarfile import TarFile
237
self.runbzr('export ../first.tar -r 1')
238
self.assert_(os.path.isfile('../first.tar'))
239
tf = TarFile('../first.tar')
240
self.assert_('first/hello' in tf.getnames(), tf.getnames())
241
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
self.runbzr('export ../first.tar.gz -r 1')
243
self.assert_(os.path.isfile('../first.tar.gz'))
244
self.runbzr('export ../first.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tbz2'))
246
self.runbzr('export ../first.tar.bz2 -r 1')
247
self.assert_(os.path.isfile('../first.tar.bz2'))
248
self.runbzr('export ../first.tar.tbz2 -r 1')
249
self.assert_(os.path.isfile('../first.tar.tbz2'))
251
from bz2 import BZ2File
252
tf = TarFile('../first.tar.tbz2',
253
fileobj=BZ2File('../first.tar.tbz2', 'r'))
254
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
255
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
256
self.runbzr('export ../first2.tar -r 1 --root pizza')
257
tf = TarFile('../first2.tar')
258
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
260
from zipfile import ZipFile
261
self.runbzr('export ../first.zip -r 1')
262
self.failUnlessExists('../first.zip')
263
zf = ZipFile('../first.zip')
264
self.assert_('first/hello' in zf.namelist(), zf.namelist())
265
self.assertEqual(zf.read('first/hello'), 'foo')
267
self.runbzr('export ../first2.zip -r 1 --root pizza')
268
zf = ZipFile('../first2.zip')
269
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
271
self.runbzr('export ../first-zip --format=zip -r 1')
272
zf = ZipFile('../first-zip')
273
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
275
def test_branch(self):
276
"""Branch from one branch to another."""
279
self.example_branch()
281
self.runbzr('branch a b')
282
b = bzrlib.branch.Branch.open('b')
283
self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
284
self.runbzr('branch a c -r 1')
286
self.runbzr('commit -m foo --unchanged')
289
def test_branch_basis(self):
290
# ensure that basis really does grab from the basis by having incomplete source
291
tree = self.make_branch_and_tree('commit_tree')
292
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
294
tree.commit('revision 1', rev_id='1')
295
source = self.make_branch_and_tree('source')
296
# this gives us an incomplete repository
297
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
298
tree.commit('revision 2', rev_id='2', allow_pointless=True)
299
tree.bzrdir.open_branch().copy_content_into(source.branch)
300
tree.copy_content_into(source)
301
self.assertFalse(source.branch.repository.has_revision('2'))
303
self.runbzr('branch source target --basis commit_tree')
304
target = bzrdir.BzrDir.open('target')
305
self.assertEqual('2', target.open_branch().last_revision())
306
self.assertEqual('2', target.open_workingtree().last_revision())
307
self.assertTrue(target.open_branch().repository.has_revision('2'))
309
def test_inventory(self):
311
def output_equals(value, *args):
312
out = self.runbzr(['inventory'] + list(args), backtick=True)
313
self.assertEquals(out, value)
316
open('a', 'wb').write('hello\n')
322
output_equals('a\n', '--kind', 'file')
323
output_equals('b\n', '--kind', 'directory')
326
"""Test the abilities of 'bzr ls'"""
328
def bzrout(*args, **kwargs):
329
kwargs['backtick'] = True
330
return self.runbzr(*args, **kwargs)
332
def ls_equals(value, *args):
333
out = self.runbzr(['ls'] + list(args), backtick=True)
334
self.assertEquals(out, value)
337
open('a', 'wb').write('hello\n')
340
bzr('ls --verbose --null', retcode=3)
343
ls_equals('? a\n', '--verbose')
344
ls_equals('a\n', '--unknown')
345
ls_equals('', '--ignored')
346
ls_equals('', '--versioned')
347
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
348
ls_equals('', '--ignored', '--versioned')
349
ls_equals('a\0', '--null')
352
ls_equals('V a\n', '--verbose')
359
open('subdir/b', 'wb').write('b\n')
365
bzr('commit -m subdir')
373
, '--verbose', '--non-recursive')
375
# Check what happens in a sub-directory
387
, '--from-root', '--null')
390
, '--from-root', '--non-recursive')
394
# Check what happens when we supply a specific revision
395
ls_equals('a\n', '--revision', '1')
397
, '--verbose', '--revision', '1')
400
ls_equals('', '--revision', '1')
402
# Now try to do ignored files.
404
open('blah.py', 'wb').write('unknown\n')
405
open('blah.pyo', 'wb').write('ignored\n')
417
ls_equals('blah.pyo\n'
419
ls_equals('blah.py\n'
428
file("myfile", "wb").write("My contents\n")
430
self.runbzr('commit -m myfile')
431
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
433
def test_pull_verbose(self):
434
"""Pull changes from one branch to another and watch the output."""
440
self.example_branch()
445
open('b', 'wb').write('else\n')
447
bzr(['commit', '-m', 'added b'])
450
out = bzr('pull --verbose ../b', backtick=True)
451
self.failIfEqual(out.find('Added Revisions:'), -1)
452
self.failIfEqual(out.find('message:\n added b'), -1)
453
self.failIfEqual(out.find('added b'), -1)
455
# Check that --overwrite --verbose prints out the removed entries
456
bzr('commit -m foo --unchanged')
458
bzr('commit -m baz --unchanged')
459
bzr('pull ../a', retcode=3)
460
out = bzr('pull --overwrite --verbose ../a', backtick=1)
462
remove_loc = out.find('Removed Revisions:')
463
self.failIfEqual(remove_loc, -1)
464
added_loc = out.find('Added Revisions:')
465
self.failIfEqual(added_loc, -1)
467
removed_message = out.find('message:\n baz')
468
self.failIfEqual(removed_message, -1)
469
self.failUnless(remove_loc < removed_message < added_loc)
471
added_message = out.find('message:\n foo')
472
self.failIfEqual(added_message, -1)
473
self.failUnless(added_loc < added_message)
475
def test_locations(self):
476
"""Using and remembering different locations"""
480
self.runbzr('commit -m unchanged --unchanged')
481
self.runbzr('pull', retcode=3)
482
self.runbzr('merge', retcode=3)
483
self.runbzr('branch . ../b')
486
self.runbzr('branch . ../c')
487
self.runbzr('pull ../c')
490
self.runbzr('pull ../b')
492
self.runbzr('pull ../c')
493
self.runbzr('branch ../c ../d')
494
shutil.rmtree('../c')
499
self.runbzr('pull', retcode=3)
500
self.runbzr('pull ../a --remember')
503
def test_add_reports(self):
504
"""add command prints the names of added files."""
506
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
507
out = self.run_bzr_captured(['add'], retcode=0)[0]
508
# the ordering is not defined at the moment
509
results = sorted(out.rstrip('\n').split('\n'))
510
self.assertEquals(['If you wish to add some of these files, please'\
511
' add them by name.',
515
'ignored 1 file(s) matching "CVS"'],
517
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
518
results = sorted(out.rstrip('\n').split('\n'))
519
self.assertEquals(['If you wish to add some of these files, please'\
520
' add them by name.',
521
'ignored CVS matching "CVS"'],
524
def test_add_quiet_is(self):
525
"""add -q does not print the names of added files."""
527
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
528
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
529
# the ordering is not defined at the moment
530
results = sorted(out.rstrip('\n').split('\n'))
531
self.assertEquals([''], results)
533
def test_add_in_unversioned(self):
534
"""Try to add a file in an unversioned directory.
536
"bzr add" should add the parent(s) as necessary.
539
self.build_tree(['inertiatic/', 'inertiatic/esp'])
540
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
541
self.run_bzr('add', 'inertiatic/esp')
542
self.assertEquals(self.capture('unknowns'), '')
544
# Multiple unversioned parents
545
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
546
self.assertEquals(self.capture('unknowns'), 'veil\n')
547
self.run_bzr('add', 'veil/cerpin/taxt')
548
self.assertEquals(self.capture('unknowns'), '')
550
# Check whacky paths work
551
self.build_tree(['cicatriz/', 'cicatriz/esp'])
552
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
553
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
554
self.assertEquals(self.capture('unknowns'), '')
556
def test_add_in_versioned(self):
557
"""Try to add a file in a versioned directory.
559
"bzr add" should do this happily.
562
self.build_tree(['inertiatic/', 'inertiatic/esp'])
563
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
564
self.run_bzr('add', '--no-recurse', 'inertiatic')
565
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
566
self.run_bzr('add', 'inertiatic/esp')
567
self.assertEquals(self.capture('unknowns'), '')
569
def test_subdir_add(self):
570
"""Add in subdirectory should add only things from there down"""
571
from bzrlib.workingtree import WorkingTree
573
eq = self.assertEqual
577
t = self.make_branch_and_tree('.')
579
self.build_tree(['src/', 'README'])
581
eq(sorted(t.unknowns()),
584
self.run_bzr('add', 'src')
586
self.build_tree(['src/foo.c'])
591
self.assertEquals(self.capture('unknowns'), 'README\n')
592
eq(len(t.read_working_inventory()), 3)
596
self.assertEquals(self.capture('unknowns'), '')
597
self.run_bzr('check')
599
def test_unknown_command(self):
600
"""Handling of unknown command."""
601
out, err = self.run_bzr_captured(['fluffy-badger'],
603
self.assertEquals(out, '')
604
err.index('unknown command')
606
def create_conflicts(self):
607
"""Create a conflicted tree"""
610
file('hello', 'wb').write("hi world")
611
file('answer', 'wb').write("42")
614
self.runbzr('commit -m base')
615
self.runbzr('branch . ../other')
616
self.runbzr('branch . ../this')
618
file('hello', 'wb').write("Hello.")
619
file('answer', 'wb').write("Is anyone there?")
620
self.runbzr('commit -m other')
622
file('hello', 'wb').write("Hello, world")
623
self.runbzr('mv answer question')
624
file('question', 'wb').write("What do you get when you multiply six"
626
self.runbzr('commit -m this')
628
def test_remerge(self):
629
"""Remerge command works as expected"""
630
self.create_conflicts()
631
self.runbzr('merge ../other --show-base', retcode=1)
632
conflict_text = file('hello').read()
633
assert '|||||||' in conflict_text
634
assert 'hi world' in conflict_text
635
self.runbzr('remerge', retcode=1)
636
conflict_text = file('hello').read()
637
assert '|||||||' not in conflict_text
638
assert 'hi world' not in conflict_text
639
os.unlink('hello.OTHER')
640
os.unlink('question.OTHER')
641
self.runbzr('remerge jello --merge-type weave', retcode=3)
642
self.runbzr('remerge hello --merge-type weave', retcode=1)
643
assert os.path.exists('hello.OTHER')
644
self.assertIs(False, os.path.exists('question.OTHER'))
645
file_id = self.runbzr('file-id hello')
646
file_id = self.runbzr('file-id hello.THIS', retcode=3)
647
self.runbzr('remerge --merge-type weave', retcode=1)
648
assert os.path.exists('hello.OTHER')
649
assert not os.path.exists('hello.BASE')
650
assert '|||||||' not in conflict_text
651
assert 'hi world' not in conflict_text
652
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
653
self.runbzr('remerge . --show-base --reprocess', retcode=3)
654
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
655
self.runbzr('remerge hello --show-base', retcode=1)
656
self.runbzr('remerge hello --reprocess', retcode=1)
657
self.runbzr('resolve --all')
658
self.runbzr('commit -m done',)
659
self.runbzr('remerge', retcode=3)
661
def test_status(self):
665
self.runbzr('commit --unchanged --message f')
666
self.runbzr('branch . ../branch2')
667
self.runbzr('branch . ../branch3')
668
self.runbzr('commit --unchanged --message peter')
669
os.chdir('../branch2')
670
self.runbzr('merge ../branch1')
671
self.runbzr('commit --unchanged --message pumpkin')
672
os.chdir('../branch3')
673
self.runbzr('merge ../branch2')
674
message = self.capture('status')
677
def test_conflicts(self):
678
"""Handling of merge conflicts"""
679
self.create_conflicts()
680
self.runbzr('merge ../other --show-base', retcode=1)
681
conflict_text = file('hello').read()
682
self.assert_('<<<<<<<' in conflict_text)
683
self.assert_('>>>>>>>' in conflict_text)
684
self.assert_('=======' in conflict_text)
685
self.assert_('|||||||' in conflict_text)
686
self.assert_('hi world' in conflict_text)
687
self.runbzr('revert')
688
self.runbzr('resolve --all')
689
self.runbzr('merge ../other', retcode=1)
690
conflict_text = file('hello').read()
691
self.assert_('|||||||' not in conflict_text)
692
self.assert_('hi world' not in conflict_text)
693
result = self.runbzr('conflicts', backtick=1)
694
self.assertEquals(result, "Text conflict in hello\nText conflict in"
696
result = self.runbzr('status', backtick=1)
697
self.assert_("conflicts:\n Text conflict in hello\n"
698
" Text conflict in question\n" in result, result)
699
self.runbzr('resolve hello')
700
result = self.runbzr('conflicts', backtick=1)
701
self.assertEquals(result, "Text conflict in question\n")
702
self.runbzr('commit -m conflicts', retcode=3)
703
self.runbzr('resolve --all')
704
result = self.runbzr('conflicts', backtick=1)
705
self.runbzr('commit -m conflicts')
706
self.assertEquals(result, "")
709
# create a source branch
710
os.mkdir('my-branch')
711
os.chdir('my-branch')
712
self.example_branch()
714
# with no push target, fail
715
self.runbzr('push', retcode=3)
716
# with an explicit target work
717
self.runbzr('push ../output-branch')
718
# with an implicit target work
721
self.runbzr('missing ../output-branch')
722
# advance this branch
723
self.runbzr('commit --unchanged -m unchanged')
725
os.chdir('../output-branch')
726
# There is no longer a difference as long as we have
727
# access to the working tree
730
# But we should be missing a revision
731
self.runbzr('missing ../my-branch', retcode=1)
733
# diverge the branches
734
self.runbzr('commit --unchanged -m unchanged')
735
os.chdir('../my-branch')
737
self.runbzr('push', retcode=3)
738
# and there are difference
739
self.runbzr('missing ../output-branch', retcode=1)
740
self.runbzr('missing --verbose ../output-branch', retcode=1)
741
# but we can force a push
742
self.runbzr('push --overwrite')
744
self.runbzr('missing ../output-branch')
746
# pushing to a new dir with no parent should fail
747
self.runbzr('push ../missing/new-branch', retcode=3)
748
# unless we provide --create-prefix
749
self.runbzr('push --create-prefix ../missing/new-branch')
751
self.runbzr('missing ../missing/new-branch')
753
def test_external_command(self):
754
"""Test that external commands can be run by setting the path
756
# We don't at present run bzr in a subprocess for blackbox tests, and so
757
# don't really capture stdout, only the internal python stream.
758
# Therefore we don't use a subcommand that produces any output or does
759
# anything -- we just check that it can be run successfully.
760
cmd_name = 'test-command'
761
if sys.platform == 'win32':
763
oldpath = os.environ.get('BZRPATH', None)
766
if os.environ.has_key('BZRPATH'):
767
del os.environ['BZRPATH']
769
f = file(cmd_name, 'wb')
770
if sys.platform == 'win32':
771
f.write('@echo off\n')
773
f.write('#!/bin/sh\n')
774
# f.write('echo Hello from test-command')
776
os.chmod(cmd_name, 0755)
778
# It should not find the command in the local
779
# directory by default, since it is not in my path
780
bzr(cmd_name, retcode=3)
782
# Now put it into my path
783
os.environ['BZRPATH'] = '.'
787
# Make sure empty path elements are ignored
788
os.environ['BZRPATH'] = os.pathsep
790
bzr(cmd_name, retcode=3)
794
os.environ['BZRPATH'] = oldpath
797
def listdir_sorted(dir):
803
181
class OldTests(ExternalBase):
804
"""old tests moved from ./testbzr."""
182
# old tests moved from ./testbzr
806
183
def test_bzr(self):
807
184
from os import chdir, mkdir
808
185
from os.path import exists
810
188
runbzr = self.runbzr
811
capture = self.capture
189
backtick = self.backtick
812
190
progress = self.log
814
192
progress("basic branch creation")
825
203
f.write('hello world!\n')
828
self.assertEquals(capture('unknowns'), 'test.txt\n')
830
out = capture("status")
831
self.assertEquals(out, 'unknown:\n test.txt\n')
833
out = capture("status --all")
834
self.assertEquals(out, "unknown:\n test.txt\n")
836
out = capture("status test.txt --all")
837
self.assertEquals(out, "unknown:\n test.txt\n")
206
out = backtick("bzr unknowns")
207
self.assertEquals(out, 'test.txt\n')
209
out = backtick("bzr status")
210
assert out == 'unknown:\n test.txt\n'
212
out = backtick("bzr status --all")
213
assert out == "unknown:\n test.txt\n"
215
out = backtick("bzr status test.txt --all")
216
assert out == "unknown:\n test.txt\n"
839
218
f = file('test2.txt', 'wt')
840
219
f.write('goodbye cruel world...\n')
843
out = capture("status test.txt")
844
self.assertEquals(out, "unknown:\n test.txt\n")
222
out = backtick("bzr status test.txt")
223
assert out == "unknown:\n test.txt\n"
846
out = capture("status")
847
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
225
out = backtick("bzr status")
226
assert out == ("unknown:\n"
849
230
os.unlink('test2.txt')
851
232
progress("command aliases")
852
out = capture("st --all")
853
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
233
out = backtick("bzr st --all")
234
assert out == ("unknown:\n"
855
out = capture("stat")
856
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
237
out = backtick("bzr stat")
238
assert out == ("unknown:\n"
858
241
progress("command help")
859
242
runbzr("help st")
861
244
runbzr("help commands")
862
runbzr("help slartibartfast", 3)
245
runbzr("help slartibartfast", 1)
864
out = capture("help ci")
247
out = backtick("bzr help ci")
865
248
out.index('aliases: ')
867
250
progress("can't rename unversioned file")
868
runbzr("rename test.txt new-test.txt", 3)
251
runbzr("rename test.txt new-test.txt", 1)
870
253
progress("adding a file")
872
255
runbzr("add test.txt")
873
self.assertEquals(capture("unknowns"), '')
874
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
256
assert backtick("bzr unknowns") == ''
257
assert backtick("bzr status --all") == ("added:\n"
876
260
progress("rename newly-added file")
877
261
runbzr("rename test.txt hello.txt")
878
self.assert_(os.path.exists("hello.txt"))
879
self.assert_(not os.path.exists("test.txt"))
262
assert os.path.exists("hello.txt")
263
assert not os.path.exists("test.txt")
881
self.assertEquals(capture("revno"), '0\n')
265
assert backtick("bzr revno") == '0\n'
883
267
progress("add first revision")
884
268
runbzr(['commit', '-m', 'add first revision'])
886
270
progress("more complex renames")
888
runbzr("rename hello.txt sub1", 3)
889
runbzr("rename hello.txt sub1/hello.txt", 3)
890
runbzr("move hello.txt sub1", 3)
272
runbzr("rename hello.txt sub1", 1)
273
runbzr("rename hello.txt sub1/hello.txt", 1)
274
runbzr("move hello.txt sub1", 1)
892
276
runbzr("add sub1")
893
277
runbzr("rename sub1 sub2")
894
278
runbzr("move hello.txt sub2")
895
self.assertEqual(capture("relpath sub2/hello.txt"),
896
pathjoin("sub2", "hello.txt\n"))
279
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
898
self.assert_(exists("sub2"))
899
self.assert_(exists("sub2/hello.txt"))
900
self.assert_(not exists("sub1"))
901
self.assert_(not exists("hello.txt"))
281
assert exists("sub2")
282
assert exists("sub2/hello.txt")
283
assert not exists("sub1")
284
assert not exists("hello.txt")
903
286
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
906
289
runbzr('add sub1')
907
290
runbzr('move sub2/hello.txt sub1')
908
self.assert_(not exists('sub2/hello.txt'))
909
self.assert_(exists('sub1/hello.txt'))
291
assert not exists('sub2/hello.txt')
292
assert exists('sub1/hello.txt')
910
293
runbzr('move sub2 sub1')
911
self.assert_(not exists('sub2'))
912
self.assert_(exists('sub1/sub2'))
294
assert not exists('sub2')
295
assert exists('sub1/sub2')
914
297
runbzr(['commit', '-m', 'rename nested subdirectories'])
916
299
chdir('sub1/sub2')
917
self.assertEquals(capture('root')[:-1],
918
pathjoin(self.test_dir, 'branch1'))
300
self.assertEquals(backtick('bzr root')[:-1],
301
os.path.join(self.test_dir, 'branch1'))
919
302
runbzr('move ../hello.txt .')
920
self.assert_(exists('./hello.txt'))
921
self.assertEquals(capture('relpath hello.txt'),
922
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
923
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
303
assert exists('./hello.txt')
304
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
305
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
924
306
runbzr(['commit', '-m', 'move to parent directory'])
926
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
308
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
928
310
runbzr('move sub2/hello.txt .')
929
self.assert_(exists('hello.txt'))
311
assert exists('hello.txt')
931
313
f = file('hello.txt', 'wt')
932
314
f.write('some nice new content\n')
935
317
f = file('msg.tmp', 'wt')
936
f.write('this is my new commit\nand it has multiple lines, for fun')
318
f.write('this is my new commit\n')
939
321
runbzr('commit -F msg.tmp')
941
self.assertEquals(capture('revno'), '5\n')
323
assert backtick('bzr revno') == '5\n'
942
324
runbzr('export -r 5 export-5.tmp')
943
325
runbzr('export export.tmp')
947
329
runbzr('log -v --forward')
948
runbzr('log -m', retcode=3)
949
log_out = capture('log -m commit')
950
self.assert_("this is my new commit\n and" in log_out)
951
self.assert_("rename nested" not in log_out)
952
self.assert_('revision-id' not in log_out)
953
self.assert_('revision-id' in capture('log --show-ids -m commit'))
955
log_out = capture('log --line')
956
for line in log_out.splitlines():
957
self.assert_(len(line) <= 79, len(line))
958
self.assert_("this is my new commit and" in log_out)
330
runbzr('log -m', retcode=1)
331
log_out = backtick('bzr log -m commit')
332
assert "this is my new commit" in log_out
333
assert "rename nested" not in log_out
334
assert 'revision-id' not in log_out
335
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
961
338
progress("file with spaces in name")
962
339
mkdir('sub directory')
963
340
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
965
runbzr('diff', retcode=1)
966
343
runbzr('commit -m add-spaces')
970
347
runbzr('log --forward')
979
os.symlink("NOWHERE1", "link1")
981
self.assertEquals(self.capture('unknowns'), '')
982
runbzr(['commit', '-m', '1: added symlink link1'])
986
self.assertEquals(self.capture('unknowns'), '')
987
os.symlink("NOWHERE2", "d1/link2")
988
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
989
# is d1/link2 found when adding d1
991
self.assertEquals(self.capture('unknowns'), '')
992
os.symlink("NOWHERE3", "d1/link3")
993
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
994
runbzr(['commit', '-m', '2: added dir, symlink'])
996
runbzr('rename d1 d2')
997
runbzr('move d2/link2 .')
998
runbzr('move link1 d2')
999
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1000
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1001
runbzr('add d2/link3')
1002
runbzr('diff', retcode=1)
1003
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1006
os.symlink("TARGET 2", "link2")
1007
os.unlink("d2/link1")
1008
os.symlink("TARGET 1", "d2/link1")
1009
runbzr('diff', retcode=1)
1010
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1011
runbzr(['commit', '-m', '4: retarget of two links'])
1013
runbzr('remove d2/link1')
1014
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1015
runbzr(['commit', '-m', '5: remove d2/link1'])
1016
# try with the rm alias
1017
runbzr('add d2/link1')
1018
runbzr(['commit', '-m', '6: add d2/link1'])
1019
runbzr('rm d2/link1')
1020
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1021
runbzr(['commit', '-m', '7: remove d2/link1'])
1025
runbzr('rename d2/link3 d1/link3new')
1026
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1027
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1031
runbzr(['export', '-r', '1', 'exp1.tmp'])
1033
self.assertEquals(listdir_sorted("."), [ "link1" ])
1034
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1037
runbzr(['export', '-r', '2', 'exp2.tmp'])
1039
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1042
runbzr(['export', '-r', '3', 'exp3.tmp'])
1044
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1045
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1046
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1047
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1050
runbzr(['export', '-r', '4', 'exp4.tmp'])
1052
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1053
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1054
self.assertEquals(os.readlink("link2") , "TARGET 2")
1055
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1058
runbzr(['export', '-r', '5', 'exp5.tmp'])
1060
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1061
self.assert_(os.path.islink("link2"))
1062
self.assert_(listdir_sorted("d2")== [ "link3" ])
1065
runbzr(['export', '-r', '8', 'exp6.tmp'])
1067
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1068
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1069
self.assertEquals(listdir_sorted("d2"), [])
1070
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1073
progress("skipping symlink tests")
1076
class RemoteTests(object):
1077
"""Test bzr ui commands against remote branches."""
1079
def test_branch(self):
1081
wt = self.make_branch_and_tree('from')
1083
wt.commit('empty commit for nonsense', allow_pointless=True)
1084
url = self.get_readonly_url('from')
1085
self.run_bzr('branch', url, 'to')
1086
branch = Branch.open('to')
1087
self.assertEqual(1, len(branch.revision_history()))
1088
# the branch should be set in to to from
1089
self.assertEqual(url + '/', branch.get_parent())
1092
self.build_tree(['branch/', 'branch/file'])
1093
self.capture('init branch')
1094
self.capture('add branch/file')
1095
self.capture('commit -m foo branch')
1096
url = self.get_readonly_url('branch/file')
1097
output = self.capture('log %s' % url)
1098
self.assertEqual(8, len(output.split('\n')))
1100
def test_check(self):
1101
self.build_tree(['branch/', 'branch/file'])
1102
self.capture('init branch')
1103
self.capture('add branch/file')
1104
self.capture('commit -m foo branch')
1105
url = self.get_readonly_url('branch/')
1106
self.run_bzr('check', url)
1108
def test_push(self):
1109
# create a source branch
1110
os.mkdir('my-branch')
1111
os.chdir('my-branch')
1112
self.run_bzr('init')
1113
file('hello', 'wt').write('foo')
1114
self.run_bzr('add', 'hello')
1115
self.run_bzr('commit', '-m', 'setup')
1117
# with an explicit target work
1118
self.run_bzr('push', self.get_url('output-branch'))
1121
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1122
"""Test various commands against a HTTP server."""
1125
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1126
"""Test various commands against a SFTP server using abs paths."""
1129
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1130
"""Test various commands against a SFTP server using abs paths."""
1133
super(SFTPTestsAbsoluteSibling, self).setUp()
1134
self._override_home = '/dev/noone/runs/tests/here'
1137
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1138
"""Test various commands against a SFTP server using homedir rel paths."""
1141
super(SFTPTestsRelative, self).setUp()
1142
self._get_remote_is_absolute = False