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):
11
self.runbzr('ignore *~')
12
self.runbzr('ignore *.pyc')
15
assert os.path.lexists('name~')
16
self.touch('name.pyc')
17
self.runbzr('clean-tree')
18
assert os.path.lexists('name~')
19
assert not os.path.lexists('name')
21
self.runbzr('clean-tree --detritus')
22
assert os.path.lexists('name')
23
assert not os.path.lexists('name~')
24
assert os.path.lexists('name.pyc')
25
self.runbzr('clean-tree --ignored')
26
assert os.path.lexists('name')
27
assert not os.path.lexists('name.pyc')
28
self.runbzr('clean-tree --unknown')
29
assert not os.path.lexists('name')
32
self.touch('name.pyc')
33
self.runbzr('clean-tree --unknown --ignored')
34
assert not os.path.lexists('name')
35
assert not os.path.lexists('name~')
36
assert not os.path.lexists('name.pyc')
38
39
def test_shelve(self):
40
self.runbzr('commit -m uc --unchanged')
41
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
41
self.run_bzr('commit -m uc --unchanged')
42
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
42
43
file('foo', 'wb').write('foo')
43
self.runbzr('add foo')
44
self.runbzr('commit -m foo')
45
self.runbzr('shelve -r 1 -m foo --all', retcode=0)
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)
47
48
def test_fetch_ghosts(self):
49
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')
51
57
def test_patch(self):
53
59
file('myfile', 'wb').write('hello')
55
self.runbzr('commit -m hello')
61
self.run_bzr('commit -m hello')
56
62
file('myfile', 'wb').write('goodbye')
57
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')
59
65
assert file('myfile', 'rb').read() == 'hello'
60
self.runbzr('patch mypatch')
66
self.run_bzr('patch --silent mypatch')
61
67
assert file('myfile', 'rb').read() == 'goodbye'
63
69
def test_branch_history(self):
65
71
file('myfile', 'wb').write('hello')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
73
self.run_bzr('commit -m hello')
74
self.run_bzr('branch-history')
70
76
def test_branch_history(self):
72
78
file('myfile', 'wb').write('hello')
74
self.runbzr('commit -m hello')
75
self.runbzr('graph-ancestry . graph.dot')
76
self.runbzr('branch . my_branch')
77
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')
79
85
def test_fetch_ghosts(self):
81
87
file('myfile', 'wb').write('hello')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
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')
87
93
def test_zap(self):
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
94
self.run_bzr('init source')
95
self.run_bzr('checkout --lightweight source checkout')
96
self.run_bzr('zap checkout')
91
97
self.assertIs(False, os.path.exists('checkout'))
92
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')
94
112
def test_zap_branch(self):
95
self.runbzr('init source')
96
self.runbzr('checkout --lightweight source checkout')
97
self.runbzr('zap --branch checkout', retcode=3)
113
self.run_bzr('init source')
114
self.run_bzr('checkout --lightweight source checkout')
115
self.run_bzr('zap --branch checkout', retcode=3)
98
116
self.assertIs(True, os.path.exists('checkout'))
99
117
self.assertIs(True, os.path.exists('source'))
100
self.runbzr('branch source source2')
101
self.runbzr('checkout --lightweight source2 checkout2')
102
self.runbzr('zap --branch checkout2')
118
self.run_bzr('branch source source2')
119
self.run_bzr('checkout --lightweight source2 checkout2')
120
self.run_bzr('zap --branch checkout2')
103
121
self.assertIs(False, os.path.exists('checkout2'))
104
122
self.assertIs(False, os.path.exists('source2'))
106
def test_branches(self):
107
self.runbzr('init source')
108
self.runbzr('init source/subsource')
109
self.runbzr('checkout --lightweight source checkout')
110
self.runbzr('init checkout/subcheckout')
111
self.runbzr('init checkout/.bzr/subcheckout')
112
out = self.capture('branches')
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]
113
131
lines = out.split('\n')
114
132
self.assertIs(True, 'source' in lines)
115
133
self.assertIs(True, 'source/subsource' in lines)
116
134
self.assertIs(True, 'checkout/subcheckout' in lines)
117
135
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
120
137
def test_import_upstream(self):
121
self.runbzr('init source')
138
self.run_bzr('init source')
122
139
os.mkdir('source/src')
123
140
f = file('source/src/myfile', 'wb')
124
141
f.write('hello?')
126
143
os.chdir('source')
128
self.runbzr('commit -m hello')
129
self.runbzr('export ../source-0.1.tar.gz')
130
self.runbzr('export ../source-0.1.tar.bz2')
131
self.runbzr('init ../import')
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')
132
150
os.chdir('../import')
133
self.runbzr('import ../source-0.1.tar.gz')
134
self.failUnlessExists('src/myfile')
135
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
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]
136
154
self.assertContainsRe(result, 'Working tree has uncommitted changes')
137
self.runbzr('commit -m commit')
138
self.runbzr('import ../source-0.1.tar.gz')
140
self.runbzr('init import2')
141
self.runbzr('import source-0.1.tar.gz import2')
142
self.failUnlessExists('import2/src/myfile')
143
self.runbzr('import source-0.1.tar.gz import3')
144
self.failUnlessExists('import3/src/myfile')
145
self.runbzr('import source-0.1.tar.bz2 import4')
146
self.failUnlessExists('import4/src/myfile')
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())
148
228
def test_suite():
149
229
return makeSuite(TestBzrTools)