31
27
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
28
# Note: Please don't add new tests here, it's too big and bulky. Instead add
33
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
# UI command/aspect that is being tested.
29
# them into small suites for the particular function that's tested.
37
32
from cStringIO import StringIO
43
38
from bzrlib.branch import Branch
44
import bzrlib.bzrdir as bzrdir
39
from bzrlib.clone import copy_branch
45
40
from bzrlib.errors import BzrCommandError
46
from bzrlib.osutils import (
52
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
53
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
54
from bzrlib.tests.blackbox import ExternalBase
55
from bzrlib.workingtree import WorkingTree
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
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
60
115
def test_nick_command(self):
61
116
"""bzr nick for viewing, setting nicknames"""
62
117
os.mkdir('me.dev')
68
123
nick = self.runbzr("nick",backtick=True)
69
124
self.assertEqual(nick, 'moo\n')
71
127
def test_invalid_commands(self):
72
128
self.runbzr("pants", retcode=3)
73
129
self.runbzr("--pants off", retcode=3)
74
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_remove_deleted(self):
147
self.build_tree(['a'])
148
self.runbzr(['add', 'a'])
149
self.runbzr(['commit', '-m', 'added a'])
151
self.runbzr(['remove', 'a'])
153
def test_other_branch_commit(self):
154
# this branch is to ensure consistent behaviour, whether we're run
155
# inside a branch, or not.
156
os.mkdir('empty_branch')
157
os.chdir('empty_branch')
162
file('foo.c', 'wt').write('int main() {}')
163
file('bar.c', 'wt').write('int main() {}')
165
self.runbzr(['add', 'branch/foo.c'])
166
self.runbzr(['add', 'branch'])
167
# can't commit files in different trees; sane error
168
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
169
self.runbzr('commit -m newstuff branch/foo.c')
170
self.runbzr('commit -m newstuff branch')
171
self.runbzr('commit -m newstuff branch', retcode=3)
173
def test_ignore_patterns(self):
174
from bzrlib.branch import Branch
175
Branch.initialize('.')
176
self.assertEquals(self.capture('unknowns'), '')
178
file('foo.tmp', 'wt').write('tmp files are ignored')
179
self.assertEquals(self.capture('unknowns'), '')
181
file('foo.c', 'wt').write('int main() {}')
182
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
184
self.runbzr(['add', 'foo.c'])
185
self.assertEquals(self.capture('unknowns'), '')
187
# 'ignore' works when creating the .bzignore file
188
file('foo.blah', 'wt').write('blah')
189
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
190
self.runbzr('ignore *.blah')
191
self.assertEquals(self.capture('unknowns'), '')
192
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
194
# 'ignore' works when then .bzrignore file already exists
195
file('garh', 'wt').write('garh')
196
self.assertEquals(self.capture('unknowns'), 'garh\n')
197
self.runbzr('ignore garh')
198
self.assertEquals(self.capture('unknowns'), '')
199
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
76
201
def test_revert(self):
77
202
self.runbzr('init')
123
245
self.runbzr('revert')
248
def test_status(self):
250
self.build_tree(['hello.txt'])
251
result = self.runbzr("status")
252
self.assert_("unknown:\n hello.txt\n" in result, result)
253
self.runbzr("add hello.txt")
254
result = self.runbzr("status")
255
self.assert_("added:\n hello.txt\n" in result, result)
256
self.runbzr("commit -m added")
257
result = self.runbzr("status -r 0..1")
258
self.assert_("added:\n hello.txt\n" in result, result)
259
self.build_tree(['world.txt'])
260
result = self.runbzr("status -r 0")
261
self.assert_("added:\n hello.txt\n" \
262
"unknown:\n world.txt\n" in result, result)
264
def test_mv_modes(self):
265
"""Test two modes of operation for mv"""
266
from bzrlib.branch import Branch
267
b = Branch.initialize('.')
268
self.build_tree(['a', 'c', 'subdir/'])
269
self.run_bzr_captured(['add', self.test_dir])
270
self.run_bzr_captured(['mv', 'a', 'b'])
271
self.run_bzr_captured(['mv', 'b', 'subdir'])
272
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
273
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
274
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
126
276
def test_main_version(self):
127
277
"""Check output from version command and master option is reasonable"""
128
278
# output is intentionally passed through to stdout so that we
185
333
tf = TarFile('../first2.tar')
186
334
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
188
from zipfile import ZipFile
189
self.runbzr('export ../first.zip -r 1')
190
self.failUnlessExists('../first.zip')
191
zf = ZipFile('../first.zip')
192
self.assert_('first/hello' in zf.namelist(), zf.namelist())
193
self.assertEqual(zf.read('first/hello'), 'foo')
195
self.runbzr('export ../first2.zip -r 1 --root pizza')
196
zf = ZipFile('../first2.zip')
197
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
337
self.example_branch()
338
file('hello', 'wt').write('hello world!')
339
self.runbzr('commit -m fixing hello')
340
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
341
self.assert_('\n+hello world!' in output)
342
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
343
self.assert_('\n+baz' in output)
344
file('moo', 'wb').write('moo')
345
self.runbzr('add moo')
349
def test_diff_branches(self):
350
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
351
branch = Branch.initialize('branch1')
352
branch.working_tree().add(['file'])
353
branch.working_tree().commit('add file')
354
copy_branch(branch, 'branch2')
355
print >> open('branch2/file', 'wb'), 'new content'
356
branch2 = Branch.open('branch2')
357
branch2.working_tree().commit('update file')
358
# should open branch1 and diff against branch2,
359
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
362
self.assertEquals(("=== modified file 'file'\n"
367
"+contents of branch1/file\n"
369
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
371
self.assertEqualDiff(("=== modified file 'file'\n"
376
"+contents of branch1/file\n"
380
def test_branch(self):
381
"""Branch from one branch to another."""
384
self.example_branch()
386
self.runbzr('branch a b')
387
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
388
self.runbzr('branch a c -r 1')
390
self.runbzr('commit -m foo --unchanged')
392
# naughty - abstraction violations RBC 20050928
393
print "test_branch used to delete the stores, how is this meant to work ?"
394
#shutil.rmtree('a/.bzr/revision-store')
395
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
396
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
397
self.runbzr('branch a d --basis b')
399
def test_merge(self):
400
from bzrlib.branch import Branch
199
self.runbzr('export ../first-zip --format=zip -r 1')
200
zf = ZipFile('../first-zip')
201
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
404
self.example_branch()
406
self.runbzr('branch a b')
408
file('goodbye', 'wt').write('quux')
409
self.runbzr(['commit', '-m', "more u's are always good"])
412
file('hello', 'wt').write('quuux')
413
# We can't merge when there are in-tree changes
414
self.runbzr('merge ../b', retcode=3)
415
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
416
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
418
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
419
self.runbzr('revert --no-backup')
420
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
421
self.runbzr('revert --no-backup')
422
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
423
self.runbzr('revert --no-backup')
424
self.runbzr('merge ../b -r last:1')
425
self.check_file_contents('goodbye', 'quux')
426
# Merging a branch pulls its revision into the tree
428
b = Branch.open('../b')
429
a.get_revision_xml(b.last_revision())
430
self.log('pending merges: %s', a.working_tree().pending_merges())
431
self.assertEquals(a.working_tree().pending_merges(),
433
self.runbzr('commit -m merged')
434
self.runbzr('merge ../b -r last:1')
435
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
437
def test_merge_with_missing_file(self):
438
"""Merge handles missing file conflicts"""
442
print >> file('sub/a.txt', 'wb'), "hello"
443
print >> file('b.txt', 'wb'), "hello"
444
print >> file('sub/c.txt', 'wb'), "hello"
447
self.runbzr(('commit', '-m', 'added a'))
448
self.runbzr('branch . ../b')
449
print >> file('sub/a.txt', 'ab'), "there"
450
print >> file('b.txt', 'ab'), "there"
451
print >> file('sub/c.txt', 'ab'), "there"
452
self.runbzr(('commit', '-m', 'Added there'))
453
os.unlink('sub/a.txt')
454
os.unlink('sub/c.txt')
457
self.runbzr(('commit', '-m', 'Removed a.txt'))
459
print >> file('sub/a.txt', 'ab'), "something"
460
print >> file('b.txt', 'ab'), "something"
461
print >> file('sub/c.txt', 'ab'), "something"
462
self.runbzr(('commit', '-m', 'Modified a.txt'))
463
self.runbzr('merge ../a/', retcode=1)
464
self.assert_(os.path.exists('sub/a.txt.THIS'))
465
self.assert_(os.path.exists('sub/a.txt.BASE'))
467
self.runbzr('merge ../b/', retcode=1)
468
self.assert_(os.path.exists('sub/a.txt.OTHER'))
469
self.assert_(os.path.exists('sub/a.txt.BASE'))
472
"""Pull changes from one branch to another."""
476
self.example_branch()
477
self.runbzr('pull', retcode=3)
478
self.runbzr('missing', retcode=3)
479
self.runbzr('missing .')
480
self.runbzr('missing')
482
self.runbzr('pull /', retcode=3)
486
self.runbzr('branch a b')
490
self.runbzr('add subdir')
491
self.runbzr('commit -m blah --unchanged')
494
b = Branch.open('../b')
495
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
496
self.runbzr('pull ../b')
497
self.assertEquals(a.revision_history(), b.revision_history())
498
self.runbzr('commit -m blah2 --unchanged')
500
self.runbzr('commit -m blah3 --unchanged')
502
self.runbzr('pull ../a', retcode=3)
504
self.runbzr('branch b overwriteme')
505
os.chdir('overwriteme')
506
self.runbzr('pull --overwrite ../a')
507
overwritten = Branch.open('.')
508
self.assertEqual(overwritten.revision_history(),
509
a.revision_history())
511
self.runbzr('merge ../b')
512
self.runbzr('commit -m blah4 --unchanged')
513
os.chdir('../b/subdir')
514
self.runbzr('pull ../../a')
515
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
516
self.runbzr('commit -m blah5 --unchanged')
517
self.runbzr('commit -m blah6 --unchanged')
519
self.runbzr('pull ../a')
521
self.runbzr('commit -m blah7 --unchanged')
522
self.runbzr('merge ../b')
523
self.runbzr('commit -m blah8 --unchanged')
524
self.runbzr('pull ../b')
525
self.runbzr('pull ../b')
203
527
def test_inventory(self):
204
528
bzr = self.runbzr
214
538
bzr('commit -m add')
216
540
output_equals('a\n', '--kind', 'file')
217
output_equals('b\n', '--kind', 'directory')
541
output_equals('b\n', '--kind', 'directory')
544
"""Test the abilities of 'bzr ls'"""
546
def bzrout(*args, **kwargs):
547
kwargs['backtick'] = True
548
return self.runbzr(*args, **kwargs)
550
def ls_equals(value, *args):
551
out = self.runbzr(['ls'] + list(args), backtick=True)
552
self.assertEquals(out, value)
555
open('a', 'wb').write('hello\n')
558
bzr('ls --verbose --null', retcode=3)
561
ls_equals('? a\n', '--verbose')
562
ls_equals('a\n', '--unknown')
563
ls_equals('', '--ignored')
564
ls_equals('', '--versioned')
565
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
566
ls_equals('', '--ignored', '--versioned')
567
ls_equals('a\0', '--null')
570
ls_equals('V a\n', '--verbose')
577
open('subdir/b', 'wb').write('b\n')
583
bzr('commit -m subdir')
591
, '--verbose', '--non-recursive')
593
# Check what happens in a sub-directory
605
, '--from-root', '--null')
608
, '--from-root', '--non-recursive')
612
# Check what happens when we supply a specific revision
613
ls_equals('a\n', '--revision', '1')
615
, '--verbose', '--revision', '1')
618
ls_equals('', '--revision', '1')
620
# Now try to do ignored files.
622
open('blah.py', 'wb').write('unknown\n')
623
open('blah.pyo', 'wb').write('ignored\n')
635
ls_equals('blah.pyo\n'
637
ls_equals('blah.py\n'
219
644
def test_pull_verbose(self):
220
645
"""Pull changes from one branch to another and watch the output."""
286
711
self.runbzr('pull ../a --remember')
287
712
self.runbzr('pull')
714
def test_add_reports(self):
715
"""add command prints the names of added files."""
716
b = Branch.initialize('.')
717
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
718
out = self.run_bzr_captured(['add'], retcode=0)[0]
719
# the ordering is not defined at the moment
720
results = sorted(out.rstrip('\n').split('\n'))
721
self.assertEquals(['added dir',
722
'added dir'+os.sep+'sub.txt',
726
def test_add_quiet_is(self):
727
"""add -q does not print the names of added files."""
728
b = Branch.initialize('.')
729
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
730
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
731
# the ordering is not defined at the moment
732
results = sorted(out.rstrip('\n').split('\n'))
733
self.assertEquals([''], results)
735
def test_add_in_unversioned(self):
736
"""Try to add a file in an unversioned directory.
738
"bzr add" should add the parent(s) as necessary.
740
from bzrlib.branch import Branch
741
Branch.initialize('.')
742
self.build_tree(['inertiatic/', 'inertiatic/esp'])
743
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
744
self.run_bzr('add', 'inertiatic/esp')
745
self.assertEquals(self.capture('unknowns'), '')
747
# Multiple unversioned parents
748
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
749
self.assertEquals(self.capture('unknowns'), 'veil\n')
750
self.run_bzr('add', 'veil/cerpin/taxt')
751
self.assertEquals(self.capture('unknowns'), '')
753
# Check whacky paths work
754
self.build_tree(['cicatriz/', 'cicatriz/esp'])
755
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
756
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
757
self.assertEquals(self.capture('unknowns'), '')
759
def test_add_in_versioned(self):
760
"""Try to add a file in a versioned directory.
762
"bzr add" should do this happily.
764
from bzrlib.branch import Branch
765
Branch.initialize('.')
766
self.build_tree(['inertiatic/', 'inertiatic/esp'])
767
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
768
self.run_bzr('add', '--no-recurse', 'inertiatic')
769
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
770
self.run_bzr('add', 'inertiatic/esp')
771
self.assertEquals(self.capture('unknowns'), '')
773
def test_subdir_add(self):
774
"""Add in subdirectory should add only things from there down"""
775
from bzrlib.branch import Branch
777
eq = self.assertEqual
781
b = Branch.initialize('.')
783
self.build_tree(['src/', 'README'])
785
eq(sorted(t.unknowns()),
788
self.run_bzr('add', 'src')
790
self.build_tree(['src/foo.c'])
795
self.assertEquals(self.capture('unknowns'), 'README\n')
796
eq(len(t.read_working_inventory()), 3)
800
self.assertEquals(self.capture('unknowns'), '')
801
self.run_bzr('check')
289
803
def test_unknown_command(self):
290
804
"""Handling of unknown command."""
291
805
out, err = self.run_bzr_captured(['fluffy-badger'],
316
830
self.runbzr('commit -m this')
318
def test_status(self):
322
self.runbzr('commit --unchanged --message f')
323
self.runbzr('branch . ../branch2')
324
self.runbzr('branch . ../branch3')
325
self.runbzr('commit --unchanged --message peter')
326
os.chdir('../branch2')
327
self.runbzr('merge ../branch1')
328
self.runbzr('commit --unchanged --message pumpkin')
329
os.chdir('../branch3')
330
self.runbzr('merge ../branch2')
331
message = self.capture('status')
832
def test_remerge(self):
833
"""Remerge command works as expected"""
834
self.create_conflicts()
835
self.runbzr('merge ../other --show-base', retcode=1)
836
conflict_text = file('hello').read()
837
assert '|||||||' in conflict_text
838
assert 'hi world' in conflict_text
839
self.runbzr('remerge', retcode=1)
840
conflict_text = file('hello').read()
841
assert '|||||||' not in conflict_text
842
assert 'hi world' not in conflict_text
843
os.unlink('hello.OTHER')
844
self.runbzr('remerge hello --merge-type weave', retcode=1)
845
assert os.path.exists('hello.OTHER')
846
file_id = self.runbzr('file-id hello')
847
file_id = self.runbzr('file-id hello.THIS', retcode=3)
848
self.runbzr('remerge --merge-type weave', retcode=1)
849
assert os.path.exists('hello.OTHER')
850
assert not os.path.exists('hello.BASE')
851
assert '|||||||' not in conflict_text
852
assert 'hi world' not in conflict_text
853
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
854
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
855
self.runbzr('remerge . --show-base --reprocess', retcode=3)
856
self.runbzr('remerge hello --show-base', retcode=1)
857
self.runbzr('remerge hello --reprocess', retcode=1)
858
self.runbzr('resolve --all')
859
self.runbzr('commit -m done',)
860
self.runbzr('remerge', retcode=3)
334
863
def test_conflicts(self):
348
877
self.assert_('|||||||' not in conflict_text)
349
878
self.assert_('hi world' not in conflict_text)
350
879
result = self.runbzr('conflicts', backtick=1)
351
self.assertEquals(result, "Text conflict in hello\nText conflict in"
880
self.assertEquals(result, "hello\nquestion\n")
353
881
result = self.runbzr('status', backtick=1)
354
self.assert_("conflicts:\n Text conflict in hello\n"
355
" Text conflict in question\n" in result, result)
882
self.assert_("conflicts:\n hello\n question\n" in result, result)
356
883
self.runbzr('resolve hello')
357
884
result = self.runbzr('conflicts', backtick=1)
358
self.assertEquals(result, "Text conflict in question\n")
885
self.assertEquals(result, "question\n")
359
886
self.runbzr('commit -m conflicts', retcode=3)
360
887
self.runbzr('resolve --all')
361
888
result = self.runbzr('conflicts', backtick=1)
362
889
self.runbzr('commit -m conflicts')
363
890
self.assertEquals(result, "")
892
def test_resign(self):
893
"""Test re signing of data."""
895
oldstrategy = bzrlib.gpg.GPGStrategy
896
branch = Branch.initialize('.')
897
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
899
# monkey patch gpg signing mechanism
900
from bzrlib.testament import Testament
901
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
902
self.runbzr('re-sign -r revid:A')
903
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
904
branch.revision_store.get('A', 'sig').read())
906
bzrlib.gpg.GPGStrategy = oldstrategy
908
def test_resign_range(self):
910
oldstrategy = bzrlib.gpg.GPGStrategy
911
branch = Branch.initialize('.')
912
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
913
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
914
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
916
# monkey patch gpg signing mechanism
917
from bzrlib.testament import Testament
918
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
919
self.runbzr('re-sign -r 1..')
920
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
921
branch.revision_store.get('A', 'sig').read())
922
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
923
branch.revision_store.get('B', 'sig').read())
924
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
925
branch.revision_store.get('C', 'sig').read())
927
bzrlib.gpg.GPGStrategy = oldstrategy
365
929
def test_push(self):
366
930
# create a source branch
367
931
os.mkdir('my-branch')
515
1090
out = capture("help ci")
516
1091
out.index('aliases: ')
1093
progress("can't rename unversioned file")
1094
runbzr("rename test.txt new-test.txt", 3)
1096
progress("adding a file")
1098
runbzr("add test.txt")
1099
self.assertEquals(capture("unknowns"), '')
1100
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
1102
progress("rename newly-added file")
1103
runbzr("rename test.txt hello.txt")
1104
self.assert_(os.path.exists("hello.txt"))
1105
self.assert_(not os.path.exists("test.txt"))
1107
self.assertEquals(capture("revno"), '0\n')
1109
progress("add first revision")
1110
runbzr(['commit', '-m', 'add first revision'])
1112
progress("more complex renames")
1114
runbzr("rename hello.txt sub1", 3)
1115
runbzr("rename hello.txt sub1/hello.txt", 3)
1116
runbzr("move hello.txt sub1", 3)
1119
runbzr("rename sub1 sub2")
1120
runbzr("move hello.txt sub2")
1121
self.assertEqual(capture("relpath sub2/hello.txt"),
1122
os.path.join("sub2", "hello.txt\n"))
1124
self.assert_(exists("sub2"))
1125
self.assert_(exists("sub2/hello.txt"))
1126
self.assert_(not exists("sub1"))
1127
self.assert_(not exists("hello.txt"))
1129
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1133
runbzr('move sub2/hello.txt sub1')
1134
self.assert_(not exists('sub2/hello.txt'))
1135
self.assert_(exists('sub1/hello.txt'))
1136
runbzr('move sub2 sub1')
1137
self.assert_(not exists('sub2'))
1138
self.assert_(exists('sub1/sub2'))
1140
runbzr(['commit', '-m', 'rename nested subdirectories'])
1143
self.assertEquals(capture('root')[:-1],
1144
os.path.join(self.test_dir, 'branch1'))
1145
runbzr('move ../hello.txt .')
1146
self.assert_(exists('./hello.txt'))
1147
self.assertEquals(capture('relpath hello.txt'),
1148
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1149
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
1150
runbzr(['commit', '-m', 'move to parent directory'])
1152
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
1154
runbzr('move sub2/hello.txt .')
1155
self.assert_(exists('hello.txt'))
518
1157
f = file('hello.txt', 'wt')
519
1158
f.write('some nice new content\n')
522
runbzr("add hello.txt")
524
1161
f = file('msg.tmp', 'wt')
525
1162
f.write('this is my new commit\nand it has multiple lines, for fun')
528
1165
runbzr('commit -F msg.tmp')
530
self.assertEquals(capture('revno'), '1\n')
531
runbzr('export -r 1 export-1.tmp')
1167
self.assertEquals(capture('revno'), '5\n')
1168
runbzr('export -r 5 export-5.tmp')
532
1169
runbzr('export export.tmp')
664
1299
progress("skipping symlink tests")
667
class RemoteTests(object):
1302
class HttpTests(TestCaseWithWebserver):
668
1303
"""Test bzr ui commands against remote branches."""
670
1305
def test_branch(self):
671
1306
os.mkdir('from')
672
wt = self.make_branch_and_tree('from')
674
wt.commit('empty commit for nonsense', allow_pointless=True)
675
url = self.get_readonly_url('from')
1307
branch = Branch.initialize('from')
1308
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1309
url = self.get_remote_url('from')
676
1310
self.run_bzr('branch', url, 'to')
677
1311
branch = Branch.open('to')
678
1312
self.assertEqual(1, len(branch.revision_history()))
679
# the branch should be set in to to from
680
self.assertEqual(url + '/', branch.get_parent())
682
1314
def test_log(self):
683
1315
self.build_tree(['branch/', 'branch/file'])
684
self.capture('init branch')
685
self.capture('add branch/file')
686
self.capture('commit -m foo branch')
687
url = self.get_readonly_url('branch/file')
1316
branch = Branch.initialize('branch')
1317
branch.working_tree().add(['file'])
1318
branch.working_tree().commit('add file', rev_id='A')
1319
url = self.get_remote_url('branch/file')
688
1320
output = self.capture('log %s' % url)
689
1321
self.assertEqual(8, len(output.split('\n')))
691
def test_check(self):
692
self.build_tree(['branch/', 'branch/file'])
693
self.capture('init branch')
694
self.capture('add branch/file')
695
self.capture('commit -m foo branch')
696
url = self.get_readonly_url('branch/')
697
self.run_bzr('check', url)
700
# create a source branch
701
os.mkdir('my-branch')
702
os.chdir('my-branch')
704
file('hello', 'wt').write('foo')
705
self.run_bzr('add', 'hello')
706
self.run_bzr('commit', '-m', 'setup')
708
# with an explicit target work
709
self.run_bzr('push', self.get_url('output-branch'))
712
class HTTPTests(TestCaseWithWebserver, RemoteTests):
713
"""Test various commands against a HTTP server."""
716
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
717
"""Test various commands against a SFTP server using abs paths."""
720
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
721
"""Test various commands against a SFTP server using abs paths."""
724
super(SFTPTestsAbsoluteSibling, self).setUp()
725
self._override_home = '/dev/noone/runs/tests/here'
728
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
729
"""Test various commands against a SFTP server using homedir rel paths."""
732
super(SFTPTestsRelative, self).setUp()
733
self._get_remote_is_absolute = False