1
from bzrlib.tests.blackbox import ExternalBase
2
from unittest import makeSuite
3
from unittest import makeSuite
5
from bzrlib import branch, osutils, workingtree
6
from bzrlib.config import LocationConfig
7
from bzrlib.transport import get_transport
8
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
9
from bzrlib.plugins.bzrtools import command
12
class TestBzrTools(TestCaseWithTransport):
15
TestCaseWithTransport.setUp(self)
16
command._testing = True
17
self.addCleanup(command._stop_testing)
4
class TestBzrTools(ExternalBase):
20
6
def touch(filename):
21
7
file(filename, 'wb').write('')
9
def test_clean_tree(self):
11
self.run_bzr('ignore *~')
12
self.run_bzr('ignore *.pyc')
15
assert os.path.lexists('name~')
16
self.touch('name.pyc')
17
self.run_bzr('clean-tree')
18
assert os.path.lexists('name~')
19
assert not os.path.lexists('name')
21
self.run_bzr('clean-tree --detritus')
22
assert os.path.lexists('name')
23
assert not os.path.lexists('name~')
24
assert os.path.lexists('name.pyc')
25
self.run_bzr('clean-tree --ignored')
26
assert os.path.lexists('name')
27
assert not os.path.lexists('name.pyc')
28
self.run_bzr('clean-tree --unknown')
29
assert not os.path.lexists('name')
32
self.touch('name.pyc')
33
self.run_bzr('clean-tree --unknown --ignored')
34
assert not os.path.lexists('name')
35
assert not os.path.lexists('name~')
36
assert not os.path.lexists('name.pyc')
23
38
def test_shelve(self):
24
39
self.run_bzr('init')
25
40
self.run_bzr('commit -m uc --unchanged')
26
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
41
self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
27
42
file('foo', 'wb').write('foo')
28
43
self.run_bzr('add foo')
29
44
self.run_bzr('commit -m foo')
30
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
45
self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
32
47
def test_fetch_ghosts(self):
33
48
self.run_bzr('init')
34
49
self.run_bzr('fetch-ghosts .')
36
def test_fetch_ghosts_with_saved(self):
37
wt = self.make_branch_and_tree('.')
38
wt.branch.set_parent('.')
39
self.run_bzr('fetch-ghosts')
41
51
def test_patch(self):
42
52
self.run_bzr('init')
43
53
file('myfile', 'wb').write('hello')
81
91
self.assertIs(False, os.path.exists('checkout'))
82
92
self.assertIs(True, os.path.exists('source'))
84
def test_zap_modified(self):
85
tree = self.make_branch_and_tree('source')
86
checkout = tree.branch.create_checkout('checkout', lightweight=True)
87
self.build_tree(['checkout/file'])
89
self.run_bzr_error(('This checkout has uncommitted changes',),
91
self.assertPathExists('checkout')
92
self.run_bzr('zap checkout --force')
93
self.assertPathDoesNotExist('checkout')
94
self.assertPathExists('source')
96
94
def test_zap_branch(self):
97
95
self.run_bzr('init source')
98
96
self.run_bzr('checkout --lightweight source checkout')
117
115
self.assertIs(True, 'source/subsource' in lines)
118
116
self.assertIs(True, 'checkout/subcheckout' in lines)
119
117
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
121
120
def test_import_upstream(self):
122
121
self.run_bzr('init source')
133
132
self.run_bzr('init ../import')
134
133
os.chdir('../import')
135
134
self.run_bzr('import ../source-0.1.tar.gz')
136
self.assertPathExists('src/myfile')
135
self.failUnlessExists('src/myfile')
137
136
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
138
137
self.assertContainsRe(result, 'Working tree has uncommitted changes')
139
138
self.run_bzr('commit -m commit')
142
141
self.run_bzr('init import2')
143
142
self.run_bzr('import source-0.1.tar.gz import2')
144
self.assertPathExists('import2/src/myfile')
143
self.failUnlessExists('import2/src/myfile')
145
144
self.run_bzr('import source-0.1.tar.gz import3')
146
self.assertPathExists('import3/src/myfile')
145
self.failUnlessExists('import3/src/myfile')
147
146
self.run_bzr('import source-0.1.tar.bz2 import4')
148
self.assertPathExists('import4/src/myfile')
147
self.failUnlessExists('import4/src/myfile')
149
148
self.run_bzr('import source-0.1 import5')
150
self.assertPathExists('import5/src/myfile')
152
def test_cbranch(self):
153
source = self.make_branch_and_tree('source')
154
config = LocationConfig(osutils.abspath('target'))
155
config.set_user_option('cbranch_target', 'target_branch')
156
self.run_bzr('cbranch source target')
157
checkout = workingtree.WorkingTree.open('target')
158
self.assertEqual(checkout.branch.base,
159
get_transport('target').base)
160
self.assertEqual(checkout.branch.get_master_branch().base,
161
get_transport('target_branch').base)
162
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
163
get_transport('source').base)
165
def test_cbranch_hardlink(self):
166
self.requireFeature(HardlinkFeature)
167
# Later formats don't support hardlinks. Boo!
168
source = self.make_branch_and_tree('source', format='1.9')
169
self.build_tree(['source/file'])
171
source.commit('added file')
172
config = LocationConfig(osutils.abspath('target'))
173
config.set_user_option('cbranch_target', 'target_branch')
174
self.run_bzr('cbranch source target --lightweight')
175
checkout = workingtree.WorkingTree.open('target')
176
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
177
os.lstat(source.abspath('file')).st_ino)
178
config = LocationConfig(osutils.abspath('target2'))
179
config.set_user_option('cbranch_target', 'target_branch2')
180
self.run_bzr('cbranch source target2 --lightweight --hardlink')
181
checkout2 = workingtree.WorkingTree.open('target2')
182
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
183
os.lstat(source.abspath('file')).st_ino)
185
def test_create_mirror(self):
186
source = self.make_branch_and_tree('source')
187
source.commit('message')
188
self.run_bzr('create-mirror source target')
189
target = branch.Branch.open('target')
190
self.assertEqual(source.last_revision(), target.last_revision())
191
self.assertEqual(source.branch.base, target.get_public_branch())
149
self.failUnlessExists('import5/src/myfile')
194
151
def test_suite():
195
152
return makeSuite(TestBzrTools)