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 (
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")
28
class TestBzrTools(TestCaseWithTransport):
31
TestCaseWithTransport.setUp(self)
32
command._testing = True
33
self.addCleanup(command._stop_testing)
6
36
def touch(filename):
7
37
file(filename, 'wb').write('')
9
def test_clean_tree(self):
13
assert os.path.lexists('name~')
14
self.touch('name.pyc')
15
self.runbzr('clean-tree')
16
assert os.path.lexists('name~')
17
assert not os.path.lexists('name')
18
self.runbzr('clean-tree --detritus')
19
assert not os.path.lexists('name~')
20
assert os.path.lexists('name.pyc')
21
self.runbzr('clean-tree --ignored')
22
assert not os.path.lexists('name.pyc')
24
39
def test_shelve(self):
26
self.runbzr('commit -m uc --unchanged')
27
self.runbzr('shelve -r 1 -m foo', retcode=0)
41
self.run_bzr('commit -m uc --unchanged')
42
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
43
file('foo', 'wb').write('foo')
44
self.run_bzr('add foo')
45
self.run_bzr('commit -m foo')
46
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
29
48
def test_fetch_ghosts(self):
31
self.runbzr('fetch-ghosts .')
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')
33
57
def test_patch(self):
35
59
file('myfile', 'wb').write('hello')
37
self.runbzr('commit -m hello')
61
self.run_bzr('commit -m hello')
38
62
file('myfile', 'wb').write('goodbye')
39
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
63
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
64
self.run_bzr('revert')
41
65
assert file('myfile', 'rb').read() == 'hello'
42
self.runbzr('patch mypatch')
66
self.run_bzr('patch --silent mypatch')
43
67
assert file('myfile', 'rb').read() == 'goodbye'
45
69
def test_branch_history(self):
47
71
file('myfile', 'wb').write('hello')
49
self.runbzr('commit -m hello')
50
self.runbzr('branch-history')
73
self.run_bzr('commit -m hello')
74
self.run_bzr('branch-history')
52
76
def test_branch_history(self):
54
78
file('myfile', 'wb').write('hello')
56
self.runbzr('commit -m hello')
57
self.runbzr('graph-ancestry . graph.dot')
58
self.runbzr('branch . my_branch')
59
self.runbzr('graph-ancestry . graph.dot --merge-branch my_branch')
80
self.run_bzr('commit -m hello')
81
self.run_bzr('graph-ancestry . graph.dot')
82
self.run_bzr('branch . my_branch')
83
self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
61
85
def test_fetch_ghosts(self):
63
87
file('myfile', 'wb').write('hello')
65
self.runbzr('commit -m hello')
66
self.runbzr('branch . my_branch')
67
self.runbzr('fetch-ghosts my_branch')
89
self.run_bzr('commit -m hello')
90
self.run_bzr('branch . my_branch')
91
self.run_bzr('fetch-ghosts my_branch')
94
self.run_bzr('init source')
95
self.run_bzr('checkout --lightweight source checkout')
96
self.run_bzr('zap checkout')
97
self.assertIs(False, os.path.exists('checkout'))
98
self.assertIs(True, os.path.exists('source'))
100
def test_zap_modified(self):
101
tree = self.make_branch_and_tree('source')
102
checkout = tree.branch.create_checkout('checkout', lightweight=True)
103
self.build_tree(['checkout/file'])
105
self.run_bzr_error(('This checkout has uncommitted changes',),
107
self.assertPathExists('checkout')
108
self.run_bzr('zap checkout --force')
109
self.assertPathDoesNotExist('checkout')
110
self.assertPathExists('source')
112
def test_zap_branch(self):
113
self.run_bzr('init source')
114
self.run_bzr('checkout --lightweight source checkout')
115
self.run_bzr('zap --branch checkout', retcode=3)
116
self.assertIs(True, os.path.exists('checkout'))
117
self.assertIs(True, os.path.exists('source'))
118
self.run_bzr('branch source source2')
119
self.run_bzr('checkout --lightweight source2 checkout2')
120
self.run_bzr('zap --branch checkout2')
121
self.assertIs(False, os.path.exists('checkout2'))
122
self.assertIs(False, os.path.exists('source2'))
124
def test_list_branches(self):
125
self.run_bzr('init source')
126
self.run_bzr('init source/subsource')
127
self.run_bzr('checkout --lightweight source checkout')
128
self.run_bzr('init checkout/subcheckout')
129
self.run_bzr('init checkout/.bzr/subcheckout')
130
out = self.run_bzr('list-branches')[0]
131
lines = out.split('\n')
132
self.assertIs(True, 'source' in lines)
133
self.assertIs(True, 'source/subsource' in lines)
134
self.assertIs(True, 'checkout/subcheckout' in lines)
135
self.assertIs(True, 'checkout' not in lines)
137
def test_import_upstream(self):
138
self.run_bzr('init source')
139
os.mkdir('source/src')
140
f = file('source/src/myfile', 'wb')
145
self.run_bzr('commit -m hello')
146
self.run_bzr('export ../source-0.1.tar.gz')
147
self.run_bzr('export ../source-0.1.tar.bz2')
148
self.run_bzr('export ../source-0.1')
149
self.run_bzr('init ../import')
150
os.chdir('../import')
151
self.run_bzr('import ../source-0.1.tar.gz')
152
self.assertPathExists('src/myfile')
153
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
154
self.assertContainsRe(result, 'Working tree has uncommitted changes')
155
self.run_bzr('commit -m commit')
156
self.run_bzr('import ../source-0.1.tar.gz')
158
self.run_bzr('init import2')
159
self.run_bzr('import source-0.1.tar.gz import2')
160
self.assertPathExists('import2/src/myfile')
161
self.run_bzr('import source-0.1.tar.gz import3')
162
self.assertPathExists('import3/src/myfile')
163
self.run_bzr('import source-0.1.tar.bz2 import4')
164
self.assertPathExists('import4/src/myfile')
165
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')
186
def test_cbranch(self):
187
source = self.make_branch_and_tree('source')
188
config = LocationConfig(osutils.abspath('target'))
189
config.set_user_option('cbranch_target', 'target_branch')
190
self.run_bzr('cbranch source target')
191
checkout = workingtree.WorkingTree.open('target')
192
self.assertEqual(checkout.branch.base,
193
get_transport('target').base)
194
self.assertEqual(checkout.branch.get_master_branch().base,
195
get_transport('target_branch').base)
196
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
197
get_transport('source').base)
199
def test_cbranch_hardlink(self):
200
self.requireFeature(HardlinkFeature)
201
# Later formats don't support hardlinks. Boo!
202
source = self.make_branch_and_tree('source', format='1.9')
203
self.build_tree(['source/file'])
205
source.commit('added file')
206
config = LocationConfig(osutils.abspath('target'))
207
config.set_user_option('cbranch_target', 'target_branch')
208
self.run_bzr('cbranch source target --lightweight')
209
checkout = workingtree.WorkingTree.open('target')
210
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
211
os.lstat(source.abspath('file')).st_ino)
212
config = LocationConfig(osutils.abspath('target2'))
213
config.set_user_option('cbranch_target', 'target_branch2')
214
self.run_bzr('cbranch source target2 --lightweight --hardlink')
215
checkout2 = workingtree.WorkingTree.open('target2')
216
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
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())
70
229
return makeSuite(TestBzrTools)