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):
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
30
def test_shelve(self):
40
self.runbzr('commit -m uc --unchanged')
41
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
32
self.run_bzr('commit -m uc --unchanged')
33
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
42
34
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)
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)
47
39
def test_fetch_ghosts(self):
49
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')
51
48
def test_patch(self):
53
50
file('myfile', 'wb').write('hello')
55
self.runbzr('commit -m hello')
52
self.run_bzr('commit -m hello')
56
53
file('myfile', 'wb').write('goodbye')
57
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')
59
56
assert file('myfile', 'rb').read() == 'hello'
60
self.runbzr('patch --silent mypatch')
57
self.run_bzr('patch --silent mypatch')
61
58
assert file('myfile', 'rb').read() == 'goodbye'
63
60
def test_branch_history(self):
65
62
file('myfile', 'wb').write('hello')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
64
self.run_bzr('commit -m hello')
65
self.run_bzr('branch-history')
70
67
def test_branch_history(self):
72
69
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')
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')
79
76
def test_fetch_ghosts(self):
81
78
file('myfile', 'wb').write('hello')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
self.runbzr('fetch-ghosts my_branch')
80
self.run_bzr('commit -m hello')
81
self.run_bzr('branch . my_branch')
82
self.run_bzr('fetch-ghosts my_branch')
87
84
def test_zap(self):
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
85
self.run_bzr('init source')
86
self.run_bzr('checkout --lightweight source checkout')
87
self.run_bzr('zap checkout')
91
88
self.assertIs(False, os.path.exists('checkout'))
92
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')
94
103
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)
104
self.run_bzr('init source')
105
self.run_bzr('checkout --lightweight source checkout')
106
self.run_bzr('zap --branch checkout', retcode=3)
98
107
self.assertIs(True, os.path.exists('checkout'))
99
108
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')
109
self.run_bzr('branch source source2')
110
self.run_bzr('checkout --lightweight source2 checkout2')
111
self.run_bzr('zap --branch checkout2')
103
112
self.assertIs(False, os.path.exists('checkout2'))
104
113
self.assertIs(False, os.path.exists('source2'))
106
115
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')
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]
113
122
lines = out.split('\n')
114
123
self.assertIs(True, 'source' in lines)
115
124
self.assertIs(True, 'source/subsource' in lines)
116
125
self.assertIs(True, 'checkout/subcheckout' in lines)
117
126
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
120
128
def test_import_upstream(self):
121
self.runbzr('init source')
129
self.run_bzr('init source')
122
130
os.mkdir('source/src')
123
131
f = file('source/src/myfile', 'wb')
124
132
f.write('hello?')
126
134
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('export ../source-0.1')
132
self.runbzr('init ../import')
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')
133
141
os.chdir('../import')
134
self.runbzr('import ../source-0.1.tar.gz')
135
self.failUnlessExists('src/myfile')
136
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
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]
137
145
self.assertContainsRe(result, 'Working tree has uncommitted changes')
138
self.runbzr('commit -m commit')
139
self.runbzr('import ../source-0.1.tar.gz')
141
self.runbzr('init import2')
142
self.runbzr('import source-0.1.tar.gz import2')
143
self.failUnlessExists('import2/src/myfile')
144
self.runbzr('import source-0.1.tar.gz import3')
145
self.failUnlessExists('import3/src/myfile')
146
self.runbzr('import source-0.1.tar.bz2 import4')
147
self.failUnlessExists('import4/src/myfile')
148
self.runbzr('import source-0.1 import5')
149
self.failUnlessExists('import5/src/myfile')
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())
151
219
def test_suite():
152
220
return makeSuite(TestBzrTools)