3
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
5
from bzrlib import branch
6
from bzrlib.tests import TestCaseWithTransport
11
9
class TestBzrTools(TestCaseWithTransport):
13
11
def touch(filename):
14
12
file(filename, 'wb').write('')
14
def test_clean_tree(self):
16
self.run_bzr('ignore *~')
17
self.run_bzr('ignore *.pyc')
20
assert os.path.lexists('name~')
21
self.touch('name.pyc')
22
self.run_bzr('clean-tree')
23
assert os.path.lexists('name~')
24
assert not os.path.lexists('name')
26
self.run_bzr('clean-tree --detritus')
27
assert os.path.lexists('name')
28
assert not os.path.lexists('name~')
29
assert os.path.lexists('name.pyc')
30
self.run_bzr('clean-tree --ignored')
31
assert os.path.lexists('name')
32
assert not os.path.lexists('name.pyc')
33
self.run_bzr('clean-tree --unknown')
34
assert not os.path.lexists('name')
37
self.touch('name.pyc')
38
self.run_bzr('clean-tree --unknown --ignored')
39
assert not os.path.lexists('name')
40
assert not os.path.lexists('name~')
41
assert not os.path.lexists('name.pyc')
16
43
def test_shelve(self):
17
44
self.run_bzr('init')
18
45
self.run_bzr('commit -m uc --unchanged')
19
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
46
self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
20
47
file('foo', 'wb').write('foo')
21
48
self.run_bzr('add foo')
22
49
self.run_bzr('commit -m foo')
23
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
50
self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
25
52
def test_fetch_ghosts(self):
26
53
self.run_bzr('init')
105
132
self.assertIs(True, 'source/subsource' in lines)
106
133
self.assertIs(True, 'checkout/subcheckout' in lines)
107
134
self.assertIs(True, 'checkout' not in lines)
135
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
109
137
def test_import_upstream(self):
110
138
self.run_bzr('init source')
137
165
self.run_bzr('import source-0.1 import5')
138
166
self.failUnlessExists('import5/src/myfile')
140
def test_cbranch(self):
141
source = self.make_branch_and_tree('source')
142
config = LocationConfig(osutils.abspath('target'))
143
config.set_user_option('cbranch_target', 'target_branch')
144
self.run_bzr('cbranch source target')
145
checkout = workingtree.WorkingTree.open('target')
146
self.assertEqual(checkout.branch.base,
147
get_transport('target').base)
148
self.assertEqual(checkout.branch.get_master_branch().base,
149
get_transport('target_branch').base)
150
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
151
get_transport('source').base)
153
def test_cbranch_hardlink(self):
154
self.requireFeature(HardlinkFeature)
155
# Later formats don't support hardlinks. Boo!
156
source = self.make_branch_and_tree('source', format='1.9')
157
self.build_tree(['source/file'])
159
source.commit('added file')
160
config = LocationConfig(osutils.abspath('target'))
161
config.set_user_option('cbranch_target', 'target_branch')
162
self.run_bzr('cbranch source target --lightweight')
163
checkout = workingtree.WorkingTree.open('target')
164
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
165
os.lstat(source.abspath('file')).st_ino)
166
config = LocationConfig(osutils.abspath('target2'))
167
config.set_user_option('cbranch_target', 'target_branch2')
168
self.run_bzr('cbranch source target2 --lightweight --hardlink')
169
checkout2 = workingtree.WorkingTree.open('target2')
170
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
171
os.lstat(source.abspath('file')).st_ino)
173
def test_create_mirror(self):
174
source = self.make_branch_and_tree('source')
175
source.commit('message')
176
self.run_bzr('create-mirror source target')
177
target = branch.Branch.open('target')
178
self.assertEqual(source.last_revision(), target.last_revision())
179
self.assertEqual(source.branch.base, target.get_public_branch())
182
168
def test_suite():
183
169
return makeSuite(TestBzrTools)