65
129
self.assertEquals(self.runbzr("whoami --email",
66
130
backtick=True).count('@'), 1)
68
def test_whoami_branch(self):
69
"""branch specific user identity works."""
132
class UserIdentityBranch(ExternalBase):
134
# tests branch specific user identity
70
135
self.runbzr('init')
71
b = bzrlib.branch.Branch.open('.')
72
b.control_files.put_utf8('email', 'Branch Identity <branch@identi.ty>')
73
bzr_email = os.environ.get('BZREMAIL')
74
if bzr_email is not None:
75
del os.environ['BZREMAIL']
136
f = file('.bzr/email', 'wt')
137
f.write('Branch Identity <branch@identi.ty>')
76
139
whoami = self.runbzr("whoami",backtick=True)
77
140
whoami_email = self.runbzr("whoami --email",backtick=True)
78
141
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
142
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
80
# Verify that the environment variable overrides the value
82
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
83
whoami = self.runbzr("whoami",backtick=True)
84
whoami_email = self.runbzr("whoami --email",backtick=True)
85
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
86
self.assertTrue(whoami_email.startswith('other@environ.ment'))
87
if bzr_email is not None:
88
os.environ['BZREMAIL'] = bzr_email
90
def test_nick_command(self):
91
"""bzr nick for viewing, setting nicknames"""
95
nick = self.runbzr("nick",backtick=True)
96
self.assertEqual(nick, 'me.dev\n')
97
nick = self.runbzr("nick moo")
98
nick = self.runbzr("nick",backtick=True)
99
self.assertEqual(nick, 'moo\n')
101
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)
106
def test_remove_deleted(self):
145
class InvalidCommands(ExternalBase):
147
self.runbzr("pants", retcode=1)
148
self.runbzr("--pants off", retcode=1)
149
self.runbzr("diff --message foo", retcode=1)
153
class EmptyCommit(ExternalBase):
107
155
self.runbzr("init")
108
self.build_tree(['a'])
109
self.runbzr(['add', 'a'])
110
self.runbzr(['commit', '-m', 'added a'])
112
self.runbzr(['remove', 'a'])
114
def test_ignore_patterns(self):
116
self.assertEquals(self.capture('unknowns'), '')
156
self.build_tree(['hello.txt'])
157
self.runbzr("commit -m empty", retcode=1)
158
self.runbzr("add hello.txt")
159
self.runbzr("commit -m added")
163
class IgnorePatterns(ExternalBase):
165
from bzrlib.branch import Branch
167
b = Branch('.', init=True)
168
self.assertEquals(list(b.unknowns()), [])
118
170
file('foo.tmp', 'wt').write('tmp files are ignored')
119
self.assertEquals(self.capture('unknowns'), '')
171
self.assertEquals(list(b.unknowns()), [])
172
assert self.backtick('bzr unknowns') == ''
121
174
file('foo.c', 'wt').write('int main() {}')
122
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
175
self.assertEquals(list(b.unknowns()), ['foo.c'])
176
assert self.backtick('bzr unknowns') == 'foo.c\n'
124
178
self.runbzr(['add', 'foo.c'])
125
self.assertEquals(self.capture('unknowns'), '')
179
assert self.backtick('bzr unknowns') == ''
127
181
# 'ignore' works when creating the .bzignore file
128
182
file('foo.blah', 'wt').write('blah')
129
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
183
self.assertEquals(list(b.unknowns()), ['foo.blah'])
130
184
self.runbzr('ignore *.blah')
131
self.assertEquals(self.capture('unknowns'), '')
132
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
185
self.assertEquals(list(b.unknowns()), [])
186
assert file('.bzrignore', 'rb').read() == '*.blah\n'
134
188
# 'ignore' works when then .bzrignore file already exists
135
189
file('garh', 'wt').write('garh')
136
self.assertEquals(self.capture('unknowns'), 'garh\n')
190
self.assertEquals(list(b.unknowns()), ['garh'])
191
assert self.backtick('bzr unknowns') == 'garh\n'
137
192
self.runbzr('ignore garh')
138
self.assertEquals(self.capture('unknowns'), '')
139
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
141
def test_revert(self):
144
file('hello', 'wt').write('foo')
145
self.runbzr('add hello')
146
self.runbzr('commit -m setup hello')
148
file('goodbye', 'wt').write('baz')
149
self.runbzr('add goodbye')
150
self.runbzr('commit -m setup goodbye')
152
file('hello', 'wt').write('bar')
153
file('goodbye', 'wt').write('qux')
154
self.runbzr('revert hello')
155
self.check_file_contents('hello', 'foo')
156
self.check_file_contents('goodbye', 'qux')
157
self.runbzr('revert')
158
self.check_file_contents('goodbye', 'baz')
160
os.mkdir('revertdir')
161
self.runbzr('add revertdir')
162
self.runbzr('commit -m f')
163
os.rmdir('revertdir')
164
self.runbzr('revert')
167
os.symlink('/unlikely/to/exist', 'symlink')
168
self.runbzr('add symlink')
169
self.runbzr('commit -m f')
171
self.runbzr('revert')
172
self.failUnlessExists('symlink')
174
os.symlink('a-different-path', 'symlink')
175
self.runbzr('revert')
176
self.assertEqual('/unlikely/to/exist',
177
os.readlink('symlink'))
179
self.log("skipping revert symlink tests")
181
file('hello', 'wt').write('xyz')
182
self.runbzr('commit -m xyz hello')
183
self.runbzr('revert -r 1 hello')
184
self.check_file_contents('hello', 'foo')
185
self.runbzr('revert hello')
186
self.check_file_contents('hello', 'xyz')
187
os.chdir('revertdir')
188
self.runbzr('revert')
191
def test_mv_modes(self):
192
"""Test two modes of operation for mv"""
194
self.build_tree(['a', 'c', 'subdir/'])
195
self.run_bzr_captured(['add', self.test_dir])
196
self.run_bzr_captured(['mv', 'a', 'b'])
197
self.run_bzr_captured(['mv', 'b', 'subdir'])
198
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
199
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
200
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
202
def test_main_version(self):
203
"""Check output from version command and master option is reasonable"""
204
# output is intentionally passed through to stdout so that we
205
# can see the version being tested
206
output = self.runbzr('version', backtick=1)
207
self.log('bzr version output:')
209
self.assert_(output.startswith('bzr (bazaar-ng) '))
210
self.assertNotEqual(output.index('Canonical'), -1)
211
# make sure --version is consistent
212
tmp_output = self.runbzr('--version', backtick=1)
213
self.log('bzr --version output:')
215
self.assertEquals(output, tmp_output)
217
def example_branch(test):
219
file('hello', 'wt').write('foo')
220
test.runbzr('add hello')
221
test.runbzr('commit -m setup hello')
222
file('goodbye', 'wt').write('baz')
223
test.runbzr('add goodbye')
224
test.runbzr('commit -m setup goodbye')
226
def test_export(self):
229
self.example_branch()
230
self.runbzr('export ../latest')
231
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
232
self.runbzr('export ../first -r 1')
233
self.assert_(not os.path.exists('../first/goodbye'))
234
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
235
self.runbzr('export ../first.gz -r 1')
236
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
237
self.runbzr('export ../first.bz2 -r 1')
238
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
240
from tarfile import TarFile
241
self.runbzr('export ../first.tar -r 1')
242
self.assert_(os.path.isfile('../first.tar'))
243
tf = TarFile('../first.tar')
244
self.assert_('first/hello' in tf.getnames(), tf.getnames())
245
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
246
self.runbzr('export ../first.tar.gz -r 1')
247
self.assert_(os.path.isfile('../first.tar.gz'))
248
self.runbzr('export ../first.tbz2 -r 1')
249
self.assert_(os.path.isfile('../first.tbz2'))
250
self.runbzr('export ../first.tar.bz2 -r 1')
251
self.assert_(os.path.isfile('../first.tar.bz2'))
252
self.runbzr('export ../first.tar.tbz2 -r 1')
253
self.assert_(os.path.isfile('../first.tar.tbz2'))
255
from bz2 import BZ2File
256
tf = TarFile('../first.tar.tbz2',
257
fileobj=BZ2File('../first.tar.tbz2', 'r'))
258
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
259
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
260
self.runbzr('export ../first2.tar -r 1 --root pizza')
261
tf = TarFile('../first2.tar')
262
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
264
from zipfile import ZipFile
265
self.runbzr('export ../first.zip -r 1')
266
self.failUnlessExists('../first.zip')
267
zf = ZipFile('../first.zip')
268
self.assert_('first/hello' in zf.namelist(), zf.namelist())
269
self.assertEqual(zf.read('first/hello'), 'foo')
271
self.runbzr('export ../first2.zip -r 1 --root pizza')
272
zf = ZipFile('../first2.zip')
273
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
275
self.runbzr('export ../first-zip --format=zip -r 1')
276
zf = ZipFile('../first-zip')
277
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
279
def test_branch(self):
280
"""Branch from one branch to another."""
283
self.example_branch()
285
self.runbzr('branch a b')
286
b = bzrlib.branch.Branch.open('b')
287
self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
288
self.runbzr('branch a c -r 1')
290
self.runbzr('commit -m foo --unchanged')
293
def test_branch_basis(self):
294
# ensure that basis really does grab from the basis by having incomplete source
295
tree = self.make_branch_and_tree('commit_tree')
296
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
298
tree.commit('revision 1', rev_id='1')
299
source = self.make_branch_and_tree('source')
300
# this gives us an incomplete repository
301
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
302
tree.commit('revision 2', rev_id='2', allow_pointless=True)
303
tree.bzrdir.open_branch().copy_content_into(source.branch)
304
tree.copy_content_into(source)
305
self.assertFalse(source.branch.repository.has_revision('2'))
307
self.runbzr('branch source target --basis commit_tree')
308
target = bzrdir.BzrDir.open('target')
309
self.assertEqual('2', target.open_branch().last_revision())
310
self.assertEqual('2', target.open_workingtree().last_revision())
311
self.assertTrue(target.open_branch().repository.has_revision('2'))
313
def test_inventory(self):
315
def output_equals(value, *args):
316
out = self.runbzr(['inventory'] + list(args), backtick=True)
317
self.assertEquals(out, value)
320
open('a', 'wb').write('hello\n')
326
output_equals('a\n', '--kind', 'file')
327
output_equals('b\n', '--kind', 'directory')
330
"""Test the abilities of 'bzr ls'"""
332
def bzrout(*args, **kwargs):
333
kwargs['backtick'] = True
334
return self.runbzr(*args, **kwargs)
336
def ls_equals(value, *args):
337
out = self.runbzr(['ls'] + list(args), backtick=True)
338
self.assertEquals(out, value)
341
open('a', 'wb').write('hello\n')
344
bzr('ls --verbose --null', retcode=3)
347
ls_equals('? a\n', '--verbose')
348
ls_equals('a\n', '--unknown')
349
ls_equals('', '--ignored')
350
ls_equals('', '--versioned')
351
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
352
ls_equals('', '--ignored', '--versioned')
353
ls_equals('a\0', '--null')
356
ls_equals('V a\n', '--verbose')
363
open('subdir/b', 'wb').write('b\n')
369
bzr('commit -m subdir')
377
, '--verbose', '--non-recursive')
379
# Check what happens in a sub-directory
391
, '--from-root', '--null')
394
, '--from-root', '--non-recursive')
398
# Check what happens when we supply a specific revision
399
ls_equals('a\n', '--revision', '1')
401
, '--verbose', '--revision', '1')
404
ls_equals('', '--revision', '1')
406
# Now try to do ignored files.
408
open('blah.py', 'wb').write('unknown\n')
409
open('blah.pyo', 'wb').write('ignored\n')
421
ls_equals('blah.pyo\n'
423
ls_equals('blah.py\n'
432
file("myfile", "wb").write("My contents\n")
434
self.runbzr('commit -m myfile')
435
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
437
def test_pull_verbose(self):
438
"""Pull changes from one branch to another and watch the output."""
444
self.example_branch()
449
open('b', 'wb').write('else\n')
451
bzr(['commit', '-m', 'added b'])
454
out = bzr('pull --verbose ../b', backtick=True)
455
self.failIfEqual(out.find('Added Revisions:'), -1)
456
self.failIfEqual(out.find('message:\n added b'), -1)
457
self.failIfEqual(out.find('added b'), -1)
459
# Check that --overwrite --verbose prints out the removed entries
460
bzr('commit -m foo --unchanged')
462
bzr('commit -m baz --unchanged')
463
bzr('pull ../a', retcode=3)
464
out = bzr('pull --overwrite --verbose ../a', backtick=1)
466
remove_loc = out.find('Removed Revisions:')
467
self.failIfEqual(remove_loc, -1)
468
added_loc = out.find('Added Revisions:')
469
self.failIfEqual(added_loc, -1)
471
removed_message = out.find('message:\n baz')
472
self.failIfEqual(removed_message, -1)
473
self.failUnless(remove_loc < removed_message < added_loc)
475
added_message = out.find('message:\n foo')
476
self.failIfEqual(added_message, -1)
477
self.failUnless(added_loc < added_message)
479
def test_locations(self):
480
"""Using and remembering different locations"""
484
self.runbzr('commit -m unchanged --unchanged')
485
self.runbzr('pull', retcode=3)
486
self.runbzr('merge', retcode=3)
487
self.runbzr('branch . ../b')
490
self.runbzr('branch . ../c')
491
self.runbzr('pull ../c')
494
self.runbzr('pull ../b')
496
self.runbzr('pull ../c')
497
self.runbzr('branch ../c ../d')
503
self.runbzr('pull', retcode=3)
504
self.runbzr('pull ../a --remember')
507
def test_unknown_command(self):
508
"""Handling of unknown command."""
509
out, err = self.run_bzr_captured(['fluffy-badger'],
511
self.assertEquals(out, '')
512
err.index('unknown command')
514
def create_conflicts(self):
515
"""Create a conflicted tree"""
518
file('hello', 'wb').write("hi world")
519
file('answer', 'wb').write("42")
522
self.runbzr('commit -m base')
523
self.runbzr('branch . ../other')
524
self.runbzr('branch . ../this')
526
file('hello', 'wb').write("Hello.")
527
file('answer', 'wb').write("Is anyone there?")
528
self.runbzr('commit -m other')
530
file('hello', 'wb').write("Hello, world")
531
self.runbzr('mv answer question')
532
file('question', 'wb').write("What do you get when you multiply six"
534
self.runbzr('commit -m this')
536
def test_remerge(self):
537
"""Remerge command works as expected"""
538
self.create_conflicts()
539
self.runbzr('merge ../other --show-base', retcode=1)
540
conflict_text = file('hello').read()
541
assert '|||||||' in conflict_text
542
assert 'hi world' in conflict_text
543
self.runbzr('remerge', retcode=1)
544
conflict_text = file('hello').read()
545
assert '|||||||' not in conflict_text
546
assert 'hi world' not in conflict_text
547
os.unlink('hello.OTHER')
548
os.unlink('question.OTHER')
549
self.runbzr('remerge jello --merge-type weave', retcode=3)
550
self.runbzr('remerge hello --merge-type weave', retcode=1)
551
assert os.path.exists('hello.OTHER')
552
self.assertIs(False, os.path.exists('question.OTHER'))
553
file_id = self.runbzr('file-id hello')
554
file_id = self.runbzr('file-id hello.THIS', retcode=3)
555
self.runbzr('remerge --merge-type weave', retcode=1)
556
assert os.path.exists('hello.OTHER')
557
assert not os.path.exists('hello.BASE')
558
assert '|||||||' not in conflict_text
559
assert 'hi world' not in conflict_text
560
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
561
self.runbzr('remerge . --show-base --reprocess', retcode=3)
562
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
563
self.runbzr('remerge hello --show-base', retcode=1)
564
self.runbzr('remerge hello --reprocess', retcode=1)
565
self.runbzr('resolve --all')
566
self.runbzr('commit -m done',)
567
self.runbzr('remerge', retcode=3)
569
def test_status(self):
573
self.runbzr('commit --unchanged --message f')
574
self.runbzr('branch . ../branch2')
575
self.runbzr('branch . ../branch3')
576
self.runbzr('commit --unchanged --message peter')
577
os.chdir('../branch2')
578
self.runbzr('merge ../branch1')
579
self.runbzr('commit --unchanged --message pumpkin')
580
os.chdir('../branch3')
581
self.runbzr('merge ../branch2')
582
message = self.capture('status')
585
def test_conflicts(self):
586
"""Handling of merge conflicts"""
587
self.create_conflicts()
588
self.runbzr('merge ../other --show-base', retcode=1)
589
conflict_text = file('hello').read()
590
self.assert_('<<<<<<<' in conflict_text)
591
self.assert_('>>>>>>>' in conflict_text)
592
self.assert_('=======' in conflict_text)
593
self.assert_('|||||||' in conflict_text)
594
self.assert_('hi world' in conflict_text)
595
self.runbzr('revert')
596
self.runbzr('resolve --all')
597
self.runbzr('merge ../other', retcode=1)
598
conflict_text = file('hello').read()
599
self.assert_('|||||||' not in conflict_text)
600
self.assert_('hi world' not in conflict_text)
601
result = self.runbzr('conflicts', backtick=1)
602
self.assertEquals(result, "Text conflict in hello\nText conflict in"
604
result = self.runbzr('status', backtick=1)
605
self.assert_("conflicts:\n Text conflict in hello\n"
606
" Text conflict in question\n" in result, result)
607
self.runbzr('resolve hello')
608
result = self.runbzr('conflicts', backtick=1)
609
self.assertEquals(result, "Text conflict in question\n")
610
self.runbzr('commit -m conflicts', retcode=3)
611
self.runbzr('resolve --all')
612
result = self.runbzr('conflicts', backtick=1)
613
self.runbzr('commit -m conflicts')
614
self.assertEquals(result, "")
617
# create a source branch
618
os.mkdir('my-branch')
619
os.chdir('my-branch')
620
self.example_branch()
622
# with no push target, fail
623
self.runbzr('push', retcode=3)
624
# with an explicit target work
625
self.runbzr('push ../output-branch')
626
# with an implicit target work
629
self.runbzr('missing ../output-branch')
630
# advance this branch
631
self.runbzr('commit --unchanged -m unchanged')
633
os.chdir('../output-branch')
634
# There is no longer a difference as long as we have
635
# access to the working tree
638
# But we should be missing a revision
639
self.runbzr('missing ../my-branch', retcode=1)
641
# diverge the branches
642
self.runbzr('commit --unchanged -m unchanged')
643
os.chdir('../my-branch')
645
self.runbzr('push', retcode=3)
646
# and there are difference
647
self.runbzr('missing ../output-branch', retcode=1)
648
self.runbzr('missing --verbose ../output-branch', retcode=1)
649
# but we can force a push
650
self.runbzr('push --overwrite')
652
self.runbzr('missing ../output-branch')
654
# pushing to a new dir with no parent should fail
655
self.runbzr('push ../missing/new-branch', retcode=3)
656
# unless we provide --create-prefix
657
self.runbzr('push --create-prefix ../missing/new-branch')
659
self.runbzr('missing ../missing/new-branch')
661
def test_external_command(self):
662
"""Test that external commands can be run by setting the path
664
# We don't at present run bzr in a subprocess for blackbox tests, and so
665
# don't really capture stdout, only the internal python stream.
666
# Therefore we don't use a subcommand that produces any output or does
667
# anything -- we just check that it can be run successfully.
668
cmd_name = 'test-command'
669
if sys.platform == 'win32':
671
oldpath = os.environ.get('BZRPATH', None)
674
if os.environ.has_key('BZRPATH'):
675
del os.environ['BZRPATH']
677
f = file(cmd_name, 'wb')
678
if sys.platform == 'win32':
679
f.write('@echo off\n')
681
f.write('#!/bin/sh\n')
682
# f.write('echo Hello from test-command')
684
os.chmod(cmd_name, 0755)
686
# It should not find the command in the local
687
# directory by default, since it is not in my path
688
bzr(cmd_name, retcode=3)
690
# Now put it into my path
691
os.environ['BZRPATH'] = '.'
695
# Make sure empty path elements are ignored
696
os.environ['BZRPATH'] = os.pathsep
698
bzr(cmd_name, retcode=3)
702
os.environ['BZRPATH'] = oldpath
705
def listdir_sorted(dir):
193
self.assertEquals(list(b.unknowns()), [])
194
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
711
199
class OldTests(ExternalBase):
712
"""old tests moved from ./testbzr."""
200
# old tests moved from ./testbzr
715
202
from os import chdir, mkdir
716
203
from os.path import exists
718
206
runbzr = self.runbzr
719
capture = self.capture
207
backtick = self.backtick
720
208
progress = self.log
722
210
progress("basic branch creation")
733
221
f.write('hello world!\n')
736
self.assertEquals(capture('unknowns'), 'test.txt\n')
738
out = capture("status")
739
self.assertEquals(out, 'unknown:\n test.txt\n')
741
out = capture("status --all")
742
self.assertEquals(out, "unknown:\n test.txt\n")
744
out = capture("status test.txt --all")
745
self.assertEquals(out, "unknown:\n test.txt\n")
224
out = backtick("bzr unknowns")
225
self.assertEquals(out, 'test.txt\n')
227
out = backtick("bzr status")
228
assert out == 'unknown:\n test.txt\n'
230
out = backtick("bzr status --all")
231
assert out == "unknown:\n test.txt\n"
233
out = backtick("bzr status test.txt --all")
234
assert out == "unknown:\n test.txt\n"
747
236
f = file('test2.txt', 'wt')
748
237
f.write('goodbye cruel world...\n')
751
out = capture("status test.txt")
752
self.assertEquals(out, "unknown:\n test.txt\n")
240
out = backtick("bzr status test.txt")
241
assert out == "unknown:\n test.txt\n"
754
out = capture("status")
755
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
243
out = backtick("bzr status")
244
assert out == ("unknown:\n"
757
248
os.unlink('test2.txt')
759
250
progress("command aliases")
760
out = capture("st --all")
761
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
251
out = backtick("bzr st --all")
252
assert out == ("unknown:\n"
763
out = capture("stat")
764
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
255
out = backtick("bzr stat")
256
assert out == ("unknown:\n"
766
259
progress("command help")
767
260
runbzr("help st")
769
262
runbzr("help commands")
770
runbzr("help slartibartfast", 3)
263
runbzr("help slartibartfast", 1)
772
out = capture("help ci")
265
out = backtick("bzr help ci")
773
266
out.index('aliases: ')
775
268
progress("can't rename unversioned file")
776
runbzr("rename test.txt new-test.txt", 3)
269
runbzr("rename test.txt new-test.txt", 1)
778
271
progress("adding a file")
780
273
runbzr("add test.txt")
781
self.assertEquals(capture("unknowns"), '')
782
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
274
assert backtick("bzr unknowns") == ''
275
assert backtick("bzr status --all") == ("added:\n"
784
278
progress("rename newly-added file")
785
279
runbzr("rename test.txt hello.txt")
786
self.assert_(os.path.exists("hello.txt"))
787
self.assert_(not os.path.exists("test.txt"))
280
assert os.path.exists("hello.txt")
281
assert not os.path.exists("test.txt")
789
self.assertEquals(capture("revno"), '0\n')
283
assert backtick("bzr revno") == '0\n'
791
285
progress("add first revision")
792
286
runbzr(['commit', '-m', 'add first revision'])
794
288
progress("more complex renames")
796
runbzr("rename hello.txt sub1", 3)
797
runbzr("rename hello.txt sub1/hello.txt", 3)
798
runbzr("move hello.txt sub1", 3)
290
runbzr("rename hello.txt sub1", 1)
291
runbzr("rename hello.txt sub1/hello.txt", 1)
292
runbzr("move hello.txt sub1", 1)
800
294
runbzr("add sub1")
801
295
runbzr("rename sub1 sub2")
802
296
runbzr("move hello.txt sub2")
803
self.assertEqual(capture("relpath sub2/hello.txt"),
804
pathjoin("sub2", "hello.txt\n"))
297
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
806
self.assert_(exists("sub2"))
807
self.assert_(exists("sub2/hello.txt"))
808
self.assert_(not exists("sub1"))
809
self.assert_(not exists("hello.txt"))
299
assert exists("sub2")
300
assert exists("sub2/hello.txt")
301
assert not exists("sub1")
302
assert not exists("hello.txt")
811
304
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
814
307
runbzr('add sub1')
815
308
runbzr('move sub2/hello.txt sub1')
816
self.assert_(not exists('sub2/hello.txt'))
817
self.assert_(exists('sub1/hello.txt'))
309
assert not exists('sub2/hello.txt')
310
assert exists('sub1/hello.txt')
818
311
runbzr('move sub2 sub1')
819
self.assert_(not exists('sub2'))
820
self.assert_(exists('sub1/sub2'))
312
assert not exists('sub2')
313
assert exists('sub1/sub2')
822
315
runbzr(['commit', '-m', 'rename nested subdirectories'])
824
317
chdir('sub1/sub2')
825
self.assertEquals(capture('root')[:-1],
826
pathjoin(self.test_dir, 'branch1'))
318
self.assertEquals(backtick('bzr root')[:-1],
319
os.path.join(self.test_dir, 'branch1'))
827
320
runbzr('move ../hello.txt .')
828
self.assert_(exists('./hello.txt'))
829
self.assertEquals(capture('relpath hello.txt'),
830
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
831
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
321
assert exists('./hello.txt')
322
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
323
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
832
324
runbzr(['commit', '-m', 'move to parent directory'])
834
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
326
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
836
328
runbzr('move sub2/hello.txt .')
837
self.assert_(exists('hello.txt'))
329
assert exists('hello.txt')
839
331
f = file('hello.txt', 'wt')
840
332
f.write('some nice new content\n')
843
335
f = file('msg.tmp', 'wt')
844
f.write('this is my new commit\nand it has multiple lines, for fun')
336
f.write('this is my new commit\n')
847
339
runbzr('commit -F msg.tmp')
849
self.assertEquals(capture('revno'), '5\n')
341
assert backtick('bzr revno') == '5\n'
850
342
runbzr('export -r 5 export-5.tmp')
851
343
runbzr('export export.tmp')
855
347
runbzr('log -v --forward')
856
runbzr('log -m', retcode=3)
857
log_out = capture('log -m commit')
858
self.assert_("this is my new commit\n and" in log_out)
859
self.assert_("rename nested" not in log_out)
860
self.assert_('revision-id' not in log_out)
861
self.assert_('revision-id' in capture('log --show-ids -m commit'))
348
runbzr('log -m', retcode=1)
349
log_out = backtick('bzr log -m commit')
350
assert "this is my new commit" in log_out
351
assert "rename nested" not in log_out
352
assert 'revision-id' not in log_out
353
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
863
log_out = capture('log --line')
864
# determine the widest line we want
865
max_width = terminal_width() - 1
866
for line in log_out.splitlines():
867
self.assert_(len(line) <= max_width, len(line))
868
self.assert_("this is my new commit and" in log_out)
870
356
progress("file with spaces in name")
871
357
mkdir('sub directory')
872
358
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
874
runbzr('diff', retcode=1)
875
361
runbzr('commit -m add-spaces')
888
os.symlink("NOWHERE1", "link1")
890
self.assertEquals(self.capture('unknowns'), '')
891
runbzr(['commit', '-m', '1: added symlink link1'])
895
self.assertEquals(self.capture('unknowns'), '')
896
os.symlink("NOWHERE2", "d1/link2")
897
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
898
# is d1/link2 found when adding d1
900
self.assertEquals(self.capture('unknowns'), '')
901
os.symlink("NOWHERE3", "d1/link3")
902
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
903
runbzr(['commit', '-m', '2: added dir, symlink'])
905
runbzr('rename d1 d2')
906
runbzr('move d2/link2 .')
907
runbzr('move link1 d2')
908
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
909
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
910
runbzr('add d2/link3')
911
runbzr('diff', retcode=1)
912
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
915
os.symlink("TARGET 2", "link2")
916
os.unlink("d2/link1")
917
os.symlink("TARGET 1", "d2/link1")
918
runbzr('diff', retcode=1)
919
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
920
runbzr(['commit', '-m', '4: retarget of two links'])
922
runbzr('remove d2/link1')
923
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
924
runbzr(['commit', '-m', '5: remove d2/link1'])
925
# try with the rm alias
926
runbzr('add d2/link1')
927
runbzr(['commit', '-m', '6: add d2/link1'])
928
runbzr('rm d2/link1')
929
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
930
runbzr(['commit', '-m', '7: remove d2/link1'])
934
runbzr('rename d2/link3 d1/link3new')
935
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
936
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
940
runbzr(['export', '-r', '1', 'exp1.tmp'])
942
self.assertEquals(listdir_sorted("."), [ "link1" ])
943
self.assertEquals(os.readlink("link1"), "NOWHERE1")
946
runbzr(['export', '-r', '2', 'exp2.tmp'])
948
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
951
runbzr(['export', '-r', '3', 'exp3.tmp'])
953
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
954
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
955
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
956
self.assertEquals(os.readlink("link2") , "NOWHERE2")
959
runbzr(['export', '-r', '4', 'exp4.tmp'])
961
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
962
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
963
self.assertEquals(os.readlink("link2") , "TARGET 2")
964
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
967
runbzr(['export', '-r', '5', 'exp5.tmp'])
969
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
970
self.assert_(os.path.islink("link2"))
971
self.assert_(listdir_sorted("d2")== [ "link3" ])
974
runbzr(['export', '-r', '8', 'exp6.tmp'])
976
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
977
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
978
self.assertEquals(listdir_sorted("d2"), [])
979
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
982
progress("skipping symlink tests")
985
class RemoteTests(object):
986
"""Test bzr ui commands against remote branches."""
988
def test_branch(self):
990
wt = self.make_branch_and_tree('from')
992
wt.commit('empty commit for nonsense', allow_pointless=True)
993
url = self.get_readonly_url('from')
994
self.run_bzr('branch', url, 'to')
995
branch = Branch.open('to')
996
self.assertEqual(1, len(branch.revision_history()))
997
# the branch should be set in to to from
998
self.assertEqual(url + '/', branch.get_parent())
1001
self.build_tree(['branch/', 'branch/file'])
1002
self.capture('init branch')
1003
self.capture('add branch/file')
1004
self.capture('commit -m foo branch')
1005
url = self.get_readonly_url('branch/file')
1006
output = self.capture('log %s' % url)
1007
self.assertEqual(8, len(output.split('\n')))
374
class RevertCommand(ExternalBase):
378
file('hello', 'wt').write('foo')
379
self.runbzr('add hello')
380
self.runbzr('commit -m setup hello')
382
file('goodbye', 'wt').write('baz')
383
self.runbzr('add goodbye')
384
self.runbzr('commit -m setup goodbye')
1009
def test_check(self):
1010
self.build_tree(['branch/', 'branch/file'])
1011
self.capture('init branch')
1012
self.capture('add branch/file')
1013
self.capture('commit -m foo branch')
1014
url = self.get_readonly_url('branch/')
1015
self.run_bzr('check', url)
1017
def test_push(self):
1018
# create a source branch
1019
os.mkdir('my-branch')
1020
os.chdir('my-branch')
1021
self.run_bzr('init')
1022
file('hello', 'wt').write('foo')
1023
self.run_bzr('add', 'hello')
1024
self.run_bzr('commit', '-m', 'setup')
1026
# with an explicit target work
1027
self.run_bzr('push', self.get_url('output-branch'))
1030
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1031
"""Test various commands against a HTTP server."""
1034
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1035
"""Test various commands against a SFTP server using abs paths."""
1038
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1039
"""Test various commands against a SFTP server using abs paths."""
1042
super(SFTPTestsAbsoluteSibling, self).setUp()
1043
self._override_home = '/dev/noone/runs/tests/here'
1046
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1047
"""Test various commands against a SFTP server using homedir rel paths."""
1050
super(SFTPTestsRelative, self).setUp()
1051
self._get_remote_is_absolute = False
386
file('hello', 'wt').write('bar')
387
file('goodbye', 'wt').write('qux')
388
self.runbzr('revert hello')
389
self.check_file_contents('hello', 'foo')
390
self.check_file_contents('goodbye', 'qux')
391
self.runbzr('revert')
392
self.check_file_contents('goodbye', 'baz')