31
31
from unittest import TestCase
32
32
from bzrlib.selftest import TestBase, InTempDir
36
class ExternalBase(TestBase):
37
def runbzr(self, args):
40
from subprocess import call
41
except ImportError, e:
45
if isinstance(args, basestring):
48
return self.runcmd(['python', self.BZRPATH,] + args)
34
52
class TestVersion(TestBase):
36
54
# output is intentionally passed through to stdout so that we
37
55
# can see the version being tested
38
self.runcmd(['bzr', 'version'])
56
self.runbzr(['version'])
42
60
class HelpCommands(TestBase):
44
self.runcmd('bzr --help')
45
self.runcmd('bzr help')
46
self.runcmd('bzr help commands')
47
self.runcmd('bzr help help')
48
self.runcmd('bzr commit -h')
64
self.runbzr('help commands')
65
self.runbzr('help help')
66
self.runbzr('commit -h')
51
69
class InitBranch(InTempDir):
54
self.runcmd(['bzr', 'init'])
58
76
class UserIdentity(InTempDir):
60
78
# this should always identify something, if only "john@localhost"
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
80
self.runbzr("whoami --email")
63
81
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
67
85
class InvalidCommands(InTempDir):
69
self.runcmd("bzr pants", retcode=1)
70
self.runcmd("bzr --pants off", retcode=1)
71
self.runcmd("bzr diff --message foo", retcode=1)
87
self.runbzr("pants", retcode=1)
88
self.runbzr("--pants off", retcode=1)
89
self.runbzr("diff --message foo", retcode=1)
75
93
class EmptyCommit(InTempDir):
77
self.runcmd("bzr init")
78
96
self.build_tree(['hello.txt'])
79
self.runcmd("bzr commit -m empty", retcode=1)
80
self.runcmd("bzr add hello.txt")
81
self.runcmd("bzr commit -m added")
97
self.runbzr("commit -m empty", retcode=1)
98
self.runbzr("add hello.txt")
99
self.runbzr("commit -m added")
145
163
progress("command help")
146
runcmd("bzr help st")
148
runcmd("bzr help commands")
149
runcmd("bzr help slartibartfast", 1)
166
runbzr("help commands")
167
runbzr("help slartibartfast", 1)
151
169
out = backtick("bzr help ci")
152
170
out.index('aliases: ')
154
172
progress("can't rename unversioned file")
155
runcmd("bzr rename test.txt new-test.txt", 1)
173
runbzr("rename test.txt new-test.txt", 1)
157
175
progress("adding a file")
159
runcmd("bzr add test.txt")
177
runbzr("add test.txt")
160
178
assert backtick("bzr unknowns") == ''
161
179
assert backtick("bzr status --all") == ("added:\n"
164
182
progress("rename newly-added file")
165
runcmd("bzr rename test.txt hello.txt")
183
runbzr("rename test.txt hello.txt")
166
184
assert os.path.exists("hello.txt")
167
185
assert not os.path.exists("test.txt")
174
192
progress("more complex renames")
176
runcmd("bzr rename hello.txt sub1", 1)
177
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
178
runcmd("bzr move hello.txt sub1", 1)
194
runbzr("rename hello.txt sub1", 1)
195
runbzr("rename hello.txt sub1/hello.txt", 1)
196
runbzr("move hello.txt sub1", 1)
180
runcmd("bzr add sub1")
181
runcmd("bzr rename sub1 sub2")
182
runcmd("bzr move hello.txt sub2")
199
runbzr("rename sub1 sub2")
200
runbzr("move hello.txt sub2")
183
201
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
185
203
assert exists("sub2")
187
205
assert not exists("sub1")
188
206
assert not exists("hello.txt")
190
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
208
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
193
runcmd('bzr add sub1')
194
runcmd('bzr move sub2/hello.txt sub1')
212
runbzr('move sub2/hello.txt sub1')
195
213
assert not exists('sub2/hello.txt')
196
214
assert exists('sub1/hello.txt')
197
runcmd('bzr move sub2 sub1')
215
runbzr('move sub2 sub1')
198
216
assert not exists('sub2')
199
217
assert exists('sub1/sub2')
201
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
219
runbzr(['commit', '-m', 'rename nested subdirectories'])
203
221
chdir('sub1/sub2')
204
222
self.assertEquals(backtick('bzr root')[:-1],
205
223
os.path.join(self.test_dir, 'branch1'))
206
runcmd('bzr move ../hello.txt .')
224
runbzr('move ../hello.txt .')
207
225
assert exists('./hello.txt')
208
226
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
209
227
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
210
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
228
runbzr(['commit', '-m', 'move to parent directory'])
212
230
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
214
runcmd('bzr move sub2/hello.txt .')
232
runbzr('move sub2/hello.txt .')
215
233
assert exists('hello.txt')
217
235
f = file('hello.txt', 'wt')
222
240
f.write('this is my new commit\n')
225
runcmd('bzr commit -F msg.tmp')
243
runbzr('commit -F msg.tmp')
227
245
assert backtick('bzr revno') == '5\n'
228
runcmd('bzr export -r 5 export-5.tmp')
229
runcmd('bzr export export.tmp')
246
runbzr('export -r 5 export-5.tmp')
247
runbzr('export export.tmp')
236
254
progress("file with spaces in name")
237
255
mkdir('sub directory')
238
256
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
241
runcmd('bzr commit -m add-spaces')
245
runcmd('bzr log --forward')
259
runbzr('commit -m add-spaces')
263
runbzr('log --forward')
256
274
progress('branch')
257
275
# Can't create a branch if it already exists
258
runcmd('bzr branch branch1', retcode=1)
276
runbzr('branch branch1', retcode=1)
259
277
# Can't create a branch if its parent doesn't exist
260
runcmd('bzr branch /unlikely/to/exist', retcode=1)
261
runcmd('bzr branch branch1 branch2')
278
runbzr('branch /unlikely/to/exist', retcode=1)
279
runbzr('branch branch1 branch2')
265
runcmd('bzr pull', retcode=1)
266
runcmd('bzr pull ../branch2')
283
runbzr('pull', retcode=1)
284
runbzr('pull ../branch2')
269
runcmd('bzr commit --unchanged -m empty')
287
runbzr('commit --unchanged -m empty')
271
289
chdir('../../branch2')
273
runcmd('bzr commit --unchanged -m empty')
291
runbzr('commit --unchanged -m empty')
274
292
chdir('../branch1')
275
runcmd('bzr commit --unchanged -m empty')
276
runcmd('bzr pull', retcode=1)
293
runbzr('commit --unchanged -m empty')
294
runbzr('pull', retcode=1)
279
297
progress('status after remove')
289
307
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
290
308
# see ~/.bzr.log for debug information
291
309
chdir('status-after-remove')
293
311
file('a', 'w').write('foo')
295
runcmd(['bzr', 'commit', '-m', 'add a'])
296
runcmd('bzr remove a')
313
runbzr(['commit', '-m', 'add a'])
301
319
progress('ignore patterns')
302
320
mkdir('ignorebranch')
303
321
chdir('ignorebranch')
305
323
assert backtick('bzr unknowns') == ''
307
325
file('foo.tmp', 'wt').write('tmp files are ignored')
310
328
file('foo.c', 'wt').write('int main() {}')
311
329
assert backtick('bzr unknowns') == 'foo.c\n'
312
runcmd('bzr add foo.c')
313
331
assert backtick('bzr unknowns') == ''
315
333
# 'ignore' works when creating the .bzignore file
316
334
file('foo.blah', 'wt').write('blah')
317
335
assert backtick('bzr unknowns') == 'foo.blah\n'
318
runcmd('bzr ignore *.blah')
336
runbzr('ignore *.blah')
319
337
assert backtick('bzr unknowns') == ''
320
338
assert file('.bzrignore', 'rb').read() == '*.blah\n'
322
340
# 'ignore' works when then .bzrignore file already exists
323
341
file('garh', 'wt').write('garh')
324
342
assert backtick('bzr unknowns') == 'garh\n'
325
runcmd('bzr ignore garh')
343
runbzr('ignore garh')
326
344
assert backtick('bzr unknowns') == ''
327
345
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
334
352
progress("recursive and non-recursive add")
335
353
mkdir('no-recurse')
336
354
chdir('no-recurse')
339
357
fp = os.path.join('foo', 'test.txt')
340
358
f = file(fp, 'w')
341
359
f.write('hello!\n')
343
runcmd('bzr add --no-recurse foo')
344
runcmd('bzr file-id foo')
345
runcmd('bzr file-id ' + fp, 1) # not versioned yet
346
runcmd('bzr commit -m add-dir-only')
348
runcmd('bzr file-id ' + fp, 1) # still not versioned
350
runcmd('bzr add foo')
351
runcmd('bzr file-id ' + fp)
352
runcmd('bzr commit -m add-sub-file')
361
runbzr('add --no-recurse foo')
362
runbzr('file-id foo')
363
runbzr('file-id ' + fp, 1) # not versioned yet
364
runbzr('commit -m add-dir-only')
366
runbzr('file-id ' + fp, 1) # still not versioned
369
runbzr('file-id ' + fp)
370
runbzr('commit -m add-sub-file')
358
376
class RevertCommand(InTempDir):
359
377
def runTest(self):
360
self.runcmd('bzr init')
362
380
file('hello', 'wt').write('foo')
363
self.runcmd('bzr add hello')
364
self.runcmd('bzr commit -m setup hello')
381
self.runbzr('add hello')
382
self.runbzr('commit -m setup hello')
366
384
file('hello', 'wt').write('bar')
367
self.runcmd('bzr revert hello')
385
self.runbzr('revert hello')
368
386
self.check_file_contents('hello', 'foo')