5
5
from bzrlib import branch, osutils, workingtree
6
6
from bzrlib.config import LocationConfig
7
7
from bzrlib.transport import get_transport
8
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
8
from bzrlib.tests import (
11
from bzrlib.plugins.bzrtools import command
14
from bzrlib.tests.features import (
16
ModuleAvailableFeature,
18
except ImportError: # bzr < 2.5
19
from bzrlib.tests import (
21
ModuleAvailableFeature,
25
LzmaFeature = ModuleAvailableFeature("lzma")
11
28
class TestBzrTools(TestCaseWithTransport):
31
TestCaseWithTransport.setUp(self)
32
command._testing = True
33
self.addCleanup(command._stop_testing)
13
36
def touch(filename):
14
37
file(filename, 'wb').write('')
16
def test_clean_tree(self):
18
self.run_bzr('ignore *~')
19
self.run_bzr('ignore *.pyc')
22
assert os.path.lexists('name~')
23
self.touch('name.pyc')
24
self.run_bzr('clean-tree --force')
25
assert os.path.lexists('name~')
26
assert not os.path.lexists('name')
28
self.run_bzr('clean-tree --detritus --force')
29
assert os.path.lexists('name')
30
assert not os.path.lexists('name~')
31
assert os.path.lexists('name.pyc')
32
self.run_bzr('clean-tree --ignored --force')
33
assert os.path.lexists('name')
34
assert not os.path.lexists('name.pyc')
35
self.run_bzr('clean-tree --unknown --force')
36
assert not os.path.lexists('name')
39
self.touch('name.pyc')
40
self.run_bzr('clean-tree --unknown --ignored --force')
41
assert not os.path.lexists('name')
42
assert not os.path.lexists('name~')
43
assert not os.path.lexists('name.pyc')
45
39
def test_shelve(self):
46
40
self.run_bzr('init')
47
41
self.run_bzr('commit -m uc --unchanged')
55
49
self.run_bzr('init')
56
50
self.run_bzr('fetch-ghosts .')
52
def test_fetch_ghosts_with_saved(self):
53
wt = self.make_branch_and_tree('.')
54
wt.branch.set_parent('.')
55
self.run_bzr('fetch-ghosts')
58
57
def test_patch(self):
59
58
self.run_bzr('init')
60
59
file('myfile', 'wb').write('hello')
105
104
checkout.add('file')
106
105
self.run_bzr_error(('This checkout has uncommitted changes',),
108
self.failUnlessExists('checkout')
107
self.assertPathExists('checkout')
109
108
self.run_bzr('zap checkout --force')
110
self.failIfExists('checkout')
111
self.failUnlessExists('source')
109
self.assertPathDoesNotExist('checkout')
110
self.assertPathExists('source')
113
112
def test_zap_branch(self):
114
113
self.run_bzr('init source')
150
149
self.run_bzr('init ../import')
151
150
os.chdir('../import')
152
151
self.run_bzr('import ../source-0.1.tar.gz')
153
self.failUnlessExists('src/myfile')
152
self.assertPathExists('src/myfile')
154
153
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
155
154
self.assertContainsRe(result, 'Working tree has uncommitted changes')
156
155
self.run_bzr('commit -m commit')
159
158
self.run_bzr('init import2')
160
159
self.run_bzr('import source-0.1.tar.gz import2')
161
self.failUnlessExists('import2/src/myfile')
160
self.assertPathExists('import2/src/myfile')
162
161
self.run_bzr('import source-0.1.tar.gz import3')
163
self.failUnlessExists('import3/src/myfile')
162
self.assertPathExists('import3/src/myfile')
164
163
self.run_bzr('import source-0.1.tar.bz2 import4')
165
self.failUnlessExists('import4/src/myfile')
164
self.assertPathExists('import4/src/myfile')
166
165
self.run_bzr('import source-0.1 import5')
167
self.failUnlessExists('import5/src/myfile')
166
self.assertPathExists('import5/src/myfile')
168
def test_import_upstream_lzma(self):
169
self.requireFeature(LzmaFeature)
170
self.run_bzr('init source')
171
os.mkdir('source/src')
172
f = file('source/src/myfile', 'wb')
177
self.run_bzr('commit -m hello')
178
self.run_bzr('export ../source-0.1.tar.lzma')
179
self.run_bzr('export ../source-0.1.tar.xz')
181
self.run_bzr('import source-0.1.tar.lzma import1')
182
self.assertPathExists('import1/src/myfile')
183
self.run_bzr('import source-0.1.tar.xz import2')
184
self.assertPathExists('import2/src/myfile')
169
186
def test_cbranch(self):
170
187
source = self.make_branch_and_tree('source')
182
199
def test_cbranch_hardlink(self):
183
200
self.requireFeature(HardlinkFeature)
184
source = self.make_branch_and_tree('source')
201
# Later formats don't support hardlinks. Boo!
202
source = self.make_branch_and_tree('source', format='1.9')
185
203
self.build_tree(['source/file'])
186
204
source.add('file')
187
205
source.commit('added file')
198
216
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
199
217
os.lstat(source.abspath('file')).st_ino)
219
def test_create_mirror(self):
220
source = self.make_branch_and_tree('source')
221
source.commit('message')
222
self.run_bzr('create-mirror source target')
223
target = branch.Branch.open('target')
224
self.assertEqual(source.last_revision(), target.last_revision())
225
self.assertEqual(source.branch.base, target.get_public_branch())
202
228
def test_suite():
203
229
return makeSuite(TestBzrTools)