1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
60
60
def test_revert(self):
61
61
self.run_bzr('init')
63
file('hello', 'wt').write('foo')
63
with file('hello', 'wt') as f: f.write('foo')
64
64
self.run_bzr('add hello')
65
65
self.run_bzr('commit -m setup hello')
67
file('goodbye', 'wt').write('baz')
67
with file('goodbye', 'wt') as f: f.write('baz')
68
68
self.run_bzr('add goodbye')
69
69
self.run_bzr('commit -m setup goodbye')
71
file('hello', 'wt').write('bar')
72
file('goodbye', 'wt').write('qux')
71
with file('hello', 'wt') as f: f.write('bar')
72
with file('goodbye', 'wt') as f: f.write('qux')
73
73
self.run_bzr('revert hello')
74
74
self.check_file_contents('hello', 'foo')
75
75
self.check_file_contents('goodbye', 'qux')
88
88
self.run_bzr('commit -m f')
89
89
os.unlink('symlink')
90
90
self.run_bzr('revert')
91
self.failUnlessExists('symlink')
91
self.assertPathExists('symlink')
92
92
os.unlink('symlink')
93
93
os.symlink('a-different-path', 'symlink')
94
94
self.run_bzr('revert')
98
98
self.log("skipping revert symlink tests")
100
file('hello', 'wt').write('xyz')
100
with file('hello', 'wt') as f: f.write('xyz')
101
101
self.run_bzr('commit -m xyz hello')
102
102
self.run_bzr('revert -r 1 hello')
103
103
self.check_file_contents('hello', 'foo')
110
110
def example_branch(test):
111
111
test.run_bzr('init')
112
file('hello', 'wt').write('foo')
112
with file('hello', 'wt') as f: f.write('foo')
113
113
test.run_bzr('add hello')
114
114
test.run_bzr('commit -m setup hello')
115
file('goodbye', 'wt').write('baz')
115
with file('goodbye', 'wt') as f: f.write('baz')
116
116
test.run_bzr('add goodbye')
117
117
test.run_bzr('commit -m setup goodbye')
128
128
self.run_bzr('branch a b')
130
open('b', 'wb').write('else\n')
130
with open('b', 'wb') as f: f.write('else\n')
131
131
self.run_bzr('add b')
132
132
self.run_bzr(['commit', '-m', 'added b'])
135
135
out = self.run_bzr('pull --verbose ../b')[0]
136
self.failIfEqual(out.find('Added Revisions:'), -1)
137
self.failIfEqual(out.find('message:\n added b'), -1)
138
self.failIfEqual(out.find('added b'), -1)
136
self.assertNotEqual(out.find('Added Revisions:'), -1)
137
self.assertNotEqual(out.find('message:\n added b'), -1)
138
self.assertNotEqual(out.find('added b'), -1)
140
140
# Check that --overwrite --verbose prints out the removed entries
141
141
self.run_bzr('commit -m foo --unchanged')
145
145
out = self.run_bzr('pull --overwrite --verbose ../a')[0]
147
147
remove_loc = out.find('Removed Revisions:')
148
self.failIfEqual(remove_loc, -1)
148
self.assertNotEqual(remove_loc, -1)
149
149
added_loc = out.find('Added Revisions:')
150
self.failIfEqual(added_loc, -1)
150
self.assertNotEqual(added_loc, -1)
152
152
removed_message = out.find('message:\n baz')
153
self.failIfEqual(removed_message, -1)
154
self.failUnless(remove_loc < removed_message < added_loc)
153
self.assertNotEqual(removed_message, -1)
154
self.assertTrue(remove_loc < removed_message < added_loc)
156
156
added_message = out.find('message:\n foo')
157
self.failIfEqual(added_message, -1)
158
self.failUnless(added_loc < added_message)
157
self.assertNotEqual(added_message, -1)
158
self.assertTrue(added_loc < added_message)
160
160
def test_locations(self):
161
161
"""Using and remembering different locations"""
195
195
"""Create a conflicted tree"""
198
file('hello', 'wb').write("hi world")
199
file('answer', 'wb').write("42")
198
with file('hello', 'wb') as f: f.write("hi world")
199
with file('answer', 'wb') as f: f.write("42")
200
200
self.run_bzr('init')
201
201
self.run_bzr('add')
202
202
self.run_bzr('commit -m base')
203
203
self.run_bzr('branch . ../other')
204
204
self.run_bzr('branch . ../this')
205
205
os.chdir('../other')
206
file('hello', 'wb').write("Hello.")
207
file('answer', 'wb').write("Is anyone there?")
206
with file('hello', 'wb') as f: f.write("Hello.")
207
with file('answer', 'wb') as f: f.write("Is anyone there?")
208
208
self.run_bzr('commit -m other')
209
209
os.chdir('../this')
210
file('hello', 'wb').write("Hello, world")
210
with file('hello', 'wb') as f: f.write("Hello, world")
211
211
self.run_bzr('mv answer question')
212
file('question', 'wb').write("What do you get when you multiply six"
212
with file('question', 'wb') as f: f.write("What do you get when you multiply six"
214
214
self.run_bzr('commit -m this')
315
315
cmd_name = 'test-command'
316
316
if sys.platform == 'win32':
317
317
cmd_name += '.bat'
318
oldpath = os.environ.get('BZRPATH', None)
320
if 'BZRPATH' in os.environ:
321
del os.environ['BZRPATH']
323
f = file(cmd_name, 'wb')
324
if sys.platform == 'win32':
325
f.write('@echo off\n')
327
f.write('#!/bin/sh\n')
328
# f.write('echo Hello from test-command')
330
os.chmod(cmd_name, 0755)
332
# It should not find the command in the local
333
# directory by default, since it is not in my path
334
self.run_bzr(cmd_name, retcode=3)
336
# Now put it into my path
337
os.environ['BZRPATH'] = '.'
339
self.run_bzr(cmd_name)
341
# Make sure empty path elements are ignored
342
os.environ['BZRPATH'] = os.pathsep
344
self.run_bzr(cmd_name, retcode=3)
348
os.environ['BZRPATH'] = oldpath
318
self.overrideEnv('BZRPATH', None)
320
f = file(cmd_name, 'wb')
321
if sys.platform == 'win32':
322
f.write('@echo off\n')
324
f.write('#!/bin/sh\n')
325
# f.write('echo Hello from test-command')
327
os.chmod(cmd_name, 0755)
329
# It should not find the command in the local
330
# directory by default, since it is not in my path
331
self.run_bzr(cmd_name, retcode=3)
333
# Now put it into my path
334
self.overrideEnv('BZRPATH', '.')
335
self.run_bzr(cmd_name)
337
# Make sure empty path elements are ignored
338
self.overrideEnv('BZRPATH', os.pathsep)
339
self.run_bzr(cmd_name, retcode=3)
351
342
def listdir_sorted(dir):
448
439
progress("file with spaces in name")
449
440
mkdir('sub directory')
450
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
441
with file('sub directory/file with spaces ', 'wt') as f: f.write('see how this works\n')
451
442
self.run_bzr('add .')
452
443
self.run_bzr('diff', retcode=1)
453
444
self.run_bzr('commit -m add-spaces')
573
564
url = self.get_readonly_url('from')
574
565
self.run_bzr(['branch', url, 'to'])
575
566
branch = Branch.open('to')
576
self.assertEqual(1, len(branch.revision_history()))
567
self.assertEqual(1, branch.last_revision_info()[0])
577
568
# the branch should be set in to to from
578
569
self.assertEqual(url + '/', branch.get_parent())
599
590
os.mkdir('my-branch')
600
591
os.chdir('my-branch')
601
592
self.run_bzr('init')
602
file('hello', 'wt').write('foo')
593
with file('hello', 'wt') as f: f.write('foo')
603
594
self.run_bzr('add hello')
604
595
self.run_bzr('commit -m setup')