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=2)
78
self.runbzr('init subdir2')
79
self.runbzr('init subdir2', retcode=1)
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_invalid_commands(self):
116
self.runbzr("pants", retcode=1)
117
self.runbzr("--pants off", retcode=1)
118
self.runbzr("diff --message foo", retcode=1)
120
def test_empty_commit(self):
122
self.build_tree(['hello.txt'])
123
self.runbzr("commit -m empty", retcode=1)
124
self.runbzr("add hello.txt")
125
self.runbzr("commit -m added")
127
def test_empty_commit_message(self):
129
file('foo.c', 'wt').write('int main() {}')
130
self.runbzr(['add', 'foo.c'])
131
self.runbzr(["commit", "-m", ""] , retcode=1)
133
def test_other_branch_commit(self):
134
# this branch is to ensure consistent behaviour, whether we're run
135
# inside a branch, or not.
136
os.mkdir('empty_branch')
137
os.chdir('empty_branch')
142
file('foo.c', 'wt').write('int main() {}')
143
file('bar.c', 'wt').write('int main() {}')
145
self.runbzr(['add', 'branch/foo.c'])
146
self.runbzr(['add', 'branch'])
147
# can't commit files in different trees; sane error
148
self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
149
self.runbzr('commit -m newstuff branch/foo.c')
150
self.runbzr('commit -m newstuff branch')
151
self.runbzr('commit -m newstuff branch', retcode=1)
154
def test_ignore_patterns(self):
155
from bzrlib.branch import Branch
157
b = Branch.initialize('.')
158
self.assertEquals(list(b.unknowns()), [])
160
file('foo.tmp', 'wt').write('tmp files are ignored')
161
self.assertEquals(list(b.unknowns()), [])
162
self.assertEquals(self.capture('unknowns'), '')
164
file('foo.c', 'wt').write('int main() {}')
165
self.assertEquals(list(b.unknowns()), ['foo.c'])
166
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
168
self.runbzr(['add', 'foo.c'])
169
self.assertEquals(self.capture('unknowns'), '')
171
# 'ignore' works when creating the .bzignore file
172
file('foo.blah', 'wt').write('blah')
173
self.assertEquals(list(b.unknowns()), ['foo.blah'])
174
self.runbzr('ignore *.blah')
175
self.assertEquals(list(b.unknowns()), [])
176
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
178
# 'ignore' works when then .bzrignore file already exists
179
file('garh', 'wt').write('garh')
180
self.assertEquals(list(b.unknowns()), ['garh'])
181
self.assertEquals(self.capture('unknowns'), 'garh\n')
182
self.runbzr('ignore garh')
183
self.assertEquals(list(b.unknowns()), [])
184
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
186
def test_revert(self):
189
file('hello', 'wt').write('foo')
190
self.runbzr('add hello')
191
self.runbzr('commit -m setup hello')
193
file('goodbye', 'wt').write('baz')
194
self.runbzr('add goodbye')
195
self.runbzr('commit -m setup goodbye')
197
file('hello', 'wt').write('bar')
198
file('goodbye', 'wt').write('qux')
199
self.runbzr('revert hello')
200
self.check_file_contents('hello', 'foo')
201
self.check_file_contents('goodbye', 'qux')
202
self.runbzr('revert')
203
self.check_file_contents('goodbye', 'baz')
205
os.mkdir('revertdir')
206
self.runbzr('add revertdir')
207
self.runbzr('commit -m f')
208
os.rmdir('revertdir')
209
self.runbzr('revert')
211
os.symlink('/unlikely/to/exist', 'symlink')
212
self.runbzr('add symlink')
213
self.runbzr('commit -m f')
215
self.runbzr('revert')
216
self.failUnlessExists('symlink')
218
os.symlink('a-different-path', 'symlink')
219
self.runbzr('revert')
220
self.assertEqual('/unlikely/to/exist',
221
os.readlink('symlink'))
223
file('hello', 'wt').write('xyz')
224
self.runbzr('commit -m xyz hello')
225
self.runbzr('revert -r 1 hello')
226
self.check_file_contents('hello', 'foo')
227
self.runbzr('revert hello')
228
self.check_file_contents('hello', 'xyz')
229
os.chdir('revertdir')
230
self.runbzr('revert')
233
def test_status(self):
235
self.build_tree(['hello.txt'])
236
result = self.runbzr("status")
237
self.assert_("unknown:\n hello.txt\n" in result, result)
238
self.runbzr("add hello.txt")
239
result = self.runbzr("status")
240
self.assert_("added:\n hello.txt\n" in result, result)
241
self.runbzr("commit -m added")
242
result = self.runbzr("status -r 0..1")
243
self.assert_("added:\n hello.txt\n" in result, result)
244
self.build_tree(['world.txt'])
245
result = self.runbzr("status -r 0")
246
self.assert_("added:\n hello.txt\n" \
247
"unknown:\n world.txt\n" in result, result)
249
def test_mv_modes(self):
250
"""Test two modes of operation for mv"""
251
from bzrlib.branch import Branch
252
b = Branch.initialize('.')
253
self.build_tree(['a', 'c', 'subdir/'])
254
self.run_bzr_captured(['add', self.test_dir])
255
self.run_bzr_captured(['mv', 'a', 'b'])
256
self.run_bzr_captured(['mv', 'b', 'subdir'])
257
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
258
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
259
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
261
def test_main_version(self):
262
"""Check output from version command and master option is reasonable"""
263
# output is intentionally passed through to stdout so that we
264
# can see the version being tested
265
output = self.runbzr('version', backtick=1)
266
self.log('bzr version output:')
268
self.assert_(output.startswith('bzr (bazaar-ng) '))
269
self.assertNotEqual(output.index('Canonical'), -1)
270
# make sure --version is consistent
271
tmp_output = self.runbzr('--version', backtick=1)
272
self.log('bzr --version output:')
274
self.assertEquals(output, tmp_output)
276
def example_branch(test):
278
file('hello', 'wt').write('foo')
279
test.runbzr('add hello')
280
test.runbzr('commit -m setup hello')
281
file('goodbye', 'wt').write('baz')
282
test.runbzr('add goodbye')
283
test.runbzr('commit -m setup goodbye')
285
def test_export(self):
288
self.example_branch()
289
self.runbzr('export ../latest')
290
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
291
self.runbzr('export ../first -r 1')
292
self.assert_(not os.path.exists('../first/goodbye'))
293
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
294
self.runbzr('export ../first.gz -r 1')
295
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
296
self.runbzr('export ../first.bz2 -r 1')
297
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
298
self.runbzr('export ../first.tar -r 1')
299
self.assert_(os.path.isfile('../first.tar'))
300
from tarfile import TarFile
301
tf = TarFile('../first.tar')
302
self.assert_('first/hello' in tf.getnames(), tf.getnames())
303
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
304
self.runbzr('export ../first.tar.gz -r 1')
305
self.assert_(os.path.isfile('../first.tar.gz'))
306
self.runbzr('export ../first.tbz2 -r 1')
307
self.assert_(os.path.isfile('../first.tbz2'))
308
self.runbzr('export ../first.tar.bz2 -r 1')
309
self.assert_(os.path.isfile('../first.tar.bz2'))
310
self.runbzr('export ../first.tar.tbz2 -r 1')
311
self.assert_(os.path.isfile('../first.tar.tbz2'))
312
from bz2 import BZ2File
313
tf = TarFile('../first.tar.tbz2',
314
fileobj=BZ2File('../first.tar.tbz2', 'r'))
315
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
316
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
317
self.runbzr('export ../first2.tar -r 1 --root pizza')
318
tf = TarFile('../first2.tar')
319
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
322
self.example_branch()
323
file('hello', 'wt').write('hello world!')
324
self.runbzr('commit -m fixing hello')
325
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
326
self.assert_('\n+hello world!' in output)
327
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
328
self.assert_('\n+baz' in output)
330
def test_diff_branches(self):
331
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
332
branch = Branch.initialize('branch1')
334
branch.commit('add file')
335
copy_branch(branch, 'branch2')
336
print >> open('branch2/file', 'w'), 'new content'
337
branch2 = Branch.open('branch2')
338
branch2.commit('update file')
339
# should open branch1 and diff against branch2,
340
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
343
self.assertEquals(("=== modified file 'file'\n"
348
"+contents of branch1/file\n"
351
def test_branch(self):
352
"""Branch from one branch to another."""
355
self.example_branch()
357
self.runbzr('branch a b')
358
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
359
self.runbzr('branch a c -r 1')
361
self.runbzr('commit -m foo --unchanged')
363
# naughty - abstraction violations RBC 20050928
364
print "test_branch used to delete the stores, how is this meant to work ?"
365
#shutil.rmtree('a/.bzr/revision-store')
366
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
367
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
368
self.runbzr('branch a d --basis b')
370
def test_merge(self):
371
from bzrlib.branch import Branch
375
self.example_branch()
377
self.runbzr('branch a b')
379
file('goodbye', 'wt').write('quux')
380
self.runbzr(['commit', '-m', "more u's are always good"])
383
file('hello', 'wt').write('quuux')
384
# We can't merge when there are in-tree changes
385
self.runbzr('merge ../b', retcode=1)
386
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
387
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
389
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
390
self.runbzr('revert --no-backup')
391
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
392
self.runbzr('revert --no-backup')
393
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
394
self.runbzr('revert --no-backup')
395
self.runbzr('merge ../b -r last:1')
396
self.check_file_contents('goodbye', 'quux')
397
# Merging a branch pulls its revision into the tree
399
b = Branch.open('../b')
400
a.get_revision_xml(b.last_revision())
401
self.log('pending merges: %s', a.pending_merges())
402
self.assertEquals(a.pending_merges(), [b.last_revision()])
403
self.runbzr('commit -m merged')
404
self.runbzr('merge ../b -r last:1')
405
self.assertEqual(Branch.open('.').pending_merges(), [])
408
def test_merge_with_missing_file(self):
409
"""Merge handles missing file conflicts"""
413
print >> file('sub/a.txt', 'wb'), "hello"
414
print >> file('b.txt', 'wb'), "hello"
415
print >> file('sub/c.txt', 'wb'), "hello"
418
self.runbzr(('commit', '-m', 'added a'))
419
self.runbzr('branch . ../b')
420
print >> file('sub/a.txt', 'ab'), "there"
421
print >> file('b.txt', 'ab'), "there"
422
print >> file('sub/c.txt', 'ab'), "there"
423
self.runbzr(('commit', '-m', 'Added there'))
424
os.unlink('sub/a.txt')
425
os.unlink('sub/c.txt')
428
self.runbzr(('commit', '-m', 'Removed a.txt'))
430
print >> file('sub/a.txt', 'ab'), "something"
431
print >> file('b.txt', 'ab'), "something"
432
print >> file('sub/c.txt', 'ab'), "something"
433
self.runbzr(('commit', '-m', 'Modified a.txt'))
434
self.runbzr('merge ../a/', retcode=1)
435
self.assert_(os.path.exists('sub/a.txt.THIS'))
436
self.assert_(os.path.exists('sub/a.txt.BASE'))
438
self.runbzr('merge ../b/', retcode=1)
439
self.assert_(os.path.exists('sub/a.txt.OTHER'))
440
self.assert_(os.path.exists('sub/a.txt.BASE'))
443
"""Pull changes from one branch to another."""
447
self.example_branch()
448
self.runbzr('pull', retcode=1)
449
self.runbzr('missing', retcode=1)
450
self.runbzr('missing .')
451
self.runbzr('missing')
453
self.runbzr('pull /', retcode=1)
457
self.runbzr('branch a b')
461
self.runbzr('add subdir')
462
self.runbzr('commit -m blah --unchanged')
465
b = Branch.open('../b')
466
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
467
self.runbzr('pull ../b')
468
self.assertEquals(a.revision_history(), b.revision_history())
469
self.runbzr('commit -m blah2 --unchanged')
471
self.runbzr('commit -m blah3 --unchanged')
473
self.runbzr('pull ../a', retcode=1)
475
self.runbzr('branch b overwriteme')
476
os.chdir('overwriteme')
477
self.runbzr('pull --overwrite ../a')
478
overwritten = Branch.open('.')
479
self.assertEqual(overwritten.revision_history(),
480
a.revision_history())
482
self.runbzr('merge ../b')
483
self.runbzr('commit -m blah4 --unchanged')
484
os.chdir('../b/subdir')
485
self.runbzr('pull ../../a')
486
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
487
self.runbzr('commit -m blah5 --unchanged')
488
self.runbzr('commit -m blah6 --unchanged')
490
self.runbzr('pull ../a')
492
self.runbzr('commit -m blah7 --unchanged')
493
self.runbzr('merge ../b')
494
self.runbzr('commit -m blah8 --unchanged')
495
self.runbzr('pull ../b')
496
self.runbzr('pull ../b')
499
"""Test the abilities of 'bzr ls'"""
501
def bzrout(*args, **kwargs):
502
kwargs['backtick'] = True
503
return self.runbzr(*args, **kwargs)
505
def ls_equals(value, *args):
506
out = self.runbzr(['ls'] + list(args), backtick=True)
507
self.assertEquals(out, value)
510
open('a', 'wb').write('hello\n')
513
bzr('ls --verbose --null', retcode=1)
516
ls_equals('? a\n', '--verbose')
517
ls_equals('a\n', '--unknown')
518
ls_equals('', '--ignored')
519
ls_equals('', '--versioned')
520
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
521
ls_equals('', '--ignored', '--versioned')
522
ls_equals('a\0', '--null')
525
ls_equals('V a\n', '--verbose')
532
open('subdir/b', 'wb').write('b\n')
538
bzr('commit -m subdir')
546
, '--verbose', '--non-recursive')
548
# Check what happens in a sub-directory
560
, '--from-root', '--null')
563
, '--from-root', '--non-recursive')
567
# Check what happens when we supply a specific revision
568
ls_equals('a\n', '--revision', '1')
570
, '--verbose', '--revision', '1')
573
ls_equals('', '--revision', '1')
575
# Now try to do ignored files.
577
open('blah.py', 'wb').write('unknown\n')
578
open('blah.pyo', 'wb').write('ignored\n')
590
ls_equals('blah.pyo\n'
592
ls_equals('blah.py\n'
600
def test_locations(self):
601
"""Using and remembering different locations"""
605
self.runbzr('commit -m unchanged --unchanged')
606
self.runbzr('pull', retcode=1)
607
self.runbzr('merge', retcode=1)
608
self.runbzr('branch . ../b')
611
self.runbzr('branch . ../c')
612
self.runbzr('pull ../c')
615
self.runbzr('pull ../b')
617
self.runbzr('pull ../c')
618
self.runbzr('branch ../c ../d')
619
shutil.rmtree('../c')
624
self.runbzr('pull', retcode=1)
625
self.runbzr('pull ../a --remember')
628
def test_add_reports(self):
629
"""add command prints the names of added files."""
630
b = Branch.initialize('.')
631
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
632
out = self.run_bzr_captured(['add'], retcode = 0)[0]
633
# the ordering is not defined at the moment
634
results = sorted(out.rstrip('\n').split('\n'))
635
self.assertEquals(['added dir',
636
'added dir'+os.sep+'sub.txt',
640
def test_add_quiet_is(self):
641
"""add -q does not print the names of added files."""
642
b = Branch.initialize('.')
643
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
644
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
645
# the ordering is not defined at the moment
646
results = sorted(out.rstrip('\n').split('\n'))
647
self.assertEquals([''], results)
649
def test_unknown_command(self):
650
"""Handling of unknown command."""
651
out, err = self.run_bzr_captured(['fluffy-badger'],
653
self.assertEquals(out, '')
654
err.index('unknown command')
656
def test_conflicts(self):
657
"""Handling of merge conflicts"""
660
file('hello', 'wb').write("hi world")
661
file('answer', 'wb').write("42")
664
self.runbzr('commit -m base')
665
self.runbzr('branch . ../other')
666
self.runbzr('branch . ../this')
668
file('hello', 'wb').write("Hello.")
669
file('answer', 'wb').write("Is anyone there?")
670
self.runbzr('commit -m other')
672
file('hello', 'wb').write("Hello, world")
673
self.runbzr('mv answer question')
674
file('question', 'wb').write("What do you get when you multiply six"
676
self.runbzr('commit -m this')
677
self.runbzr('merge ../other --show-base', retcode=1)
678
conflict_text = file('hello').read()
679
self.assert_('<<<<<<<' in conflict_text)
680
self.assert_('>>>>>>>' in conflict_text)
681
self.assert_('=======' in conflict_text)
682
self.assert_('|||||||' in conflict_text)
683
self.assert_('hi world' in conflict_text)
684
self.runbzr('revert')
685
self.runbzr('resolve --all')
686
self.runbzr('merge ../other', retcode=1)
687
conflict_text = file('hello').read()
688
self.assert_('|||||||' not in conflict_text)
689
self.assert_('hi world' not in conflict_text)
690
result = self.runbzr('conflicts', backtick=1)
691
self.assertEquals(result, "hello\nquestion\n")
692
result = self.runbzr('status', backtick=1)
693
self.assert_("conflicts:\n hello\n question\n" in result, result)
694
self.runbzr('resolve hello')
695
result = self.runbzr('conflicts', backtick=1)
696
self.assertEquals(result, "question\n")
697
self.runbzr('commit -m conflicts', retcode=1)
698
self.runbzr('resolve --all')
699
result = self.runbzr('conflicts', backtick=1)
700
self.runbzr('commit -m conflicts')
701
self.assertEquals(result, "")
703
def test_resign(self):
704
"""Test re signing of data."""
706
oldstrategy = bzrlib.gpg.GPGStrategy
707
branch = Branch.initialize('.')
708
branch.commit("base", allow_pointless=True, rev_id='A')
710
# monkey patch gpg signing mechanism
711
from bzrlib.testament import Testament
712
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
713
self.runbzr('re-sign -r revid:A')
714
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
715
branch.revision_store.get('A', 'sig').read())
717
bzrlib.gpg.GPGStrategy = oldstrategy
719
def test_resign_range(self):
721
oldstrategy = bzrlib.gpg.GPGStrategy
722
branch = Branch.initialize('.')
723
branch.commit("base", allow_pointless=True, rev_id='A')
724
branch.commit("base", allow_pointless=True, rev_id='B')
725
branch.commit("base", allow_pointless=True, rev_id='C')
727
# monkey patch gpg signing mechanism
728
from bzrlib.testament import Testament
729
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
730
self.runbzr('re-sign -r 1..')
731
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
732
branch.revision_store.get('A', 'sig').read())
733
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
734
branch.revision_store.get('B', 'sig').read())
735
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
736
branch.revision_store.get('C', 'sig').read())
738
bzrlib.gpg.GPGStrategy = oldstrategy
741
# create a source branch
742
os.mkdir('my-branch')
743
os.chdir('my-branch')
744
self.example_branch()
746
# with no push target, fail
747
self.runbzr('push', retcode=1)
748
# with an explicit target work
749
self.runbzr('push ../output-branch')
750
# with an implicit target work
753
self.runbzr('missing ../output-branch')
754
# advance this branch
755
self.runbzr('commit --unchanged -m unchanged')
757
os.chdir('../output-branch')
758
# should be a diff as we have not pushed the tree
759
self.runbzr('diff', retcode=1)
760
self.runbzr('revert')
763
# diverge the branches
764
self.runbzr('commit --unchanged -m unchanged')
765
os.chdir('../my-branch')
767
self.runbzr('push', retcode=1)
768
# and there are difference
769
self.runbzr('missing ../output-branch', retcode=1)
770
# but we can force a push
771
self.runbzr('push --overwrite')
773
self.runbzr('missing ../output-branch')
775
# pushing to a new dir with no parent should fail
776
self.runbzr('push ../missing/new-branch', retcode=1)
777
# unless we provide --create-prefix
778
self.runbzr('push --create-prefix ../missing/new-branch')
780
self.runbzr('missing ../missing/new-branch')
783
def listdir_sorted(dir):
789
class OldTests(ExternalBase):
790
"""old tests moved from ./testbzr."""
793
from os import chdir, mkdir
794
from os.path import exists
797
capture = self.capture
800
progress("basic branch creation")
805
self.assertEquals(capture('root').rstrip(),
806
os.path.join(self.test_dir, 'branch1'))
808
progress("status of new file")
810
f = file('test.txt', 'wt')
811
f.write('hello world!\n')
814
self.assertEquals(capture('unknowns'), 'test.txt\n')
816
out = capture("status")
817
self.assertEquals(out, 'unknown:\n test.txt\n')
819
out = capture("status --all")
820
self.assertEquals(out, "unknown:\n test.txt\n")
822
out = capture("status test.txt --all")
823
self.assertEquals(out, "unknown:\n test.txt\n")
825
f = file('test2.txt', 'wt')
826
f.write('goodbye cruel world...\n')
829
out = capture("status test.txt")
830
self.assertEquals(out, "unknown:\n test.txt\n")
832
out = capture("status")
833
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
835
os.unlink('test2.txt')
837
progress("command aliases")
838
out = capture("st --all")
839
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
841
out = capture("stat")
842
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
844
progress("command help")
847
runbzr("help commands")
848
runbzr("help slartibartfast", 1)
850
out = capture("help ci")
851
out.index('aliases: ')
853
progress("can't rename unversioned file")
854
runbzr("rename test.txt new-test.txt", 1)
856
progress("adding a file")
858
runbzr("add test.txt")
859
self.assertEquals(capture("unknowns"), '')
860
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
862
progress("rename newly-added file")
863
runbzr("rename test.txt hello.txt")
864
self.assert_(os.path.exists("hello.txt"))
865
self.assert_(not os.path.exists("test.txt"))
867
self.assertEquals(capture("revno"), '0\n')
869
progress("add first revision")
870
runbzr(['commit', '-m', 'add first revision'])
872
progress("more complex renames")
874
runbzr("rename hello.txt sub1", 1)
875
runbzr("rename hello.txt sub1/hello.txt", 1)
876
runbzr("move hello.txt sub1", 1)
879
runbzr("rename sub1 sub2")
880
runbzr("move hello.txt sub2")
881
self.assertEqual(capture("relpath sub2/hello.txt"),
882
os.path.join("sub2", "hello.txt\n"))
884
self.assert_(exists("sub2"))
885
self.assert_(exists("sub2/hello.txt"))
886
self.assert_(not exists("sub1"))
887
self.assert_(not exists("hello.txt"))
889
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
893
runbzr('move sub2/hello.txt sub1')
894
self.assert_(not exists('sub2/hello.txt'))
895
self.assert_(exists('sub1/hello.txt'))
896
runbzr('move sub2 sub1')
897
self.assert_(not exists('sub2'))
898
self.assert_(exists('sub1/sub2'))
900
runbzr(['commit', '-m', 'rename nested subdirectories'])
903
self.assertEquals(capture('root')[:-1],
904
os.path.join(self.test_dir, 'branch1'))
905
runbzr('move ../hello.txt .')
906
self.assert_(exists('./hello.txt'))
907
self.assertEquals(capture('relpath hello.txt'),
908
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
909
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
910
runbzr(['commit', '-m', 'move to parent directory'])
912
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
914
runbzr('move sub2/hello.txt .')
915
self.assert_(exists('hello.txt'))
917
f = file('hello.txt', 'wt')
918
f.write('some nice new content\n')
921
f = file('msg.tmp', 'wt')
922
f.write('this is my new commit\nand it has multiple lines, for fun')
925
runbzr('commit -F msg.tmp')
927
self.assertEquals(capture('revno'), '5\n')
928
runbzr('export -r 5 export-5.tmp')
929
runbzr('export export.tmp')
933
runbzr('log -v --forward')
934
runbzr('log -m', retcode=1)
935
log_out = capture('log -m commit')
936
self.assert_("this is my new commit\n and" in log_out)
937
self.assert_("rename nested" not in log_out)
938
self.assert_('revision-id' not in log_out)
939
self.assert_('revision-id' in capture('log --show-ids -m commit'))
941
log_out = capture('log --line')
942
for line in log_out.splitlines():
943
self.assert_(len(line) <= 79, len(line))
944
self.assert_("this is my new commit and" in log_out)
947
progress("file with spaces in name")
948
mkdir('sub directory')
949
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
951
runbzr('diff', retcode=1)
952
runbzr('commit -m add-spaces')
956
runbzr('log --forward')
965
os.symlink("NOWHERE1", "link1")
967
self.assertEquals(self.capture('unknowns'), '')
968
runbzr(['commit', '-m', '1: added symlink link1'])
972
self.assertEquals(self.capture('unknowns'), '')
973
os.symlink("NOWHERE2", "d1/link2")
974
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
975
# is d1/link2 found when adding d1
977
self.assertEquals(self.capture('unknowns'), '')
978
os.symlink("NOWHERE3", "d1/link3")
979
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
980
runbzr(['commit', '-m', '2: added dir, symlink'])
982
runbzr('rename d1 d2')
983
runbzr('move d2/link2 .')
984
runbzr('move link1 d2')
985
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
986
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
987
runbzr('add d2/link3')
988
runbzr('diff', retcode=1)
989
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
992
os.symlink("TARGET 2", "link2")
993
os.unlink("d2/link1")
994
os.symlink("TARGET 1", "d2/link1")
995
runbzr('diff', retcode=1)
996
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
997
runbzr(['commit', '-m', '4: retarget of two links'])
999
runbzr('remove d2/link1')
1000
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1001
runbzr(['commit', '-m', '5: remove d2/link1'])
1002
# try with the rm alias
1003
runbzr('add d2/link1')
1004
runbzr(['commit', '-m', '6: add d2/link1'])
1005
runbzr('rm d2/link1')
1006
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1007
runbzr(['commit', '-m', '7: remove d2/link1'])
1011
runbzr('rename d2/link3 d1/link3new')
1012
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1013
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1017
runbzr(['export', '-r', '1', 'exp1.tmp'])
1019
self.assertEquals(listdir_sorted("."), [ "link1" ])
1020
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1023
runbzr(['export', '-r', '2', 'exp2.tmp'])
1025
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1028
runbzr(['export', '-r', '3', 'exp3.tmp'])
1030
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1031
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1032
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1033
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1036
runbzr(['export', '-r', '4', 'exp4.tmp'])
1038
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1039
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1040
self.assertEquals(os.readlink("link2") , "TARGET 2")
1041
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1044
runbzr(['export', '-r', '5', 'exp5.tmp'])
1046
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1047
self.assert_(os.path.islink("link2"))
1048
self.assert_(listdir_sorted("d2")== [ "link3" ])
1051
runbzr(['export', '-r', '8', 'exp6.tmp'])
1053
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1054
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1055
self.assertEquals(listdir_sorted("d2"), [])
1056
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1059
progress("skipping symlink tests")
1062
class HttpTests(TestCaseWithWebserver):
1063
"""Test bzr ui commands against remote branches."""
1065
def test_branch(self):
1067
branch = Branch.initialize('from')
1068
branch.commit('empty commit for nonsense', allow_pointless=True)
1069
url = self.get_remote_url('from')
1070
self.run_bzr('branch', url, 'to')
1071
branch = Branch.open('to')
1072
self.assertEqual(1, len(branch.revision_history()))
1075
self.build_tree(['branch/', 'branch/file'])
1076
branch = Branch.initialize('branch')
1077
branch.add(['file'])
1078
branch.commit('add file', rev_id='A')
1079
url = self.get_remote_url('branch/file')
1080
output = self.capture('log %s' % url)
1081
self.assertEqual(7, len(output.split('\n')))