68
70
def test_whoami_branch(self):
69
71
"""branch specific user identity works."""
70
72
self.runbzr('init')
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']
73
f = file('.bzr/email', 'wt')
74
f.write('Branch Identity <branch@identi.ty>')
76
76
whoami = self.runbzr("whoami",backtick=True)
77
77
whoami_email = self.runbzr("whoami --email",backtick=True)
78
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
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
81
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)
82
self.runbzr("pants", retcode=1)
83
self.runbzr("--pants off", retcode=1)
84
self.runbzr("diff --message foo", retcode=1)
86
def test_empty_commit(self):
88
self.build_tree(['hello.txt'])
89
self.runbzr("commit -m empty", retcode=1)
90
self.runbzr("add hello.txt")
91
self.runbzr("commit -m added")
106
93
def test_ignore_patterns(self):
108
self.assertEquals(self.capture('unknowns'), '')
94
from bzrlib.branch import Branch
96
b = Branch('.', init=True)
97
self.assertEquals(list(b.unknowns()), [])
110
99
file('foo.tmp', 'wt').write('tmp files are ignored')
111
self.assertEquals(self.capture('unknowns'), '')
100
self.assertEquals(list(b.unknowns()), [])
101
assert self.backtick('bzr unknowns') == ''
113
103
file('foo.c', 'wt').write('int main() {}')
114
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
104
self.assertEquals(list(b.unknowns()), ['foo.c'])
105
assert self.backtick('bzr unknowns') == 'foo.c\n'
116
107
self.runbzr(['add', 'foo.c'])
117
self.assertEquals(self.capture('unknowns'), '')
108
assert self.backtick('bzr unknowns') == ''
119
110
# 'ignore' works when creating the .bzignore file
120
111
file('foo.blah', 'wt').write('blah')
121
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
112
self.assertEquals(list(b.unknowns()), ['foo.blah'])
122
113
self.runbzr('ignore *.blah')
123
self.assertEquals(self.capture('unknowns'), '')
124
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
114
self.assertEquals(list(b.unknowns()), [])
115
assert file('.bzrignore', 'rb').read() == '*.blah\n'
126
117
# 'ignore' works when then .bzrignore file already exists
127
118
file('garh', 'wt').write('garh')
128
self.assertEquals(self.capture('unknowns'), 'garh\n')
119
self.assertEquals(list(b.unknowns()), ['garh'])
120
assert self.backtick('bzr unknowns') == 'garh\n'
129
121
self.runbzr('ignore garh')
130
self.assertEquals(self.capture('unknowns'), '')
131
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
122
self.assertEquals(list(b.unknowns()), [])
123
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
133
125
def test_revert(self):
134
126
self.runbzr('init')
215
184
test.runbzr('add goodbye')
216
185
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')
187
def test_revert(self):
188
self.example_branch()
189
file('hello', 'wt').write('bar')
190
file('goodbye', 'wt').write('qux')
191
self.runbzr('revert hello')
192
self.check_file_contents('hello', 'foo')
193
self.check_file_contents('goodbye', 'qux')
194
self.runbzr('revert')
195
self.check_file_contents('goodbye', 'baz')
197
def test_merge(self):
198
from bzrlib.branch import Branch
202
self.example_branch()
204
self.runbzr('branch a b')
206
file('goodbye', 'wt').write('quux')
207
self.runbzr(['commit', '-m', "more u's are always good"])
210
file('hello', 'wt').write('quuux')
211
# We can't merge when there are in-tree changes
212
self.runbzr('merge ../b', retcode=1)
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
214
self.runbzr('merge ../b')
215
self.check_file_contents('goodbye', 'quux')
216
# Merging a branch pulls its revision into the tree
219
a.get_revision_xml(b.last_patch())
220
self.log('pending merges: %s', a.pending_merges())
221
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
# % (a.pending_merges(), b.last_patch())
225
"""Pull changes from one branch to another."""
229
self.example_branch()
230
self.runbzr('pull', retcode=1)
231
self.runbzr('missing', retcode=1)
232
self.runbzr('missing .')
233
self.runbzr('missing')
235
self.runbzr('pull /', retcode=1)
239
self.runbzr('branch a b')
242
self.runbzr('commit -m blah --unchanged')
246
assert a.revision_history() == b.revision_history()[:-1]
452
247
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):
248
assert a.revision_history() == b.revision_history()
249
self.runbzr('commit -m blah2 --unchanged')
251
self.runbzr('commit -m blah3 --unchanged')
252
self.runbzr('pull ../a', retcode=1)
254
self.runbzr('merge ../b')
255
self.runbzr('commit -m blah4 --unchanged')
257
self.runbzr('pull ../a')
258
assert a.revision_history()[-1] == b.revision_history()[-1]
261
def test_add_reports(self):
262
"""add command prints the names of added files."""
263
b = Branch('.', init=True)
264
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
266
from cStringIO import StringIO
269
ret = self.apply_redirected(None, out, None,
272
self.assertEquals(ret, 0)
274
# the ordering is not defined at the moment
275
results = sorted(out.getvalue().rstrip('\n').split('\n'))
276
self.assertEquals(['added dir',
669
282
class OldTests(ExternalBase):
691
304
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')
699
out = capture("status --all")
700
self.assertEquals(out, "unknown:\n test.txt\n")
702
out = capture("status test.txt --all")
703
self.assertEquals(out, "unknown:\n test.txt\n")
307
out = backtick("bzr unknowns")
308
self.assertEquals(out, 'test.txt\n')
310
out = backtick("bzr status")
311
assert out == 'unknown:\n test.txt\n'
313
out = backtick("bzr status --all")
314
assert out == "unknown:\n test.txt\n"
316
out = backtick("bzr status test.txt --all")
317
assert out == "unknown:\n test.txt\n"
705
319
f = file('test2.txt', 'wt')
706
320
f.write('goodbye cruel world...\n')
709
out = capture("status test.txt")
710
self.assertEquals(out, "unknown:\n test.txt\n")
323
out = backtick("bzr status test.txt")
324
assert out == "unknown:\n test.txt\n"
712
out = capture("status")
713
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
326
out = backtick("bzr status")
327
assert out == ("unknown:\n"
715
331
os.unlink('test2.txt')
717
333
progress("command aliases")
718
out = capture("st --all")
719
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
334
out = backtick("bzr st --all")
335
assert out == ("unknown:\n"
721
out = capture("stat")
722
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
338
out = backtick("bzr stat")
339
assert out == ("unknown:\n"
724
342
progress("command help")
725
343
runbzr("help st")
727
345
runbzr("help commands")
728
runbzr("help slartibartfast", 3)
346
runbzr("help slartibartfast", 1)
730
out = capture("help ci")
348
out = backtick("bzr help ci")
731
349
out.index('aliases: ')
733
351
progress("can't rename unversioned file")
734
runbzr("rename test.txt new-test.txt", 3)
352
runbzr("rename test.txt new-test.txt", 1)
736
354
progress("adding a file")
738
356
runbzr("add test.txt")
739
self.assertEquals(capture("unknowns"), '')
740
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
357
assert backtick("bzr unknowns") == ''
358
assert backtick("bzr status --all") == ("added:\n"
742
361
progress("rename newly-added file")
743
362
runbzr("rename test.txt hello.txt")
744
self.assert_(os.path.exists("hello.txt"))
745
self.assert_(not os.path.exists("test.txt"))
363
assert os.path.exists("hello.txt")
364
assert not os.path.exists("test.txt")
747
self.assertEquals(capture("revno"), '0\n')
366
assert backtick("bzr revno") == '0\n'
749
368
progress("add first revision")
750
369
runbzr(['commit', '-m', 'add first revision'])
752
371
progress("more complex renames")
754
runbzr("rename hello.txt sub1", 3)
755
runbzr("rename hello.txt sub1/hello.txt", 3)
756
runbzr("move hello.txt sub1", 3)
373
runbzr("rename hello.txt sub1", 1)
374
runbzr("rename hello.txt sub1/hello.txt", 1)
375
runbzr("move hello.txt sub1", 1)
758
377
runbzr("add sub1")
759
378
runbzr("rename sub1 sub2")
760
379
runbzr("move hello.txt sub2")
761
self.assertEqual(capture("relpath sub2/hello.txt"),
762
pathjoin("sub2", "hello.txt\n"))
380
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
764
self.assert_(exists("sub2"))
765
self.assert_(exists("sub2/hello.txt"))
766
self.assert_(not exists("sub1"))
767
self.assert_(not exists("hello.txt"))
382
assert exists("sub2")
383
assert exists("sub2/hello.txt")
384
assert not exists("sub1")
385
assert not exists("hello.txt")
769
387
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
772
390
runbzr('add sub1')
773
391
runbzr('move sub2/hello.txt sub1')
774
self.assert_(not exists('sub2/hello.txt'))
775
self.assert_(exists('sub1/hello.txt'))
392
assert not exists('sub2/hello.txt')
393
assert exists('sub1/hello.txt')
776
394
runbzr('move sub2 sub1')
777
self.assert_(not exists('sub2'))
778
self.assert_(exists('sub1/sub2'))
395
assert not exists('sub2')
396
assert exists('sub1/sub2')
780
398
runbzr(['commit', '-m', 'rename nested subdirectories'])
782
400
chdir('sub1/sub2')
783
self.assertEquals(capture('root')[:-1],
784
pathjoin(self.test_dir, 'branch1'))
401
self.assertEquals(backtick('bzr root')[:-1],
402
os.path.join(self.test_dir, 'branch1'))
785
403
runbzr('move ../hello.txt .')
786
self.assert_(exists('./hello.txt'))
787
self.assertEquals(capture('relpath hello.txt'),
788
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
789
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
404
assert exists('./hello.txt')
405
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
406
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
790
407
runbzr(['commit', '-m', 'move to parent directory'])
792
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
409
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
794
411
runbzr('move sub2/hello.txt .')
795
self.assert_(exists('hello.txt'))
412
assert exists('hello.txt')
797
414
f = file('hello.txt', 'wt')
798
415
f.write('some nice new content\n')
801
418
f = file('msg.tmp', 'wt')
802
f.write('this is my new commit\nand it has multiple lines, for fun')
419
f.write('this is my new commit\n')
805
422
runbzr('commit -F msg.tmp')
807
self.assertEquals(capture('revno'), '5\n')
424
assert backtick('bzr revno') == '5\n'
808
425
runbzr('export -r 5 export-5.tmp')
809
426
runbzr('export export.tmp')
813
430
runbzr('log -v --forward')
814
runbzr('log -m', retcode=3)
815
log_out = capture('log -m commit')
816
self.assert_("this is my new commit\n and" in log_out)
817
self.assert_("rename nested" not in log_out)
818
self.assert_('revision-id' not in log_out)
819
self.assert_('revision-id' in capture('log --show-ids -m commit'))
431
runbzr('log -m', retcode=1)
432
log_out = backtick('bzr log -m commit')
433
assert "this is my new commit" in log_out
434
assert "rename nested" not in log_out
435
assert 'revision-id' not in log_out
436
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
821
log_out = capture('log --line')
822
# determine the widest line we want
823
max_width = terminal_width() - 1
824
for line in log_out.splitlines():
825
self.assert_(len(line) <= max_width, len(line))
826
self.assert_("this is my new commit and" not in log_out)
827
self.assert_("this is my new commit" in log_out)
829
439
progress("file with spaces in name")
830
440
mkdir('sub directory')
831
441
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
833
runbzr('diff', retcode=1)
834
444
runbzr('commit -m add-spaces')
847
os.symlink("NOWHERE1", "link1")
849
self.assertEquals(self.capture('unknowns'), '')
850
runbzr(['commit', '-m', '1: added symlink link1'])
854
self.assertEquals(self.capture('unknowns'), '')
855
os.symlink("NOWHERE2", "d1/link2")
856
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
857
# is d1/link2 found when adding d1
859
self.assertEquals(self.capture('unknowns'), '')
860
os.symlink("NOWHERE3", "d1/link3")
861
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
862
runbzr(['commit', '-m', '2: added dir, symlink'])
864
runbzr('rename d1 d2')
865
runbzr('move d2/link2 .')
866
runbzr('move link1 d2')
867
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
868
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
869
runbzr('add d2/link3')
870
runbzr('diff', retcode=1)
871
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
874
os.symlink("TARGET 2", "link2")
875
os.unlink("d2/link1")
876
os.symlink("TARGET 1", "d2/link1")
877
runbzr('diff', retcode=1)
878
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
879
runbzr(['commit', '-m', '4: retarget of two links'])
881
runbzr('remove d2/link1')
882
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
883
runbzr(['commit', '-m', '5: remove d2/link1'])
884
# try with the rm alias
885
runbzr('add d2/link1')
886
runbzr(['commit', '-m', '6: add d2/link1'])
887
runbzr('rm d2/link1')
888
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
889
runbzr(['commit', '-m', '7: remove d2/link1'])
893
runbzr('rename d2/link3 d1/link3new')
894
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
895
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
899
runbzr(['export', '-r', '1', 'exp1.tmp'])
901
self.assertEquals(listdir_sorted("."), [ "link1" ])
902
self.assertEquals(os.readlink("link1"), "NOWHERE1")
905
runbzr(['export', '-r', '2', 'exp2.tmp'])
907
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
910
runbzr(['export', '-r', '3', 'exp3.tmp'])
912
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
913
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
914
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
915
self.assertEquals(os.readlink("link2") , "NOWHERE2")
918
runbzr(['export', '-r', '4', 'exp4.tmp'])
920
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
921
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
922
self.assertEquals(os.readlink("link2") , "TARGET 2")
923
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
926
runbzr(['export', '-r', '5', 'exp5.tmp'])
928
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
929
self.assert_(os.path.islink("link2"))
930
self.assert_(listdir_sorted("d2")== [ "link3" ])
933
runbzr(['export', '-r', '8', 'exp6.tmp'])
935
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
936
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
937
self.assertEquals(listdir_sorted("d2"), [])
938
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
941
progress("skipping symlink tests")
944
class RemoteTests(object):
945
"""Test bzr ui commands against remote branches."""
947
def test_branch(self):
949
wt = self.make_branch_and_tree('from')
951
wt.commit('empty commit for nonsense', allow_pointless=True)
952
url = self.get_readonly_url('from')
953
self.run_bzr('branch', url, 'to')
954
branch = Branch.open('to')
955
self.assertEqual(1, len(branch.revision_history()))
956
# the branch should be set in to to from
957
self.assertEqual(url + '/', branch.get_parent())
960
self.build_tree(['branch/', 'branch/file'])
961
self.capture('init branch')
962
self.capture('add branch/file')
963
self.capture('commit -m foo branch')
964
url = self.get_readonly_url('branch/file')
965
output = self.capture('log %s' % url)
966
self.assertEqual(8, len(output.split('\n')))
968
def test_check(self):
969
self.build_tree(['branch/', 'branch/file'])
970
self.capture('init branch')
971
self.capture('add branch/file')
972
self.capture('commit -m foo branch')
973
url = self.get_readonly_url('branch/')
974
self.run_bzr('check', url)
977
# create a source branch
978
os.mkdir('my-branch')
979
os.chdir('my-branch')
981
file('hello', 'wt').write('foo')
982
self.run_bzr('add', 'hello')
983
self.run_bzr('commit', '-m', 'setup')
985
# with an explicit target work
986
self.run_bzr('push', self.get_url('output-branch'))
989
class HTTPTests(TestCaseWithWebserver, RemoteTests):
990
"""Test various commands against a HTTP server."""
993
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
994
"""Test various commands against a SFTP server using abs paths."""
997
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
998
"""Test various commands against a SFTP server using abs paths."""
1001
super(SFTPTestsAbsoluteSibling, self).setUp()
1002
self._override_home = '/dev/noone/runs/tests/here'
1005
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1006
"""Test various commands against a SFTP server using homedir rel paths."""
1009
super(SFTPTestsRelative, self).setUp()
1010
self._get_remote_is_absolute = False