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 (
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")
8
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
28
11
class TestBzrTools(TestCaseWithTransport):
31
TestCaseWithTransport.setUp(self)
32
command._testing = True
33
self.addCleanup(command._stop_testing)
36
13
def touch(filename):
37
14
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')
39
45
def test_shelve(self):
40
46
self.run_bzr('init')
41
47
self.run_bzr('commit -m uc --unchanged')
42
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
48
self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
43
49
file('foo', 'wb').write('foo')
44
50
self.run_bzr('add foo')
45
51
self.run_bzr('commit -m foo')
46
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
52
self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
48
54
def test_fetch_ghosts(self):
49
55
self.run_bzr('init')
50
56
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')
57
58
def test_patch(self):
58
59
self.run_bzr('init')
59
60
file('myfile', 'wb').write('hello')
104
105
checkout.add('file')
105
106
self.run_bzr_error(('This checkout has uncommitted changes',),
107
self.assertPathExists('checkout')
108
self.failUnlessExists('checkout')
108
109
self.run_bzr('zap checkout --force')
109
self.assertPathDoesNotExist('checkout')
110
self.assertPathExists('source')
110
self.failIfExists('checkout')
111
self.failUnlessExists('source')
112
113
def test_zap_branch(self):
113
114
self.run_bzr('init source')
121
122
self.assertIs(False, os.path.exists('checkout2'))
122
123
self.assertIs(False, os.path.exists('source2'))
124
def test_list_branches(self):
125
def test_branches(self):
125
126
self.run_bzr('init source')
126
127
self.run_bzr('init source/subsource')
127
128
self.run_bzr('checkout --lightweight source checkout')
128
129
self.run_bzr('init checkout/subcheckout')
129
130
self.run_bzr('init checkout/.bzr/subcheckout')
130
out = self.run_bzr('list-branches')[0]
131
out = self.run_bzr('branches')[0]
131
132
lines = out.split('\n')
132
133
self.assertIs(True, 'source' in lines)
133
134
self.assertIs(True, 'source/subsource' in lines)
149
150
self.run_bzr('init ../import')
150
151
os.chdir('../import')
151
152
self.run_bzr('import ../source-0.1.tar.gz')
152
self.assertPathExists('src/myfile')
153
self.failUnlessExists('src/myfile')
153
154
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
154
155
self.assertContainsRe(result, 'Working tree has uncommitted changes')
155
156
self.run_bzr('commit -m commit')
158
159
self.run_bzr('init import2')
159
160
self.run_bzr('import source-0.1.tar.gz import2')
160
self.assertPathExists('import2/src/myfile')
161
self.failUnlessExists('import2/src/myfile')
161
162
self.run_bzr('import source-0.1.tar.gz import3')
162
self.assertPathExists('import3/src/myfile')
163
self.failUnlessExists('import3/src/myfile')
163
164
self.run_bzr('import source-0.1.tar.bz2 import4')
164
self.assertPathExists('import4/src/myfile')
165
self.failUnlessExists('import4/src/myfile')
165
166
self.run_bzr('import source-0.1 import5')
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')
167
self.failUnlessExists('import5/src/myfile')
186
169
def test_cbranch(self):
187
170
source = self.make_branch_and_tree('source')
199
182
def test_cbranch_hardlink(self):
200
183
self.requireFeature(HardlinkFeature)
201
# Later formats don't support hardlinks. Boo!
202
source = self.make_branch_and_tree('source', format='1.9')
184
source = self.make_branch_and_tree('source')
203
185
self.build_tree(['source/file'])
204
186
source.add('file')
205
187
source.commit('added file')
216
198
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
217
199
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())
228
202
def test_suite():
229
203
return makeSuite(TestBzrTools)