1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr.
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface. This doesn't actually run a new interpreter but
23
rather starts again from the run_bzr function.
27
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
28
# Note: Please don't add new tests here, it's too big and bulky. Instead add
29
# them into small suites for the particular function that's tested.
32
from cStringIO import StringIO
38
from bzrlib.branch import Branch
39
from bzrlib.clone import copy_branch
40
from bzrlib.errors import BzrCommandError
41
from bzrlib.osutils import has_symlinks
42
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
43
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
46
class ExternalBase(TestCaseInTempDir):
48
def runbzr(self, args, retcode=0, backtick=False):
49
if isinstance(args, basestring):
53
return self.run_bzr_captured(args, retcode=retcode)[0]
55
return self.run_bzr_captured(args, retcode=retcode)
58
class TestCommands(ExternalBase):
60
def test_help_commands(self):
63
self.runbzr('help commands')
64
self.runbzr('help help')
65
self.runbzr('commit -h')
67
def test_init_branch(self):
70
# Can it handle subdirectories as well?
71
self.runbzr('init subdir1')
72
self.assert_(os.path.exists('subdir1'))
73
self.assert_(os.path.exists('subdir1/.bzr'))
75
self.runbzr('init subdir2/nothere', retcode=3)
78
self.runbzr('init subdir2')
79
self.runbzr('init subdir2', retcode=3)
81
self.runbzr('init subdir2/subsubdir1')
82
self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
84
def test_whoami(self):
85
# this should always identify something, if only "john@localhost"
87
self.runbzr("whoami --email")
89
self.assertEquals(self.runbzr("whoami --email",
90
backtick=True).count('@'), 1)
92
def test_whoami_branch(self):
93
"""branch specific user identity works."""
95
f = file('.bzr/email', 'wt')
96
f.write('Branch Identity <branch@identi.ty>')
98
bzr_email = os.environ.get('BZREMAIL')
99
if bzr_email is not None:
100
del os.environ['BZREMAIL']
101
whoami = self.runbzr("whoami",backtick=True)
102
whoami_email = self.runbzr("whoami --email",backtick=True)
103
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
104
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
105
# Verify that the environment variable overrides the value
107
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
108
whoami = self.runbzr("whoami",backtick=True)
109
whoami_email = self.runbzr("whoami --email",backtick=True)
110
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
111
self.assertTrue(whoami_email.startswith('other@environ.ment'))
112
if bzr_email is not None:
113
os.environ['BZREMAIL'] = bzr_email
115
def test_nick_command(self):
116
"""bzr nick for viewing, setting nicknames"""
120
nick = self.runbzr("nick",backtick=True)
121
self.assertEqual(nick, 'me.dev\n')
122
nick = self.runbzr("nick moo")
123
nick = self.runbzr("nick",backtick=True)
124
self.assertEqual(nick, 'moo\n')
127
def test_invalid_commands(self):
128
self.runbzr("pants", retcode=3)
129
self.runbzr("--pants off", retcode=3)
130
self.runbzr("diff --message foo", retcode=3)
132
def test_empty_commit(self):
134
self.build_tree(['hello.txt'])
135
self.runbzr("commit -m empty", retcode=3)
136
self.runbzr("add hello.txt")
137
self.runbzr("commit -m added")
139
def test_empty_commit_message(self):
141
file('foo.c', 'wt').write('int main() {}')
142
self.runbzr(['add', 'foo.c'])
143
self.runbzr(["commit", "-m", ""] , retcode=3)
145
def test_other_branch_commit(self):
146
# this branch is to ensure consistent behaviour, whether we're run
147
# inside a branch, or not.
148
os.mkdir('empty_branch')
149
os.chdir('empty_branch')
154
file('foo.c', 'wt').write('int main() {}')
155
file('bar.c', 'wt').write('int main() {}')
157
self.runbzr(['add', 'branch/foo.c'])
158
self.runbzr(['add', 'branch'])
159
# can't commit files in different trees; sane error
160
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
161
self.runbzr('commit -m newstuff branch/foo.c')
162
self.runbzr('commit -m newstuff branch')
163
self.runbzr('commit -m newstuff branch', retcode=3)
166
def test_ignore_patterns(self):
167
from bzrlib.branch import Branch
169
b = Branch.initialize('.')
170
self.assertEquals(list(b.unknowns()), [])
172
file('foo.tmp', 'wt').write('tmp files are ignored')
173
self.assertEquals(list(b.unknowns()), [])
174
self.assertEquals(self.capture('unknowns'), '')
176
file('foo.c', 'wt').write('int main() {}')
177
self.assertEquals(list(b.unknowns()), ['foo.c'])
178
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
180
self.runbzr(['add', 'foo.c'])
181
self.assertEquals(self.capture('unknowns'), '')
183
# 'ignore' works when creating the .bzignore file
184
file('foo.blah', 'wt').write('blah')
185
self.assertEquals(list(b.unknowns()), ['foo.blah'])
186
self.runbzr('ignore *.blah')
187
self.assertEquals(list(b.unknowns()), [])
188
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
190
# 'ignore' works when then .bzrignore file already exists
191
file('garh', 'wt').write('garh')
192
self.assertEquals(list(b.unknowns()), ['garh'])
193
self.assertEquals(self.capture('unknowns'), 'garh\n')
194
self.runbzr('ignore garh')
195
self.assertEquals(list(b.unknowns()), [])
196
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
198
def test_revert(self):
201
file('hello', 'wt').write('foo')
202
self.runbzr('add hello')
203
self.runbzr('commit -m setup hello')
205
file('goodbye', 'wt').write('baz')
206
self.runbzr('add goodbye')
207
self.runbzr('commit -m setup goodbye')
209
file('hello', 'wt').write('bar')
210
file('goodbye', 'wt').write('qux')
211
self.runbzr('revert hello')
212
self.check_file_contents('hello', 'foo')
213
self.check_file_contents('goodbye', 'qux')
214
self.runbzr('revert')
215
self.check_file_contents('goodbye', 'baz')
217
os.mkdir('revertdir')
218
self.runbzr('add revertdir')
219
self.runbzr('commit -m f')
220
os.rmdir('revertdir')
221
self.runbzr('revert')
223
os.symlink('/unlikely/to/exist', 'symlink')
224
self.runbzr('add symlink')
225
self.runbzr('commit -m f')
227
self.runbzr('revert')
228
self.failUnlessExists('symlink')
230
os.symlink('a-different-path', 'symlink')
231
self.runbzr('revert')
232
self.assertEqual('/unlikely/to/exist',
233
os.readlink('symlink'))
235
file('hello', 'wt').write('xyz')
236
self.runbzr('commit -m xyz hello')
237
self.runbzr('revert -r 1 hello')
238
self.check_file_contents('hello', 'foo')
239
self.runbzr('revert hello')
240
self.check_file_contents('hello', 'xyz')
241
os.chdir('revertdir')
242
self.runbzr('revert')
245
def test_status(self):
247
self.build_tree(['hello.txt'])
248
result = self.runbzr("status")
249
self.assert_("unknown:\n hello.txt\n" in result, result)
250
self.runbzr("add hello.txt")
251
result = self.runbzr("status")
252
self.assert_("added:\n hello.txt\n" in result, result)
253
self.runbzr("commit -m added")
254
result = self.runbzr("status -r 0..1")
255
self.assert_("added:\n hello.txt\n" in result, result)
256
self.build_tree(['world.txt'])
257
result = self.runbzr("status -r 0")
258
self.assert_("added:\n hello.txt\n" \
259
"unknown:\n world.txt\n" in result, result)
261
def test_mv_modes(self):
262
"""Test two modes of operation for mv"""
263
from bzrlib.branch import Branch
264
b = Branch.initialize('.')
265
self.build_tree(['a', 'c', 'subdir/'])
266
self.run_bzr_captured(['add', self.test_dir])
267
self.run_bzr_captured(['mv', 'a', 'b'])
268
self.run_bzr_captured(['mv', 'b', 'subdir'])
269
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
270
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
271
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
273
def test_main_version(self):
274
"""Check output from version command and master option is reasonable"""
275
# output is intentionally passed through to stdout so that we
276
# can see the version being tested
277
output = self.runbzr('version', backtick=1)
278
self.log('bzr version output:')
280
self.assert_(output.startswith('bzr (bazaar-ng) '))
281
self.assertNotEqual(output.index('Canonical'), -1)
282
# make sure --version is consistent
283
tmp_output = self.runbzr('--version', backtick=1)
284
self.log('bzr --version output:')
286
self.assertEquals(output, tmp_output)
288
def example_branch(test):
290
file('hello', 'wt').write('foo')
291
test.runbzr('add hello')
292
test.runbzr('commit -m setup hello')
293
file('goodbye', 'wt').write('baz')
294
test.runbzr('add goodbye')
295
test.runbzr('commit -m setup goodbye')
297
def test_export(self):
300
self.example_branch()
301
self.runbzr('export ../latest')
302
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
303
self.runbzr('export ../first -r 1')
304
self.assert_(not os.path.exists('../first/goodbye'))
305
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
306
self.runbzr('export ../first.gz -r 1')
307
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
308
self.runbzr('export ../first.bz2 -r 1')
309
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
310
self.runbzr('export ../first.tar -r 1')
311
self.assert_(os.path.isfile('../first.tar'))
312
from tarfile import TarFile
313
tf = TarFile('../first.tar')
314
self.assert_('first/hello' in tf.getnames(), tf.getnames())
315
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
316
self.runbzr('export ../first.tar.gz -r 1')
317
self.assert_(os.path.isfile('../first.tar.gz'))
318
self.runbzr('export ../first.tbz2 -r 1')
319
self.assert_(os.path.isfile('../first.tbz2'))
320
self.runbzr('export ../first.tar.bz2 -r 1')
321
self.assert_(os.path.isfile('../first.tar.bz2'))
322
self.runbzr('export ../first.tar.tbz2 -r 1')
323
self.assert_(os.path.isfile('../first.tar.tbz2'))
324
from bz2 import BZ2File
325
tf = TarFile('../first.tar.tbz2',
326
fileobj=BZ2File('../first.tar.tbz2', 'r'))
327
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
328
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
329
self.runbzr('export ../first2.tar -r 1 --root pizza')
330
tf = TarFile('../first2.tar')
331
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
334
self.example_branch()
335
file('hello', 'wt').write('hello world!')
336
self.runbzr('commit -m fixing hello')
337
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
338
self.assert_('\n+hello world!' in output)
339
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
340
self.assert_('\n+baz' in output)
341
file('moo', 'wb').write('moo')
342
self.runbzr('add moo')
346
def test_diff_branches(self):
347
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
348
branch = Branch.initialize('branch1')
350
branch.commit('add file')
351
copy_branch(branch, 'branch2')
352
print >> open('branch2/file', 'w'), 'new content'
353
branch2 = Branch.open('branch2')
354
branch2.commit('update file')
355
# should open branch1 and diff against branch2,
356
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
359
self.assertEquals(("=== modified file 'file'\n"
364
"+contents of branch1/file\n"
366
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
368
self.assertEqualDiff(("=== modified file 'file'\n"
373
"+contents of branch1/file\n"
377
def test_branch(self):
378
"""Branch from one branch to another."""
381
self.example_branch()
383
self.runbzr('branch a b')
384
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
385
self.runbzr('branch a c -r 1')
387
self.runbzr('commit -m foo --unchanged')
389
# naughty - abstraction violations RBC 20050928
390
print "test_branch used to delete the stores, how is this meant to work ?"
391
#shutil.rmtree('a/.bzr/revision-store')
392
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
393
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
394
self.runbzr('branch a d --basis b')
396
def test_merge(self):
397
from bzrlib.branch import Branch
401
self.example_branch()
403
self.runbzr('branch a b')
405
file('goodbye', 'wt').write('quux')
406
self.runbzr(['commit', '-m', "more u's are always good"])
409
file('hello', 'wt').write('quuux')
410
# We can't merge when there are in-tree changes
411
self.runbzr('merge ../b', retcode=3)
412
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
413
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
415
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
416
self.runbzr('revert --no-backup')
417
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
418
self.runbzr('revert --no-backup')
419
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
420
self.runbzr('revert --no-backup')
421
self.runbzr('merge ../b -r last:1')
422
self.check_file_contents('goodbye', 'quux')
423
# Merging a branch pulls its revision into the tree
425
b = Branch.open('../b')
426
a.get_revision_xml(b.last_revision())
427
self.log('pending merges: %s', a.pending_merges())
428
self.assertEquals(a.pending_merges(), [b.last_revision()])
429
self.runbzr('commit -m merged')
430
self.runbzr('merge ../b -r last:1')
431
self.assertEqual(Branch.open('.').pending_merges(), [])
434
def test_merge_with_missing_file(self):
435
"""Merge handles missing file conflicts"""
439
print >> file('sub/a.txt', 'wb'), "hello"
440
print >> file('b.txt', 'wb'), "hello"
441
print >> file('sub/c.txt', 'wb'), "hello"
444
self.runbzr(('commit', '-m', 'added a'))
445
self.runbzr('branch . ../b')
446
print >> file('sub/a.txt', 'ab'), "there"
447
print >> file('b.txt', 'ab'), "there"
448
print >> file('sub/c.txt', 'ab'), "there"
449
self.runbzr(('commit', '-m', 'Added there'))
450
os.unlink('sub/a.txt')
451
os.unlink('sub/c.txt')
454
self.runbzr(('commit', '-m', 'Removed a.txt'))
456
print >> file('sub/a.txt', 'ab'), "something"
457
print >> file('b.txt', 'ab'), "something"
458
print >> file('sub/c.txt', 'ab'), "something"
459
self.runbzr(('commit', '-m', 'Modified a.txt'))
460
self.runbzr('merge ../a/', retcode=1)
461
self.assert_(os.path.exists('sub/a.txt.THIS'))
462
self.assert_(os.path.exists('sub/a.txt.BASE'))
464
self.runbzr('merge ../b/', retcode=1)
465
self.assert_(os.path.exists('sub/a.txt.OTHER'))
466
self.assert_(os.path.exists('sub/a.txt.BASE'))
469
"""Pull changes from one branch to another."""
473
self.example_branch()
474
self.runbzr('pull', retcode=3)
475
self.runbzr('missing', retcode=3)
476
self.runbzr('missing .')
477
self.runbzr('missing')
479
self.runbzr('pull /', retcode=3)
483
self.runbzr('branch a b')
487
self.runbzr('add subdir')
488
self.runbzr('commit -m blah --unchanged')
491
b = Branch.open('../b')
492
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
493
self.runbzr('pull ../b')
494
self.assertEquals(a.revision_history(), b.revision_history())
495
self.runbzr('commit -m blah2 --unchanged')
497
self.runbzr('commit -m blah3 --unchanged')
499
self.runbzr('pull ../a', retcode=3)
501
self.runbzr('branch b overwriteme')
502
os.chdir('overwriteme')
503
self.runbzr('pull --overwrite ../a')
504
overwritten = Branch.open('.')
505
self.assertEqual(overwritten.revision_history(),
506
a.revision_history())
508
self.runbzr('merge ../b')
509
self.runbzr('commit -m blah4 --unchanged')
510
os.chdir('../b/subdir')
511
self.runbzr('pull ../../a')
512
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
513
self.runbzr('commit -m blah5 --unchanged')
514
self.runbzr('commit -m blah6 --unchanged')
516
self.runbzr('pull ../a')
518
self.runbzr('commit -m blah7 --unchanged')
519
self.runbzr('merge ../b')
520
self.runbzr('commit -m blah8 --unchanged')
521
self.runbzr('pull ../b')
522
self.runbzr('pull ../b')
525
"""Test the abilities of 'bzr ls'"""
527
def bzrout(*args, **kwargs):
528
kwargs['backtick'] = True
529
return self.runbzr(*args, **kwargs)
531
def ls_equals(value, *args):
532
out = self.runbzr(['ls'] + list(args), backtick=True)
533
self.assertEquals(out, value)
536
open('a', 'wb').write('hello\n')
539
bzr('ls --verbose --null', retcode=3)
542
ls_equals('? a\n', '--verbose')
543
ls_equals('a\n', '--unknown')
544
ls_equals('', '--ignored')
545
ls_equals('', '--versioned')
546
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
547
ls_equals('', '--ignored', '--versioned')
548
ls_equals('a\0', '--null')
551
ls_equals('V a\n', '--verbose')
558
open('subdir/b', 'wb').write('b\n')
564
bzr('commit -m subdir')
572
, '--verbose', '--non-recursive')
574
# Check what happens in a sub-directory
586
, '--from-root', '--null')
589
, '--from-root', '--non-recursive')
593
# Check what happens when we supply a specific revision
594
ls_equals('a\n', '--revision', '1')
596
, '--verbose', '--revision', '1')
599
ls_equals('', '--revision', '1')
601
# Now try to do ignored files.
603
open('blah.py', 'wb').write('unknown\n')
604
open('blah.pyo', 'wb').write('ignored\n')
616
ls_equals('blah.pyo\n'
618
ls_equals('blah.py\n'
626
def test_locations(self):
627
"""Using and remembering different locations"""
631
self.runbzr('commit -m unchanged --unchanged')
632
self.runbzr('pull', retcode=3)
633
self.runbzr('merge', retcode=3)
634
self.runbzr('branch . ../b')
637
self.runbzr('branch . ../c')
638
self.runbzr('pull ../c')
641
self.runbzr('pull ../b')
643
self.runbzr('pull ../c')
644
self.runbzr('branch ../c ../d')
645
shutil.rmtree('../c')
650
self.runbzr('pull', retcode=3)
651
self.runbzr('pull ../a --remember')
654
def test_add_reports(self):
655
"""add command prints the names of added files."""
656
b = Branch.initialize('.')
657
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
658
out = self.run_bzr_captured(['add'], retcode = 0)[0]
659
# the ordering is not defined at the moment
660
results = sorted(out.rstrip('\n').split('\n'))
661
self.assertEquals(['added dir',
662
'added dir'+os.sep+'sub.txt',
666
def test_add_quiet_is(self):
667
"""add -q does not print the names of added files."""
668
b = Branch.initialize('.')
669
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
670
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
671
# the ordering is not defined at the moment
672
results = sorted(out.rstrip('\n').split('\n'))
673
self.assertEquals([''], results)
675
def test_unknown_command(self):
676
"""Handling of unknown command."""
677
out, err = self.run_bzr_captured(['fluffy-badger'],
679
self.assertEquals(out, '')
680
err.index('unknown command')
682
def create_conflicts(self):
683
"""Create a conflicted tree"""
686
file('hello', 'wb').write("hi world")
687
file('answer', 'wb').write("42")
690
self.runbzr('commit -m base')
691
self.runbzr('branch . ../other')
692
self.runbzr('branch . ../this')
694
file('hello', 'wb').write("Hello.")
695
file('answer', 'wb').write("Is anyone there?")
696
self.runbzr('commit -m other')
698
file('hello', 'wb').write("Hello, world")
699
self.runbzr('mv answer question')
700
file('question', 'wb').write("What do you get when you multiply six"
702
self.runbzr('commit -m this')
704
def test_remerge(self):
705
"""Remerge command works as expected"""
706
self.create_conflicts()
707
self.runbzr('merge ../other --show-base', retcode=1)
708
conflict_text = file('hello').read()
709
assert '|||||||' in conflict_text
710
assert 'hi world' in conflict_text
711
self.runbzr('remerge', retcode=1)
712
conflict_text = file('hello').read()
713
assert '|||||||' not in conflict_text
714
assert 'hi world' not in conflict_text
715
os.unlink('hello.OTHER')
716
self.runbzr('remerge hello --merge-type weave', retcode=1)
717
assert os.path.exists('hello.OTHER')
718
file_id = self.runbzr('file-id hello')
719
file_id = self.runbzr('file-id hello.THIS', retcode=3)
720
self.runbzr('remerge --merge-type weave', retcode=1)
721
assert os.path.exists('hello.OTHER')
722
assert not os.path.exists('hello.BASE')
723
assert '|||||||' not in conflict_text
724
assert 'hi world' not in conflict_text
725
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
726
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
727
self.runbzr('remerge . --show-base --reprocess', retcode=3)
728
self.runbzr('remerge hello --show-base', retcode=1)
729
self.runbzr('remerge hello --reprocess', retcode=1)
730
self.runbzr('resolve --all')
731
self.runbzr('commit -m done',)
732
self.runbzr('remerge', retcode=3)
735
def test_conflicts(self):
736
"""Handling of merge conflicts"""
737
self.create_conflicts()
738
self.runbzr('merge ../other --show-base', retcode=1)
739
conflict_text = file('hello').read()
740
self.assert_('<<<<<<<' in conflict_text)
741
self.assert_('>>>>>>>' in conflict_text)
742
self.assert_('=======' in conflict_text)
743
self.assert_('|||||||' in conflict_text)
744
self.assert_('hi world' in conflict_text)
745
self.runbzr('revert')
746
self.runbzr('resolve --all')
747
self.runbzr('merge ../other', retcode=1)
748
conflict_text = file('hello').read()
749
self.assert_('|||||||' not in conflict_text)
750
self.assert_('hi world' not in conflict_text)
751
result = self.runbzr('conflicts', backtick=1)
752
self.assertEquals(result, "hello\nquestion\n")
753
result = self.runbzr('status', backtick=1)
754
self.assert_("conflicts:\n hello\n question\n" in result, result)
755
self.runbzr('resolve hello')
756
result = self.runbzr('conflicts', backtick=1)
757
self.assertEquals(result, "question\n")
758
self.runbzr('commit -m conflicts', retcode=3)
759
self.runbzr('resolve --all')
760
result = self.runbzr('conflicts', backtick=1)
761
self.runbzr('commit -m conflicts')
762
self.assertEquals(result, "")
764
def test_resign(self):
765
"""Test re signing of data."""
767
oldstrategy = bzrlib.gpg.GPGStrategy
768
branch = Branch.initialize('.')
769
branch.commit("base", allow_pointless=True, rev_id='A')
771
# monkey patch gpg signing mechanism
772
from bzrlib.testament import Testament
773
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
774
self.runbzr('re-sign -r revid:A')
775
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
776
branch.revision_store.get('A', 'sig').read())
778
bzrlib.gpg.GPGStrategy = oldstrategy
780
def test_resign_range(self):
782
oldstrategy = bzrlib.gpg.GPGStrategy
783
branch = Branch.initialize('.')
784
branch.commit("base", allow_pointless=True, rev_id='A')
785
branch.commit("base", allow_pointless=True, rev_id='B')
786
branch.commit("base", allow_pointless=True, rev_id='C')
788
# monkey patch gpg signing mechanism
789
from bzrlib.testament import Testament
790
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
791
self.runbzr('re-sign -r 1..')
792
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
793
branch.revision_store.get('A', 'sig').read())
794
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
795
branch.revision_store.get('B', 'sig').read())
796
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
797
branch.revision_store.get('C', 'sig').read())
799
bzrlib.gpg.GPGStrategy = oldstrategy
802
# create a source branch
803
os.mkdir('my-branch')
804
os.chdir('my-branch')
805
self.example_branch()
807
# with no push target, fail
808
self.runbzr('push', retcode=3)
809
# with an explicit target work
810
self.runbzr('push ../output-branch')
811
# with an implicit target work
814
self.runbzr('missing ../output-branch')
815
# advance this branch
816
self.runbzr('commit --unchanged -m unchanged')
818
os.chdir('../output-branch')
819
# should be a diff as we have not pushed the tree
820
self.runbzr('diff', retcode=1)
821
self.runbzr('revert')
824
# diverge the branches
825
self.runbzr('commit --unchanged -m unchanged')
826
os.chdir('../my-branch')
828
self.runbzr('push', retcode=3)
829
# and there are difference
830
self.runbzr('missing ../output-branch', retcode=1)
831
self.runbzr('missing --verbose ../output-branch', retcode=1)
832
# but we can force a push
833
self.runbzr('push --overwrite')
835
self.runbzr('missing ../output-branch')
837
# pushing to a new dir with no parent should fail
838
self.runbzr('push ../missing/new-branch', retcode=3)
839
# unless we provide --create-prefix
840
self.runbzr('push --create-prefix ../missing/new-branch')
842
self.runbzr('missing ../missing/new-branch')
845
def listdir_sorted(dir):
851
class OldTests(ExternalBase):
852
"""old tests moved from ./testbzr."""
855
from os import chdir, mkdir
856
from os.path import exists
859
capture = self.capture
862
progress("basic branch creation")
867
self.assertEquals(capture('root').rstrip(),
868
os.path.join(self.test_dir, 'branch1'))
870
progress("status of new file")
872
f = file('test.txt', 'wt')
873
f.write('hello world!\n')
876
self.assertEquals(capture('unknowns'), 'test.txt\n')
878
out = capture("status")
879
self.assertEquals(out, 'unknown:\n test.txt\n')
881
out = capture("status --all")
882
self.assertEquals(out, "unknown:\n test.txt\n")
884
out = capture("status test.txt --all")
885
self.assertEquals(out, "unknown:\n test.txt\n")
887
f = file('test2.txt', 'wt')
888
f.write('goodbye cruel world...\n')
891
out = capture("status test.txt")
892
self.assertEquals(out, "unknown:\n test.txt\n")
894
out = capture("status")
895
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
897
os.unlink('test2.txt')
899
progress("command aliases")
900
out = capture("st --all")
901
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
903
out = capture("stat")
904
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
906
progress("command help")
909
runbzr("help commands")
910
runbzr("help slartibartfast", 3)
912
out = capture("help ci")
913
out.index('aliases: ')
915
progress("can't rename unversioned file")
916
runbzr("rename test.txt new-test.txt", 3)
918
progress("adding a file")
920
runbzr("add test.txt")
921
self.assertEquals(capture("unknowns"), '')
922
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
924
progress("rename newly-added file")
925
runbzr("rename test.txt hello.txt")
926
self.assert_(os.path.exists("hello.txt"))
927
self.assert_(not os.path.exists("test.txt"))
929
self.assertEquals(capture("revno"), '0\n')
931
progress("add first revision")
932
runbzr(['commit', '-m', 'add first revision'])
934
progress("more complex renames")
936
runbzr("rename hello.txt sub1", 3)
937
runbzr("rename hello.txt sub1/hello.txt", 3)
938
runbzr("move hello.txt sub1", 3)
941
runbzr("rename sub1 sub2")
942
runbzr("move hello.txt sub2")
943
self.assertEqual(capture("relpath sub2/hello.txt"),
944
os.path.join("sub2", "hello.txt\n"))
946
self.assert_(exists("sub2"))
947
self.assert_(exists("sub2/hello.txt"))
948
self.assert_(not exists("sub1"))
949
self.assert_(not exists("hello.txt"))
951
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
955
runbzr('move sub2/hello.txt sub1')
956
self.assert_(not exists('sub2/hello.txt'))
957
self.assert_(exists('sub1/hello.txt'))
958
runbzr('move sub2 sub1')
959
self.assert_(not exists('sub2'))
960
self.assert_(exists('sub1/sub2'))
962
runbzr(['commit', '-m', 'rename nested subdirectories'])
965
self.assertEquals(capture('root')[:-1],
966
os.path.join(self.test_dir, 'branch1'))
967
runbzr('move ../hello.txt .')
968
self.assert_(exists('./hello.txt'))
969
self.assertEquals(capture('relpath hello.txt'),
970
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
971
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
972
runbzr(['commit', '-m', 'move to parent directory'])
974
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
976
runbzr('move sub2/hello.txt .')
977
self.assert_(exists('hello.txt'))
979
f = file('hello.txt', 'wt')
980
f.write('some nice new content\n')
983
f = file('msg.tmp', 'wt')
984
f.write('this is my new commit\nand it has multiple lines, for fun')
987
runbzr('commit -F msg.tmp')
989
self.assertEquals(capture('revno'), '5\n')
990
runbzr('export -r 5 export-5.tmp')
991
runbzr('export export.tmp')
995
runbzr('log -v --forward')
996
runbzr('log -m', retcode=3)
997
log_out = capture('log -m commit')
998
self.assert_("this is my new commit\n and" in log_out)
999
self.assert_("rename nested" not in log_out)
1000
self.assert_('revision-id' not in log_out)
1001
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1003
log_out = capture('log --line')
1004
for line in log_out.splitlines():
1005
self.assert_(len(line) <= 79, len(line))
1006
self.assert_("this is my new commit and" in log_out)
1009
progress("file with spaces in name")
1010
mkdir('sub directory')
1011
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1013
runbzr('diff', retcode=1)
1014
runbzr('commit -m add-spaces')
1018
runbzr('log --forward')
1023
progress("symlinks")
1027
os.symlink("NOWHERE1", "link1")
1029
self.assertEquals(self.capture('unknowns'), '')
1030
runbzr(['commit', '-m', '1: added symlink link1'])
1034
self.assertEquals(self.capture('unknowns'), '')
1035
os.symlink("NOWHERE2", "d1/link2")
1036
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1037
# is d1/link2 found when adding d1
1039
self.assertEquals(self.capture('unknowns'), '')
1040
os.symlink("NOWHERE3", "d1/link3")
1041
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1042
runbzr(['commit', '-m', '2: added dir, symlink'])
1044
runbzr('rename d1 d2')
1045
runbzr('move d2/link2 .')
1046
runbzr('move link1 d2')
1047
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1048
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1049
runbzr('add d2/link3')
1050
runbzr('diff', retcode=1)
1051
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1054
os.symlink("TARGET 2", "link2")
1055
os.unlink("d2/link1")
1056
os.symlink("TARGET 1", "d2/link1")
1057
runbzr('diff', retcode=1)
1058
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1059
runbzr(['commit', '-m', '4: retarget of two links'])
1061
runbzr('remove d2/link1')
1062
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1063
runbzr(['commit', '-m', '5: remove d2/link1'])
1064
# try with the rm alias
1065
runbzr('add d2/link1')
1066
runbzr(['commit', '-m', '6: add d2/link1'])
1067
runbzr('rm d2/link1')
1068
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1069
runbzr(['commit', '-m', '7: remove d2/link1'])
1073
runbzr('rename d2/link3 d1/link3new')
1074
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1075
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1079
runbzr(['export', '-r', '1', 'exp1.tmp'])
1081
self.assertEquals(listdir_sorted("."), [ "link1" ])
1082
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1085
runbzr(['export', '-r', '2', 'exp2.tmp'])
1087
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1090
runbzr(['export', '-r', '3', 'exp3.tmp'])
1092
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1093
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1094
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1095
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1098
runbzr(['export', '-r', '4', 'exp4.tmp'])
1100
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1101
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1102
self.assertEquals(os.readlink("link2") , "TARGET 2")
1103
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1106
runbzr(['export', '-r', '5', 'exp5.tmp'])
1108
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1109
self.assert_(os.path.islink("link2"))
1110
self.assert_(listdir_sorted("d2")== [ "link3" ])
1113
runbzr(['export', '-r', '8', 'exp6.tmp'])
1115
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1116
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1117
self.assertEquals(listdir_sorted("d2"), [])
1118
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1121
progress("skipping symlink tests")
1124
class HttpTests(TestCaseWithWebserver):
1125
"""Test bzr ui commands against remote branches."""
1127
def test_branch(self):
1129
branch = Branch.initialize('from')
1130
branch.commit('empty commit for nonsense', allow_pointless=True)
1131
url = self.get_remote_url('from')
1132
self.run_bzr('branch', url, 'to')
1133
branch = Branch.open('to')
1134
self.assertEqual(1, len(branch.revision_history()))
1137
self.build_tree(['branch/', 'branch/file'])
1138
branch = Branch.initialize('branch')
1139
branch.add(['file'])
1140
branch.commit('add file', rev_id='A')
1141
url = self.get_remote_url('branch/file')
1142
output = self.capture('log %s' % url)
1143
self.assertEqual(8, len(output.split('\n')))