31
32
"""Test that bzr gives proper errors outside of a working tree."""
33
34
def test_cwd_log(self):
34
tmp_dir = osutils.mkdtemp()
35
# Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
36
tmp_dir = osutils.realpath(osutils.mkdtemp())
37
# We expect a read-to-root attempt to occur.
38
self.permit_url('file:///')
35
39
self.addCleanup(lambda: osutils.rmtree(tmp_dir))
36
self.addCleanup(lambda: os.chdir('..'))
38
out, err = self.run_bzr('log', retcode=3)
40
out, err = self.run_bzr('log', retcode=3, working_dir=tmp_dir)
39
41
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n'
40
% (osutils.getcwd(),),
43
45
def test_url_log(self):
47
49
u' "%s".\n' % url, err)
49
51
def test_diff_outside_tree(self):
50
tmp_dir = osutils.mkdtemp()
52
tree = self.make_branch_and_tree('branch1')
53
tree.commit('nothing')
54
tree.commit('nothing')
55
# A directory we can run commands from which we hope is not contained
56
# in a bzr tree (though if there is one at or above $TEMPDIR, this is
57
# false and may cause test failures).
58
# Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
59
tmp_dir = osutils.realpath(osutils.mkdtemp())
51
60
self.addCleanup(lambda: osutils.rmtree(tmp_dir))
52
self.addCleanup(lambda: os.chdir('..'))
54
self.run_bzr('init branch1')
55
self.run_bzr(['commit', '-m', 'nothing',
56
'--unchanged', 'branch1'])
57
self.run_bzr(['commit', '-m', 'nothing',
58
'--unchanged', 'branch1'])
59
this_dir = osutils.getcwd()
60
branch2 = "%s/branch2" % (this_dir,)
61
# We expect a read-to-root attempt to occur.
62
self.permit_url('file:///')
63
expected_error = u'bzr: ERROR: Not a branch: "%s/branch2/".\n' % tmp_dir
62
out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3)
63
self.assertEquals('', out)
64
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
65
out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3,
67
self.assertEqual('', out)
68
self.assertEqual(expected_error, err)
67
out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3)
68
self.assertEquals('', out)
69
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
70
out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3,
72
self.assertEqual('', out)
73
self.assertEqual(expected_error, err)
72
out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3)
73
self.assertEquals('', out)
74
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
75
out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3,
77
self.assertEqual('', out)
78
self.assertEqual(expected_error, err)
77
out, err = self.run_bzr('diff', retcode=3)
78
self.assertEquals('', out)
79
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (this_dir,),
80
out, err = self.run_bzr('diff', retcode=3, working_dir=tmp_dir)
81
self.assertEqual('', out)
82
self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % tmp_dir, err)