1
from bzrlib.tests.blackbox import ExternalBase
2
from unittest import makeSuite
3
from unittest import makeSuite
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)
4
class TestBzrTools(ExternalBase):
36
6
def touch(filename):
37
7
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')
39
38
def test_shelve(self):
41
self.run_bzr('commit -m uc --unchanged')
42
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
40
self.runbzr('commit -m uc --unchanged')
41
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
43
42
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)
43
self.runbzr('add foo')
44
self.runbzr('commit -m foo')
45
self.runbzr('shelve -r 1 -m foo --all', retcode=0)
48
47
def test_fetch_ghosts(self):
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')
49
self.runbzr('fetch-ghosts .')
57
51
def test_patch(self):
59
53
file('myfile', 'wb').write('hello')
61
self.run_bzr('commit -m hello')
55
self.runbzr('commit -m hello')
62
56
file('myfile', 'wb').write('goodbye')
63
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
64
self.run_bzr('revert')
57
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
65
59
assert file('myfile', 'rb').read() == 'hello'
66
self.run_bzr('patch --silent mypatch')
60
self.runbzr('patch mypatch')
67
61
assert file('myfile', 'rb').read() == 'goodbye'
69
63
def test_branch_history(self):
71
65
file('myfile', 'wb').write('hello')
73
self.run_bzr('commit -m hello')
74
self.run_bzr('branch-history')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
76
70
def test_branch_history(self):
78
72
file('myfile', 'wb').write('hello')
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')
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')
85
79
def test_fetch_ghosts(self):
87
81
file('myfile', 'wb').write('hello')
89
self.run_bzr('commit -m hello')
90
self.run_bzr('branch . my_branch')
91
self.run_bzr('fetch-ghosts my_branch')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
self.runbzr('fetch-ghosts my_branch')
93
87
def test_zap(self):
94
self.run_bzr('init source')
95
self.run_bzr('checkout --lightweight source checkout')
96
self.run_bzr('zap checkout')
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
97
91
self.assertIs(False, os.path.exists('checkout'))
98
92
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
94
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)
95
self.runbzr('init source')
96
self.runbzr('checkout --lightweight source checkout')
97
self.runbzr('zap --branch checkout', retcode=3)
116
98
self.assertIs(True, os.path.exists('checkout'))
117
99
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')
100
self.runbzr('branch source source2')
101
self.runbzr('checkout --lightweight source2 checkout2')
102
self.runbzr('zap --branch checkout2')
121
103
self.assertIs(False, os.path.exists('checkout2'))
122
104
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]
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')
131
113
lines = out.split('\n')
132
114
self.assertIs(True, 'source' in lines)
133
115
self.assertIs(True, 'source/subsource' in lines)
134
116
self.assertIs(True, 'checkout/subcheckout' in lines)
135
117
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
137
120
def test_import_upstream(self):
138
self.run_bzr('init source')
121
self.runbzr('init source')
139
122
os.mkdir('source/src')
140
123
f = file('source/src/myfile', 'wb')
141
124
f.write('hello?')
143
126
os.chdir('source')
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')
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')
150
132
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]
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]
154
136
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())
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')
228
148
def test_suite():
229
149
return makeSuite(TestBzrTools)