1
from bzrlib.tests.blackbox import ExternalBase
2
3
from unittest import makeSuite
4
class TestBzrTools(ExternalBase):
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
11
class TestBzrTools(TestCaseWithTransport):
6
13
def touch(filename):
7
14
file(filename, 'wb').write('')
14
21
self.touch('name~')
15
22
assert os.path.lexists('name~')
16
23
self.touch('name.pyc')
17
self.run_bzr('clean-tree')
24
self.run_bzr('clean-tree --force')
18
25
assert os.path.lexists('name~')
19
26
assert not os.path.lexists('name')
21
self.run_bzr('clean-tree --detritus')
28
self.run_bzr('clean-tree --detritus --force')
22
29
assert os.path.lexists('name')
23
30
assert not os.path.lexists('name~')
24
31
assert os.path.lexists('name.pyc')
25
self.run_bzr('clean-tree --ignored')
32
self.run_bzr('clean-tree --ignored --force')
26
33
assert os.path.lexists('name')
27
34
assert not os.path.lexists('name.pyc')
28
self.run_bzr('clean-tree --unknown')
35
self.run_bzr('clean-tree --unknown --force')
29
36
assert not os.path.lexists('name')
31
38
self.touch('name~')
32
39
self.touch('name.pyc')
33
self.run_bzr('clean-tree --unknown --ignored')
40
self.run_bzr('clean-tree --unknown --ignored --force')
34
41
assert not os.path.lexists('name')
35
42
assert not os.path.lexists('name~')
36
43
assert not os.path.lexists('name.pyc')
38
45
def test_shelve(self):
39
46
self.run_bzr('init')
40
47
self.run_bzr('commit -m uc --unchanged')
41
self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
48
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
42
49
file('foo', 'wb').write('foo')
43
50
self.run_bzr('add foo')
44
51
self.run_bzr('commit -m foo')
45
self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
52
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
47
54
def test_fetch_ghosts(self):
48
55
self.run_bzr('init')
91
98
self.assertIs(False, os.path.exists('checkout'))
92
99
self.assertIs(True, os.path.exists('source'))
101
def test_zap_modified(self):
102
tree = self.make_branch_and_tree('source')
103
checkout = tree.branch.create_checkout('checkout', lightweight=True)
104
self.build_tree(['checkout/file'])
106
self.run_bzr_error(('This checkout has uncommitted changes',),
108
self.failUnlessExists('checkout')
109
self.run_bzr('zap checkout --force')
110
self.failIfExists('checkout')
111
self.failUnlessExists('source')
94
113
def test_zap_branch(self):
95
114
self.run_bzr('init source')
96
115
self.run_bzr('checkout --lightweight source checkout')
115
134
self.assertIs(True, 'source/subsource' in lines)
116
135
self.assertIs(True, 'checkout/subcheckout' in lines)
117
136
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
120
138
def test_import_upstream(self):
121
139
self.run_bzr('init source')
148
166
self.run_bzr('import source-0.1 import5')
149
167
self.failUnlessExists('import5/src/myfile')
169
def test_cbranch(self):
170
source = self.make_branch_and_tree('source')
171
config = LocationConfig(osutils.abspath('target'))
172
config.set_user_option('cbranch_target', 'target_branch')
173
self.run_bzr('cbranch source target')
174
checkout = workingtree.WorkingTree.open('target')
175
self.assertEqual(checkout.branch.base,
176
get_transport('target').base)
177
self.assertEqual(checkout.branch.get_master_branch().base,
178
get_transport('target_branch').base)
179
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
180
get_transport('source').base)
182
def test_cbranch_hardlink(self):
183
self.requireFeature(HardlinkFeature)
184
source = self.make_branch_and_tree('source')
185
self.build_tree(['source/file'])
187
source.commit('added file')
188
config = LocationConfig(osutils.abspath('target'))
189
config.set_user_option('cbranch_target', 'target_branch')
190
self.run_bzr('cbranch source target --lightweight')
191
checkout = workingtree.WorkingTree.open('target')
192
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
193
os.lstat(source.abspath('file')).st_ino)
194
config = LocationConfig(osutils.abspath('target2'))
195
config.set_user_option('cbranch_target', 'target_branch2')
196
self.run_bzr('cbranch source target2 --lightweight --hardlink')
197
checkout2 = workingtree.WorkingTree.open('target2')
198
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
199
os.lstat(source.abspath('file')).st_ino)
151
202
def test_suite():
152
203
return makeSuite(TestBzrTools)