26
26
it's normally invoked.
29
from cStringIO import StringIO
33
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
34
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
37
37
class ExternalBase(TestCaseInTempDir):
39
38
def runbzr(self, args, retcode=0, backtick=False):
40
39
if isinstance(args, basestring):
41
40
args = args.split()
72
71
f = file('.bzr/email', 'wt')
73
72
f.write('Branch Identity <branch@identi.ty>')
75
bzr_email = os.environ.get('BZREMAIL')
76
if bzr_email is not None:
77
del os.environ['BZREMAIL']
78
74
whoami = self.runbzr("whoami",backtick=True)
79
75
whoami_email = self.runbzr("whoami --email",backtick=True)
80
76
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
81
77
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
82
# Verify that the environment variable overrides the value
84
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
85
whoami = self.runbzr("whoami",backtick=True)
86
whoami_email = self.runbzr("whoami --email",backtick=True)
87
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
88
self.assertTrue(whoami_email.startswith('other@environ.ment'))
89
if bzr_email is not None:
90
os.environ['BZREMAIL'] = bzr_email
92
79
def test_invalid_commands(self):
93
80
self.runbzr("pants", retcode=1)
158
145
os.rmdir('revertdir')
159
146
self.runbzr('revert')
161
file('hello', 'wt').write('xyz')
162
self.runbzr('commit -m xyz hello')
163
self.runbzr('revert -r 1 hello')
164
self.check_file_contents('hello', 'foo')
165
self.runbzr('revert hello')
166
self.check_file_contents('hello', 'xyz')
167
os.chdir('revertdir')
168
self.runbzr('revert')
172
148
def test_mv_modes(self):
173
149
"""Test two modes of operation for mv"""
174
150
from bzrlib.branch import Branch
175
151
b = Branch.initialize('.')
176
152
self.build_tree(['a', 'c', 'subdir/'])
177
self.run_bzr_captured(['add', self.test_dir])
178
self.run_bzr_captured(['mv', 'a', 'b'])
179
self.run_bzr_captured(['mv', 'b', 'subdir'])
180
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
181
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
182
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
153
self.run_bzr('add', self.test_dir)
154
self.run_bzr('mv', 'a', 'b')
155
self.run_bzr('mv', 'b', 'subdir')
156
self.run_bzr('mv', 'subdir/b', 'a')
157
self.run_bzr('mv', 'a', 'c', 'subdir')
158
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
185
161
def test_main_version(self):
206
182
test.runbzr('add goodbye')
207
183
test.runbzr('commit -m setup goodbye')
210
self.example_branch()
211
file('hello', 'wt').write('hello world!')
212
self.runbzr('commit -m fixing hello')
213
output = self.runbzr('diff -r 2..3', backtick=1)
214
self.assert_('\n+hello world!' in output)
215
output = self.runbzr('diff -r last:3..last:1', backtick=1)
216
self.assert_('\n+baz' in output)
218
def test_branch(self):
219
"""Branch from one branch to another."""
222
self.example_branch()
224
self.runbzr('branch a b')
225
self.runbzr('branch a c -r 1')
185
def test_revert(self):
186
self.example_branch()
187
file('hello', 'wt').write('bar')
188
file('goodbye', 'wt').write('qux')
189
self.runbzr('revert hello')
190
self.check_file_contents('hello', 'foo')
191
self.check_file_contents('goodbye', 'qux')
192
self.runbzr('revert')
193
self.check_file_contents('goodbye', 'baz')
227
195
def test_merge(self):
228
196
from bzrlib.branch import Branch
286
252
self.runbzr('merge ../b')
287
253
self.runbzr('commit -m blah4 --unchanged')
288
os.chdir('../b/subdir')
289
self.runbzr('pull ../../a')
255
self.runbzr('pull ../a')
290
256
assert a.revision_history()[-1] == b.revision_history()[-1]
292
259
def test_add_reports(self):
293
260
"""add command prints the names of added files."""
294
261
b = Branch.initialize('.')
295
262
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
296
out = self.run_bzr_captured(['add'], retcode = 0)[0]
264
from cStringIO import StringIO
267
ret = self.apply_redirected(None, out, None,
270
self.assertEquals(ret, 0)
297
272
# the ordering is not defined at the moment
298
results = sorted(out.rstrip('\n').split('\n'))
273
results = sorted(out.getvalue().rstrip('\n').split('\n'))
299
274
self.assertEquals(['added dir',
300
275
'added dir/sub.txt',
301
276
'added top.txt',],