87
89
if bzr_email is not None:
88
90
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
92
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)
93
self.runbzr("pants", retcode=1)
94
self.runbzr("--pants off", retcode=1)
95
self.runbzr("diff --message foo", retcode=1)
97
def test_empty_commit(self):
99
self.build_tree(['hello.txt'])
100
self.runbzr("commit -m empty", retcode=1)
101
self.runbzr("add hello.txt")
102
self.runbzr("commit -m added")
106
104
def test_ignore_patterns(self):
108
self.assertEquals(self.capture('unknowns'), '')
105
from bzrlib.branch import Branch
107
b = Branch.initialize('.')
108
self.assertEquals(list(b.unknowns()), [])
110
110
file('foo.tmp', 'wt').write('tmp files are ignored')
111
self.assertEquals(self.capture('unknowns'), '')
111
self.assertEquals(list(b.unknowns()), [])
112
assert self.capture('unknowns') == ''
113
114
file('foo.c', 'wt').write('int main() {}')
114
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
115
self.assertEquals(list(b.unknowns()), ['foo.c'])
116
assert self.capture('unknowns') == 'foo.c\n'
116
118
self.runbzr(['add', 'foo.c'])
117
self.assertEquals(self.capture('unknowns'), '')
119
assert self.capture('unknowns') == ''
119
121
# 'ignore' works when creating the .bzignore file
120
122
file('foo.blah', 'wt').write('blah')
121
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
123
self.assertEquals(list(b.unknowns()), ['foo.blah'])
122
124
self.runbzr('ignore *.blah')
123
self.assertEquals(self.capture('unknowns'), '')
124
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
125
self.assertEquals(list(b.unknowns()), [])
126
assert file('.bzrignore', 'rU').read() == '*.blah\n'
126
128
# 'ignore' works when then .bzrignore file already exists
127
129
file('garh', 'wt').write('garh')
128
self.assertEquals(self.capture('unknowns'), 'garh\n')
130
self.assertEquals(list(b.unknowns()), ['garh'])
131
assert self.capture('unknowns') == 'garh\n'
129
132
self.runbzr('ignore garh')
130
self.assertEquals(self.capture('unknowns'), '')
131
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
133
self.assertEquals(list(b.unknowns()), [])
134
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
136
def test_revert(self):
139
file('hello', 'wt').write('foo')
140
self.runbzr('add hello')
141
self.runbzr('commit -m setup hello')
143
file('goodbye', 'wt').write('baz')
144
self.runbzr('add goodbye')
145
self.runbzr('commit -m setup goodbye')
147
file('hello', 'wt').write('bar')
148
file('goodbye', 'wt').write('qux')
149
self.runbzr('revert hello')
150
self.check_file_contents('hello', 'foo')
151
self.check_file_contents('goodbye', 'qux')
152
self.runbzr('revert')
153
self.check_file_contents('goodbye', 'baz')
155
os.mkdir('revertdir')
156
self.runbzr('add revertdir')
157
self.runbzr('commit -m f')
158
os.rmdir('revertdir')
159
self.runbzr('revert')
161
file('hello', 'wt').write('xyz')
162
self.runbzr('commit -m xyz hello')
163
self.runbzr('revert -r 1 hello')
164
self.check_file_contents('hello', 'foo')
165
self.runbzr('revert hello')
166
self.check_file_contents('hello', 'xyz')
167
os.chdir('revertdir')
168
self.runbzr('revert')
133
172
def test_mv_modes(self):
134
173
"""Test two modes of operation for mv"""
174
from bzrlib.branch import Branch
175
b = Branch.initialize('.')
136
176
self.build_tree(['a', 'c', 'subdir/'])
137
177
self.run_bzr_captured(['add', self.test_dir])
138
178
self.run_bzr_captured(['mv', 'a', 'b'])
165
206
test.runbzr('add goodbye')
166
207
test.runbzr('commit -m setup goodbye')
168
def test_export(self):
171
self.example_branch()
172
self.runbzr('export ../latest')
173
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
174
self.runbzr('export ../first -r 1')
175
self.assert_(not os.path.exists('../first/goodbye'))
176
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
177
self.runbzr('export ../first.gz -r 1')
178
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
179
self.runbzr('export ../first.bz2 -r 1')
180
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
182
from tarfile import TarFile
183
self.runbzr('export ../first.tar -r 1')
184
self.assert_(os.path.isfile('../first.tar'))
185
tf = TarFile('../first.tar')
186
self.assert_('first/hello' in tf.getnames(), tf.getnames())
187
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
188
self.runbzr('export ../first.tar.gz -r 1')
189
self.assert_(os.path.isfile('../first.tar.gz'))
190
self.runbzr('export ../first.tbz2 -r 1')
191
self.assert_(os.path.isfile('../first.tbz2'))
192
self.runbzr('export ../first.tar.bz2 -r 1')
193
self.assert_(os.path.isfile('../first.tar.bz2'))
194
self.runbzr('export ../first.tar.tbz2 -r 1')
195
self.assert_(os.path.isfile('../first.tar.tbz2'))
197
from bz2 import BZ2File
198
tf = TarFile('../first.tar.tbz2',
199
fileobj=BZ2File('../first.tar.tbz2', 'r'))
200
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
201
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
202
self.runbzr('export ../first2.tar -r 1 --root pizza')
203
tf = TarFile('../first2.tar')
204
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
206
from zipfile import ZipFile
207
self.runbzr('export ../first.zip -r 1')
208
self.failUnlessExists('../first.zip')
209
zf = ZipFile('../first.zip')
210
self.assert_('first/hello' in zf.namelist(), zf.namelist())
211
self.assertEqual(zf.read('first/hello'), 'foo')
213
self.runbzr('export ../first2.zip -r 1 --root pizza')
214
zf = ZipFile('../first2.zip')
215
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
217
self.runbzr('export ../first-zip --format=zip -r 1')
218
zf = ZipFile('../first-zip')
219
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
221
def test_inventory(self):
223
def output_equals(value, *args):
224
out = self.runbzr(['inventory'] + list(args), backtick=True)
225
self.assertEquals(out, value)
228
open('a', 'wb').write('hello\n')
234
output_equals('a\n', '--kind', 'file')
235
output_equals('b\n', '--kind', 'directory')
238
"""Test the abilities of 'bzr ls'"""
240
def bzrout(*args, **kwargs):
241
kwargs['backtick'] = True
242
return self.runbzr(*args, **kwargs)
244
def ls_equals(value, *args):
245
out = self.runbzr(['ls'] + list(args), backtick=True)
246
self.assertEquals(out, value)
249
open('a', 'wb').write('hello\n')
252
bzr('ls --verbose --null', retcode=3)
255
ls_equals('? a\n', '--verbose')
256
ls_equals('a\n', '--unknown')
257
ls_equals('', '--ignored')
258
ls_equals('', '--versioned')
259
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
260
ls_equals('', '--ignored', '--versioned')
261
ls_equals('a\0', '--null')
264
ls_equals('V a\n', '--verbose')
210
self.example_branch()
211
file('hello', 'wt').write('hello world!')
212
self.runbzr('commit -m fixing hello')
213
output = self.runbzr('diff -r 2..3', backtick=1)
214
self.assert_('\n+hello world!' in output)
215
output = self.runbzr('diff -r last:3..last:1', backtick=1)
216
self.assert_('\n+baz' in output)
218
def test_branch(self):
219
"""Branch from one branch to another."""
222
self.example_branch()
224
self.runbzr('branch a b')
225
self.runbzr('branch a c -r 1')
227
def test_merge(self):
228
from bzrlib.branch import Branch
232
self.example_branch()
234
self.runbzr('branch a b')
236
file('goodbye', 'wt').write('quux')
237
self.runbzr(['commit', '-m', "more u's are always good"])
240
file('hello', 'wt').write('quuux')
241
# We can't merge when there are in-tree changes
242
self.runbzr('merge ../b', retcode=1)
243
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
244
self.runbzr('merge ../b')
245
self.check_file_contents('goodbye', 'quux')
246
# Merging a branch pulls its revision into the tree
248
b = Branch.open('../b')
249
a.get_revision_xml(b.last_patch())
250
self.log('pending merges: %s', a.pending_merges())
251
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
252
# % (a.pending_merges(), b.last_patch())
255
"""Pull changes from one branch to another."""
259
self.example_branch()
260
self.runbzr('pull', retcode=1)
261
self.runbzr('missing', retcode=1)
262
self.runbzr('missing .')
263
self.runbzr('missing')
265
self.runbzr('pull /', retcode=1)
269
self.runbzr('branch a b')
267
272
os.mkdir('subdir')
271
open('subdir/b', 'wb').write('b\n')
277
bzr('commit -m subdir')
285
, '--verbose', '--non-recursive')
287
# Check what happens in a sub-directory
299
, '--from-root', '--null')
302
, '--from-root', '--non-recursive')
306
# Check what happens when we supply a specific revision
307
ls_equals('a\n', '--revision', '1')
309
, '--verbose', '--revision', '1')
312
ls_equals('', '--revision', '1')
314
# Now try to do ignored files.
316
open('blah.py', 'wb').write('unknown\n')
317
open('blah.pyo', 'wb').write('ignored\n')
329
ls_equals('blah.pyo\n'
331
ls_equals('blah.py\n'
340
file("myfile", "wb").write("My contents\n")
342
self.runbzr('commit -m myfile')
343
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
345
def test_pull_verbose(self):
346
"""Pull changes from one branch to another and watch the output."""
352
self.example_branch()
357
open('b', 'wb').write('else\n')
359
bzr(['commit', '-m', 'added b'])
362
out = bzr('pull --verbose ../b', backtick=True)
363
self.failIfEqual(out.find('Added Revisions:'), -1)
364
self.failIfEqual(out.find('message:\n added b'), -1)
365
self.failIfEqual(out.find('added b'), -1)
367
# Check that --overwrite --verbose prints out the removed entries
368
bzr('commit -m foo --unchanged')
370
bzr('commit -m baz --unchanged')
371
bzr('pull ../a', retcode=3)
372
out = bzr('pull --overwrite --verbose ../a', backtick=1)
374
remove_loc = out.find('Removed Revisions:')
375
self.failIfEqual(remove_loc, -1)
376
added_loc = out.find('Added Revisions:')
377
self.failIfEqual(added_loc, -1)
379
removed_message = out.find('message:\n baz')
380
self.failIfEqual(removed_message, -1)
381
self.failUnless(remove_loc < removed_message < added_loc)
383
added_message = out.find('message:\n foo')
384
self.failIfEqual(added_message, -1)
385
self.failUnless(added_loc < added_message)
387
def test_locations(self):
388
"""Using and remembering different locations"""
392
self.runbzr('commit -m unchanged --unchanged')
393
self.runbzr('pull', retcode=3)
394
self.runbzr('merge', retcode=3)
395
self.runbzr('branch . ../b')
398
self.runbzr('branch . ../c')
399
self.runbzr('pull ../c')
273
self.runbzr('add subdir')
274
self.runbzr('commit -m blah --unchanged')
277
b = Branch.open('../b')
278
assert a.revision_history() == b.revision_history()[:-1]
402
279
self.runbzr('pull ../b')
404
self.runbzr('pull ../c')
405
self.runbzr('branch ../c ../d')
280
assert a.revision_history() == b.revision_history()
281
self.runbzr('commit -m blah2 --unchanged')
411
self.runbzr('pull', retcode=3)
412
self.runbzr('pull ../a --remember')
283
self.runbzr('commit -m blah3 --unchanged')
284
self.runbzr('pull ../a', retcode=1)
286
self.runbzr('merge ../b')
287
self.runbzr('commit -m blah4 --unchanged')
288
os.chdir('../b/subdir')
289
self.runbzr('pull ../../a')
290
assert a.revision_history()[-1] == b.revision_history()[-1]
292
def test_add_reports(self):
293
"""add command prints the names of added files."""
294
b = Branch.initialize('.')
295
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
296
out = self.run_bzr_captured(['add'], retcode = 0)[0]
297
# the ordering is not defined at the moment
298
results = sorted(out.rstrip('\n').split('\n'))
299
self.assertEquals(['added dir',
300
'added dir'+os.sep+'sub.txt',
415
304
def test_unknown_command(self):
416
305
"""Handling of unknown command."""
417
306
out, err = self.run_bzr_captured(['fluffy-badger'],
419
308
self.assertEquals(out, '')
420
309
err.index('unknown command')
422
def create_conflicts(self):
423
"""Create a conflicted tree"""
426
file('hello', 'wb').write("hi world")
427
file('answer', 'wb').write("42")
430
self.runbzr('commit -m base')
431
self.runbzr('branch . ../other')
432
self.runbzr('branch . ../this')
434
file('hello', 'wb').write("Hello.")
435
file('answer', 'wb').write("Is anyone there?")
436
self.runbzr('commit -m other')
438
file('hello', 'wb').write("Hello, world")
439
self.runbzr('mv answer question')
440
file('question', 'wb').write("What do you get when you multiply six"
442
self.runbzr('commit -m this')
444
def test_status(self):
448
self.runbzr('commit --unchanged --message f')
449
self.runbzr('branch . ../branch2')
450
self.runbzr('branch . ../branch3')
451
self.runbzr('commit --unchanged --message peter')
452
os.chdir('../branch2')
453
self.runbzr('merge ../branch1')
454
self.runbzr('commit --unchanged --message pumpkin')
455
os.chdir('../branch3')
456
self.runbzr('merge ../branch2')
457
message = self.capture('status')
460
def test_conflicts(self):
461
"""Handling of merge conflicts"""
462
self.create_conflicts()
463
self.runbzr('merge ../other --show-base', retcode=1)
464
conflict_text = file('hello').read()
465
self.assert_('<<<<<<<' in conflict_text)
466
self.assert_('>>>>>>>' in conflict_text)
467
self.assert_('=======' in conflict_text)
468
self.assert_('|||||||' in conflict_text)
469
self.assert_('hi world' in conflict_text)
470
self.runbzr('revert')
471
self.runbzr('resolve --all')
472
self.runbzr('merge ../other', retcode=1)
473
conflict_text = file('hello').read()
474
self.assert_('|||||||' not in conflict_text)
475
self.assert_('hi world' not in conflict_text)
476
result = self.runbzr('conflicts', backtick=1)
477
self.assertEquals(result, "Text conflict in hello\nText conflict in"
479
result = self.runbzr('status', backtick=1)
480
self.assert_("conflicts:\n Text conflict in hello\n"
481
" Text conflict in question\n" in result, result)
482
self.runbzr('resolve hello')
483
result = self.runbzr('conflicts', backtick=1)
484
self.assertEquals(result, "Text conflict in question\n")
485
self.runbzr('commit -m conflicts', retcode=3)
486
self.runbzr('resolve --all')
487
result = self.runbzr('conflicts', backtick=1)
488
self.runbzr('commit -m conflicts')
489
self.assertEquals(result, "")
492
# create a source branch
493
os.mkdir('my-branch')
494
os.chdir('my-branch')
495
self.example_branch()
497
# with no push target, fail
498
self.runbzr('push', retcode=3)
499
# with an explicit target work
500
self.runbzr('push ../output-branch')
501
# with an implicit target work
504
self.runbzr('missing ../output-branch')
505
# advance this branch
506
self.runbzr('commit --unchanged -m unchanged')
508
os.chdir('../output-branch')
509
# There is no longer a difference as long as we have
510
# access to the working tree
513
# But we should be missing a revision
514
self.runbzr('missing ../my-branch', retcode=1)
516
# diverge the branches
517
self.runbzr('commit --unchanged -m unchanged')
518
os.chdir('../my-branch')
520
self.runbzr('push', retcode=3)
521
# and there are difference
522
self.runbzr('missing ../output-branch', retcode=1)
523
self.runbzr('missing --verbose ../output-branch', retcode=1)
524
# but we can force a push
525
self.runbzr('push --overwrite')
527
self.runbzr('missing ../output-branch')
529
# pushing to a new dir with no parent should fail
530
self.runbzr('push ../missing/new-branch', retcode=3)
531
# unless we provide --create-prefix
532
self.runbzr('push --create-prefix ../missing/new-branch')
534
self.runbzr('missing ../missing/new-branch')
536
def test_external_command(self):
537
"""Test that external commands can be run by setting the path
539
# We don't at present run bzr in a subprocess for blackbox tests, and so
540
# don't really capture stdout, only the internal python stream.
541
# Therefore we don't use a subcommand that produces any output or does
542
# anything -- we just check that it can be run successfully.
543
cmd_name = 'test-command'
544
if sys.platform == 'win32':
546
oldpath = os.environ.get('BZRPATH', None)
549
if os.environ.has_key('BZRPATH'):
550
del os.environ['BZRPATH']
552
f = file(cmd_name, 'wb')
553
if sys.platform == 'win32':
554
f.write('@echo off\n')
556
f.write('#!/bin/sh\n')
557
# f.write('echo Hello from test-command')
559
os.chmod(cmd_name, 0755)
561
# It should not find the command in the local
562
# directory by default, since it is not in my path
563
bzr(cmd_name, retcode=3)
565
# Now put it into my path
566
os.environ['BZRPATH'] = '.'
570
# Make sure empty path elements are ignored
571
os.environ['BZRPATH'] = os.pathsep
573
bzr(cmd_name, retcode=3)
577
os.environ['BZRPATH'] = oldpath
580
def listdir_sorted(dir):
586
313
class OldTests(ExternalBase):
611
338
self.assertEquals(capture('unknowns'), 'test.txt\n')
613
340
out = capture("status")
614
self.assertEquals(out, 'unknown:\n test.txt\n')
341
assert out == 'unknown:\n test.txt\n'
343
out = capture("status --all")
344
assert out == "unknown:\n test.txt\n"
346
out = capture("status test.txt --all")
347
assert out == "unknown:\n test.txt\n"
616
349
f = file('test2.txt', 'wt')
617
350
f.write('goodbye cruel world...\n')
620
353
out = capture("status test.txt")
621
self.assertEquals(out, "unknown:\n test.txt\n")
354
assert out == "unknown:\n test.txt\n"
623
356
out = capture("status")
624
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
357
assert out == ("unknown:\n"
626
361
os.unlink('test2.txt')
628
363
progress("command aliases")
630
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
364
out = capture("st --all")
365
assert out == ("unknown:\n"
632
368
out = capture("stat")
633
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
369
assert out == ("unknown:\n"
635
372
progress("command help")
636
373
runbzr("help st")
638
375
runbzr("help commands")
639
runbzr("help slartibartfast", 3)
376
runbzr("help slartibartfast", 1)
641
378
out = capture("help ci")
642
379
out.index('aliases: ')
644
381
progress("can't rename unversioned file")
645
runbzr("rename test.txt new-test.txt", 3)
382
runbzr("rename test.txt new-test.txt", 1)
647
384
progress("adding a file")
649
386
runbzr("add test.txt")
650
self.assertEquals(capture("unknowns"), '')
387
assert capture("unknowns") == ''
388
assert capture("status --all") == ("added:\n"
652
391
progress("rename newly-added file")
653
392
runbzr("rename test.txt hello.txt")
654
self.assert_(os.path.exists("hello.txt"))
655
self.assert_(not os.path.exists("test.txt"))
393
assert os.path.exists("hello.txt")
394
assert not os.path.exists("test.txt")
657
self.assertEquals(capture("revno"), '0\n')
396
assert capture("revno") == '0\n'
659
398
progress("add first revision")
660
399
runbzr(['commit', '-m', 'add first revision'])
662
401
progress("more complex renames")
664
runbzr("rename hello.txt sub1", 3)
665
runbzr("rename hello.txt sub1/hello.txt", 3)
666
runbzr("move hello.txt sub1", 3)
403
runbzr("rename hello.txt sub1", 1)
404
runbzr("rename hello.txt sub1/hello.txt", 1)
405
runbzr("move hello.txt sub1", 1)
668
407
runbzr("add sub1")
669
408
runbzr("rename sub1 sub2")
670
409
runbzr("move hello.txt sub2")
671
self.assertEqual(capture("relpath sub2/hello.txt"),
672
pathjoin("sub2", "hello.txt\n"))
410
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
674
self.assert_(exists("sub2"))
675
self.assert_(exists("sub2/hello.txt"))
676
self.assert_(not exists("sub1"))
677
self.assert_(not exists("hello.txt"))
412
assert exists("sub2")
413
assert exists("sub2/hello.txt")
414
assert not exists("sub1")
415
assert not exists("hello.txt")
679
417
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
682
420
runbzr('add sub1')
683
421
runbzr('move sub2/hello.txt sub1')
684
self.assert_(not exists('sub2/hello.txt'))
685
self.assert_(exists('sub1/hello.txt'))
422
assert not exists('sub2/hello.txt')
423
assert exists('sub1/hello.txt')
686
424
runbzr('move sub2 sub1')
687
self.assert_(not exists('sub2'))
688
self.assert_(exists('sub1/sub2'))
425
assert not exists('sub2')
426
assert exists('sub1/sub2')
690
428
runbzr(['commit', '-m', 'rename nested subdirectories'])
692
430
chdir('sub1/sub2')
693
431
self.assertEquals(capture('root')[:-1],
694
pathjoin(self.test_dir, 'branch1'))
432
os.path.join(self.test_dir, 'branch1'))
695
433
runbzr('move ../hello.txt .')
696
self.assert_(exists('./hello.txt'))
434
assert exists('./hello.txt')
697
435
self.assertEquals(capture('relpath hello.txt'),
698
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
699
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
436
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
437
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
700
438
runbzr(['commit', '-m', 'move to parent directory'])
702
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
440
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
704
442
runbzr('move sub2/hello.txt .')
705
self.assert_(exists('hello.txt'))
443
assert exists('hello.txt')
707
445
f = file('hello.txt', 'wt')
708
446
f.write('some nice new content\n')
711
449
f = file('msg.tmp', 'wt')
712
f.write('this is my new commit\nand it has multiple lines, for fun')
450
f.write('this is my new commit\n')
715
453
runbzr('commit -F msg.tmp')
717
self.assertEquals(capture('revno'), '5\n')
455
assert capture('revno') == '5\n'
718
456
runbzr('export -r 5 export-5.tmp')
719
457
runbzr('export export.tmp')
723
461
runbzr('log -v --forward')
724
runbzr('log -m', retcode=3)
462
runbzr('log -m', retcode=1)
725
463
log_out = capture('log -m commit')
726
self.assert_("this is my new commit\n and" in log_out)
727
self.assert_("rename nested" not in log_out)
728
self.assert_('revision-id' not in log_out)
729
self.assert_('revision-id' in capture('log --show-ids -m commit'))
464
assert "this is my new commit" in log_out
465
assert "rename nested" not in log_out
466
assert 'revision-id' not in log_out
467
assert 'revision-id' in capture('log --show-ids -m commit')
731
log_out = capture('log --line')
732
# determine the widest line we want
733
max_width = terminal_width() - 1
734
for line in log_out.splitlines():
735
self.assert_(len(line) <= max_width, len(line))
736
self.assert_("this is my new commit and" not in log_out)
737
self.assert_("this is my new commit" in log_out)
739
470
progress("file with spaces in name")
740
471
mkdir('sub directory')
741
472
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
743
runbzr('diff', retcode=1)
744
475
runbzr('commit -m add-spaces')
757
os.symlink("NOWHERE1", "link1")
759
self.assertEquals(self.capture('unknowns'), '')
760
runbzr(['commit', '-m', '1: added symlink link1'])
764
self.assertEquals(self.capture('unknowns'), '')
765
os.symlink("NOWHERE2", "d1/link2")
766
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
767
# is d1/link2 found when adding d1
769
self.assertEquals(self.capture('unknowns'), '')
770
os.symlink("NOWHERE3", "d1/link3")
771
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
772
runbzr(['commit', '-m', '2: added dir, symlink'])
774
runbzr('rename d1 d2')
775
runbzr('move d2/link2 .')
776
runbzr('move link1 d2')
777
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
778
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
779
runbzr('add d2/link3')
780
runbzr('diff', retcode=1)
781
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
784
os.symlink("TARGET 2", "link2")
785
os.unlink("d2/link1")
786
os.symlink("TARGET 1", "d2/link1")
787
runbzr('diff', retcode=1)
788
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
789
runbzr(['commit', '-m', '4: retarget of two links'])
791
runbzr('remove d2/link1')
792
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
793
runbzr(['commit', '-m', '5: remove d2/link1'])
794
# try with the rm alias
795
runbzr('add d2/link1')
796
runbzr(['commit', '-m', '6: add d2/link1'])
797
runbzr('rm d2/link1')
798
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
799
runbzr(['commit', '-m', '7: remove d2/link1'])
803
runbzr('rename d2/link3 d1/link3new')
804
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
805
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
809
runbzr(['export', '-r', '1', 'exp1.tmp'])
811
self.assertEquals(listdir_sorted("."), [ "link1" ])
812
self.assertEquals(os.readlink("link1"), "NOWHERE1")
815
runbzr(['export', '-r', '2', 'exp2.tmp'])
817
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
820
runbzr(['export', '-r', '3', 'exp3.tmp'])
822
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
823
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
824
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
825
self.assertEquals(os.readlink("link2") , "NOWHERE2")
828
runbzr(['export', '-r', '4', 'exp4.tmp'])
830
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
831
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
832
self.assertEquals(os.readlink("link2") , "TARGET 2")
833
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
836
runbzr(['export', '-r', '5', 'exp5.tmp'])
838
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
839
self.assert_(os.path.islink("link2"))
840
self.assert_(listdir_sorted("d2")== [ "link3" ])
843
runbzr(['export', '-r', '8', 'exp6.tmp'])
845
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
846
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
847
self.assertEquals(listdir_sorted("d2"), [])
848
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
851
progress("skipping symlink tests")
854
class RemoteTests(object):
855
"""Test bzr ui commands against remote branches."""
857
def test_branch(self):
859
wt = self.make_branch_and_tree('from')
861
wt.commit('empty commit for nonsense', allow_pointless=True)
862
url = self.get_readonly_url('from')
863
self.run_bzr('branch', url, 'to')
864
branch = Branch.open('to')
865
self.assertEqual(1, len(branch.revision_history()))
866
# the branch should be set in to to from
867
self.assertEqual(url + '/', branch.get_parent())
870
self.build_tree(['branch/', 'branch/file'])
871
self.capture('init branch')
872
self.capture('add branch/file')
873
self.capture('commit -m foo branch')
874
url = self.get_readonly_url('branch/file')
875
output = self.capture('log %s' % url)
876
self.assertEqual(8, len(output.split('\n')))
878
def test_check(self):
879
self.build_tree(['branch/', 'branch/file'])
880
self.capture('init branch')
881
self.capture('add branch/file')
882
self.capture('commit -m foo branch')
883
url = self.get_readonly_url('branch/')
884
self.run_bzr('check', url)
887
# create a source branch
888
os.mkdir('my-branch')
889
os.chdir('my-branch')
891
file('hello', 'wt').write('foo')
892
self.run_bzr('add', 'hello')
893
self.run_bzr('commit', '-m', 'setup')
895
# with an explicit target work
896
self.run_bzr('push', self.get_url('output-branch'))
899
class HTTPTests(TestCaseWithWebserver, RemoteTests):
900
"""Test various commands against a HTTP server."""
903
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
904
"""Test various commands against a SFTP server using abs paths."""
907
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
908
"""Test various commands against a SFTP server using abs paths."""
911
super(SFTPTestsAbsoluteSibling, self).setUp()
912
self._override_home = '/dev/noone/runs/tests/here'
915
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
916
"""Test various commands against a SFTP server using homedir rel paths."""
919
super(SFTPTestsRelative, self).setUp()
920
self._get_remote_is_absolute = False