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 (
10
ModuleAvailableFeature,
11
TestCaseWithTransport,
13
from bzrlib.plugins.bzrtools import command
16
LzmaFeature = ModuleAvailableFeature("lzma")
19
class TestBzrTools(TestCaseWithTransport):
22
TestCaseWithTransport.setUp(self)
23
command._testing = True
24
self.addCleanup(command._stop_testing)
6
27
def touch(filename):
7
28
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
30
def test_shelve(self):
26
self.runbzr('commit -m uc --unchanged')
27
self.runbzr('shelve -r 1 -m foo', retcode=0)
32
self.run_bzr('commit -m uc --unchanged')
33
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
34
file('foo', 'wb').write('foo')
35
self.run_bzr('add foo')
36
self.run_bzr('commit -m foo')
37
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
29
39
def test_fetch_ghosts(self):
31
self.runbzr('fetch-ghosts .')
41
self.run_bzr('fetch-ghosts .')
43
def test_fetch_ghosts_with_saved(self):
44
wt = self.make_branch_and_tree('.')
45
wt.branch.set_parent('.')
46
self.run_bzr('fetch-ghosts')
33
48
def test_patch(self):
35
50
file('myfile', 'wb').write('hello')
37
self.runbzr('commit -m hello')
52
self.run_bzr('commit -m hello')
38
53
file('myfile', 'wb').write('goodbye')
39
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
54
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
55
self.run_bzr('revert')
41
56
assert file('myfile', 'rb').read() == 'hello'
42
self.runbzr('patch mypatch')
57
self.run_bzr('patch --silent mypatch')
43
58
assert file('myfile', 'rb').read() == 'goodbye'
45
60
def test_branch_history(self):
47
62
file('myfile', 'wb').write('hello')
49
self.runbzr('commit -m hello')
50
self.runbzr('branch-history')
64
self.run_bzr('commit -m hello')
65
self.run_bzr('branch-history')
52
67
def test_branch_history(self):
54
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')
69
file('myfile', 'wb').write('hello')
71
self.run_bzr('commit -m hello')
72
self.run_bzr('graph-ancestry . graph.dot')
73
self.run_bzr('branch . my_branch')
74
self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
76
def test_fetch_ghosts(self):
78
file('myfile', 'wb').write('hello')
80
self.run_bzr('commit -m hello')
81
self.run_bzr('branch . my_branch')
82
self.run_bzr('fetch-ghosts my_branch')
85
self.run_bzr('init source')
86
self.run_bzr('checkout --lightweight source checkout')
87
self.run_bzr('zap checkout')
88
self.assertIs(False, os.path.exists('checkout'))
89
self.assertIs(True, os.path.exists('source'))
91
def test_zap_modified(self):
92
tree = self.make_branch_and_tree('source')
93
checkout = tree.branch.create_checkout('checkout', lightweight=True)
94
self.build_tree(['checkout/file'])
96
self.run_bzr_error(('This checkout has uncommitted changes',),
98
self.assertPathExists('checkout')
99
self.run_bzr('zap checkout --force')
100
self.assertPathDoesNotExist('checkout')
101
self.assertPathExists('source')
103
def test_zap_branch(self):
104
self.run_bzr('init source')
105
self.run_bzr('checkout --lightweight source checkout')
106
self.run_bzr('zap --branch checkout', retcode=3)
107
self.assertIs(True, os.path.exists('checkout'))
108
self.assertIs(True, os.path.exists('source'))
109
self.run_bzr('branch source source2')
110
self.run_bzr('checkout --lightweight source2 checkout2')
111
self.run_bzr('zap --branch checkout2')
112
self.assertIs(False, os.path.exists('checkout2'))
113
self.assertIs(False, os.path.exists('source2'))
115
def test_branches(self):
116
self.run_bzr('init source')
117
self.run_bzr('init source/subsource')
118
self.run_bzr('checkout --lightweight source checkout')
119
self.run_bzr('init checkout/subcheckout')
120
self.run_bzr('init checkout/.bzr/subcheckout')
121
out = self.run_bzr('branches')[0]
122
lines = out.split('\n')
123
self.assertIs(True, 'source' in lines)
124
self.assertIs(True, 'source/subsource' in lines)
125
self.assertIs(True, 'checkout/subcheckout' in lines)
126
self.assertIs(True, 'checkout' not in lines)
128
def test_import_upstream(self):
129
self.run_bzr('init source')
130
os.mkdir('source/src')
131
f = file('source/src/myfile', 'wb')
136
self.run_bzr('commit -m hello')
137
self.run_bzr('export ../source-0.1.tar.gz')
138
self.run_bzr('export ../source-0.1.tar.bz2')
139
self.run_bzr('export ../source-0.1')
140
self.run_bzr('init ../import')
141
os.chdir('../import')
142
self.run_bzr('import ../source-0.1.tar.gz')
143
self.assertPathExists('src/myfile')
144
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
145
self.assertContainsRe(result, 'Working tree has uncommitted changes')
146
self.run_bzr('commit -m commit')
147
self.run_bzr('import ../source-0.1.tar.gz')
149
self.run_bzr('init import2')
150
self.run_bzr('import source-0.1.tar.gz import2')
151
self.assertPathExists('import2/src/myfile')
152
self.run_bzr('import source-0.1.tar.gz import3')
153
self.assertPathExists('import3/src/myfile')
154
self.run_bzr('import source-0.1.tar.bz2 import4')
155
self.assertPathExists('import4/src/myfile')
156
self.run_bzr('import source-0.1 import5')
157
self.assertPathExists('import5/src/myfile')
159
def test_import_upstream_lzma(self):
160
self.requireFeature(LzmaFeature)
161
self.run_bzr('init source')
162
os.mkdir('source/src')
163
f = file('source/src/myfile', 'wb')
168
self.run_bzr('commit -m hello')
169
self.run_bzr('export ../source-0.1.tar.lzma')
170
self.run_bzr('export ../source-0.1.tar.xz')
172
self.run_bzr('import source-0.1.tar.lzma import1')
173
self.assertPathExists('import1/src/myfile')
174
self.run_bzr('import source-0.1.tar.xz import2')
175
self.assertPathExists('import2/src/myfile')
177
def test_cbranch(self):
178
source = self.make_branch_and_tree('source')
179
config = LocationConfig(osutils.abspath('target'))
180
config.set_user_option('cbranch_target', 'target_branch')
181
self.run_bzr('cbranch source target')
182
checkout = workingtree.WorkingTree.open('target')
183
self.assertEqual(checkout.branch.base,
184
get_transport('target').base)
185
self.assertEqual(checkout.branch.get_master_branch().base,
186
get_transport('target_branch').base)
187
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
188
get_transport('source').base)
190
def test_cbranch_hardlink(self):
191
self.requireFeature(HardlinkFeature)
192
# Later formats don't support hardlinks. Boo!
193
source = self.make_branch_and_tree('source', format='1.9')
194
self.build_tree(['source/file'])
196
source.commit('added file')
197
config = LocationConfig(osutils.abspath('target'))
198
config.set_user_option('cbranch_target', 'target_branch')
199
self.run_bzr('cbranch source target --lightweight')
200
checkout = workingtree.WorkingTree.open('target')
201
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
202
os.lstat(source.abspath('file')).st_ino)
203
config = LocationConfig(osutils.abspath('target2'))
204
config.set_user_option('cbranch_target', 'target_branch2')
205
self.run_bzr('cbranch source target2 --lightweight --hardlink')
206
checkout2 = workingtree.WorkingTree.open('target2')
207
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
208
os.lstat(source.abspath('file')).st_ino)
210
def test_create_mirror(self):
211
source = self.make_branch_and_tree('source')
212
source.commit('message')
213
self.run_bzr('create-mirror source target')
214
target = branch.Branch.open('target')
215
self.assertEqual(source.last_revision(), target.last_revision())
216
self.assertEqual(source.branch.base, target.get_public_branch())
62
220
return makeSuite(TestBzrTools)