58
58
class TestCommands(ExternalBase):
60
def test_whoami(self):
61
# this should always identify something, if only "john@localhost"
63
self.runbzr("whoami --email")
65
self.assertEquals(self.runbzr("whoami --email",
66
backtick=True).count('@'), 1)
68
def test_whoami_branch(self):
69
"""branch specific user identity works."""
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']
76
whoami = self.runbzr("whoami",backtick=True)
77
whoami_email = self.runbzr("whoami --email",backtick=True)
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
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
60
def test_nick_command(self):
91
61
"""bzr nick for viewing, setting nicknames"""
103
73
self.runbzr("--pants off", retcode=3)
104
74
self.runbzr("diff --message foo", retcode=3)
106
def test_ignore_patterns(self):
108
self.assertEquals(self.capture('unknowns'), '')
110
file('foo.tmp', 'wt').write('tmp files are ignored')
111
self.assertEquals(self.capture('unknowns'), '')
113
file('foo.c', 'wt').write('int main() {}')
114
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
116
self.runbzr(['add', 'foo.c'])
117
self.assertEquals(self.capture('unknowns'), '')
119
# 'ignore' works when creating the .bzignore file
120
file('foo.blah', 'wt').write('blah')
121
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
122
self.runbzr('ignore *.blah')
123
self.assertEquals(self.capture('unknowns'), '')
124
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
126
# 'ignore' works when then .bzrignore file already exists
127
file('garh', 'wt').write('garh')
128
self.assertEquals(self.capture('unknowns'), 'garh\n')
129
self.runbzr('ignore garh')
130
self.assertEquals(self.capture('unknowns'), '')
131
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
133
76
def test_revert(self):
134
77
self.runbzr('init')
180
123
self.runbzr('revert')
183
def test_mv_modes(self):
184
"""Test two modes of operation for mv"""
186
self.build_tree(['a', 'c', 'subdir/'])
187
self.run_bzr_captured(['add', self.test_dir])
188
self.run_bzr_captured(['mv', 'a', 'b'])
189
self.run_bzr_captured(['mv', 'b', 'subdir'])
190
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
191
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
192
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
194
126
def test_main_version(self):
195
127
"""Check output from version command and master option is reasonable"""
196
128
# output is intentionally passed through to stdout so that we
282
214
bzr('commit -m add')
284
216
output_equals('a\n', '--kind', 'file')
285
output_equals('b\n', '--kind', 'directory')
288
"""Test the abilities of 'bzr ls'"""
290
def bzrout(*args, **kwargs):
291
kwargs['backtick'] = True
292
return self.runbzr(*args, **kwargs)
294
def ls_equals(value, *args):
295
out = self.runbzr(['ls'] + list(args), backtick=True)
296
self.assertEquals(out, value)
299
open('a', 'wb').write('hello\n')
302
bzr('ls --verbose --null', retcode=3)
305
ls_equals('? a\n', '--verbose')
306
ls_equals('a\n', '--unknown')
307
ls_equals('', '--ignored')
308
ls_equals('', '--versioned')
309
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
310
ls_equals('', '--ignored', '--versioned')
311
ls_equals('a\0', '--null')
314
ls_equals('V a\n', '--verbose')
321
open('subdir/b', 'wb').write('b\n')
327
bzr('commit -m subdir')
335
, '--verbose', '--non-recursive')
337
# Check what happens in a sub-directory
349
, '--from-root', '--null')
352
, '--from-root', '--non-recursive')
356
# Check what happens when we supply a specific revision
357
ls_equals('a\n', '--revision', '1')
359
, '--verbose', '--revision', '1')
362
ls_equals('', '--revision', '1')
364
# Now try to do ignored files.
366
open('blah.py', 'wb').write('unknown\n')
367
open('blah.pyo', 'wb').write('ignored\n')
379
ls_equals('blah.pyo\n'
381
ls_equals('blah.py\n'
390
file("myfile", "wb").write("My contents\n")
392
self.runbzr('commit -m myfile')
393
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
217
output_equals('b\n', '--kind', 'directory')
395
219
def test_pull_verbose(self):
396
220
"""Pull changes from one branch to another and watch the output."""
492
316
self.runbzr('commit -m this')
494
def test_remerge(self):
495
"""Remerge command works as expected"""
496
self.create_conflicts()
497
self.runbzr('merge ../other --show-base', retcode=1)
498
conflict_text = file('hello').read()
499
assert '|||||||' in conflict_text
500
assert 'hi world' in conflict_text
501
self.runbzr('remerge', retcode=1)
502
conflict_text = file('hello').read()
503
assert '|||||||' not in conflict_text
504
assert 'hi world' not in conflict_text
505
os.unlink('hello.OTHER')
506
os.unlink('question.OTHER')
507
self.runbzr('remerge jello --merge-type weave', retcode=3)
508
self.runbzr('remerge hello --merge-type weave', retcode=1)
509
assert os.path.exists('hello.OTHER')
510
self.assertIs(False, os.path.exists('question.OTHER'))
511
file_id = self.runbzr('file-id hello')
512
file_id = self.runbzr('file-id hello.THIS', retcode=3)
513
self.runbzr('remerge --merge-type weave', retcode=1)
514
assert os.path.exists('hello.OTHER')
515
assert not os.path.exists('hello.BASE')
516
assert '|||||||' not in conflict_text
517
assert 'hi world' not in conflict_text
518
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
519
self.runbzr('remerge . --show-base --reprocess', retcode=3)
520
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
521
self.runbzr('remerge hello --show-base', retcode=1)
522
self.runbzr('remerge hello --reprocess', retcode=1)
523
self.runbzr('resolve --all')
524
self.runbzr('commit -m done',)
525
self.runbzr('remerge', retcode=3)
527
318
def test_status(self):
528
319
os.mkdir('branch1')
529
320
os.chdir('branch1')
730
515
out = capture("help ci")
731
516
out.index('aliases: ')
733
progress("can't rename unversioned file")
734
runbzr("rename test.txt new-test.txt", 3)
736
progress("adding a file")
738
runbzr("add test.txt")
739
self.assertEquals(capture("unknowns"), '')
740
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
742
progress("rename newly-added file")
743
runbzr("rename test.txt hello.txt")
744
self.assert_(os.path.exists("hello.txt"))
745
self.assert_(not os.path.exists("test.txt"))
747
self.assertEquals(capture("revno"), '0\n')
749
progress("add first revision")
750
runbzr(['commit', '-m', 'add first revision'])
752
progress("more complex renames")
754
runbzr("rename hello.txt sub1", 3)
755
runbzr("rename hello.txt sub1/hello.txt", 3)
756
runbzr("move hello.txt sub1", 3)
759
runbzr("rename sub1 sub2")
760
runbzr("move hello.txt sub2")
761
self.assertEqual(capture("relpath sub2/hello.txt"),
762
pathjoin("sub2", "hello.txt\n"))
764
self.assert_(exists("sub2"))
765
self.assert_(exists("sub2/hello.txt"))
766
self.assert_(not exists("sub1"))
767
self.assert_(not exists("hello.txt"))
769
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
773
runbzr('move sub2/hello.txt sub1')
774
self.assert_(not exists('sub2/hello.txt'))
775
self.assert_(exists('sub1/hello.txt'))
776
runbzr('move sub2 sub1')
777
self.assert_(not exists('sub2'))
778
self.assert_(exists('sub1/sub2'))
780
runbzr(['commit', '-m', 'rename nested subdirectories'])
783
self.assertEquals(capture('root')[:-1],
784
pathjoin(self.test_dir, 'branch1'))
785
runbzr('move ../hello.txt .')
786
self.assert_(exists('./hello.txt'))
787
self.assertEquals(capture('relpath hello.txt'),
788
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
789
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
790
runbzr(['commit', '-m', 'move to parent directory'])
792
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
794
runbzr('move sub2/hello.txt .')
795
self.assert_(exists('hello.txt'))
797
518
f = file('hello.txt', 'wt')
798
519
f.write('some nice new content\n')
522
runbzr("add hello.txt")
801
524
f = file('msg.tmp', 'wt')
802
525
f.write('this is my new commit\nand it has multiple lines, for fun')
805
528
runbzr('commit -F msg.tmp')
807
self.assertEquals(capture('revno'), '5\n')
808
runbzr('export -r 5 export-5.tmp')
530
self.assertEquals(capture('revno'), '1\n')
531
runbzr('export -r 1 export-1.tmp')
809
532
runbzr('export export.tmp')