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 TestCaseWithTransport, HardlinkFeature
9
from bzrlib.plugins.bzrtools import command
12
class TestBzrTools(TestCaseWithTransport):
15
TestCaseWithTransport.setUp(self)
16
command._testing = True
17
self.addCleanup(command._stop_testing)
6
20
def touch(filename):
7
21
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
23
def test_shelve(self):
40
self.runbzr('commit -m uc --unchanged')
41
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
25
self.run_bzr('commit -m uc --unchanged')
26
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
42
27
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)
28
self.run_bzr('add foo')
29
self.run_bzr('commit -m foo')
30
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
47
32
def test_fetch_ghosts(self):
49
self.runbzr('fetch-ghosts .')
34
self.run_bzr('fetch-ghosts .')
36
def test_fetch_ghosts_with_saved(self):
37
wt = self.make_branch_and_tree('.')
38
wt.branch.set_parent('.')
39
self.run_bzr('fetch-ghosts')
51
41
def test_patch(self):
53
43
file('myfile', 'wb').write('hello')
55
self.runbzr('commit -m hello')
45
self.run_bzr('commit -m hello')
56
46
file('myfile', 'wb').write('goodbye')
57
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
47
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
48
self.run_bzr('revert')
59
49
assert file('myfile', 'rb').read() == 'hello'
60
self.runbzr('patch mypatch')
50
self.run_bzr('patch --silent mypatch')
61
51
assert file('myfile', 'rb').read() == 'goodbye'
63
53
def test_branch_history(self):
65
55
file('myfile', 'wb').write('hello')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
57
self.run_bzr('commit -m hello')
58
self.run_bzr('branch-history')
70
60
def test_branch_history(self):
72
62
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')
64
self.run_bzr('commit -m hello')
65
self.run_bzr('graph-ancestry . graph.dot')
66
self.run_bzr('branch . my_branch')
67
self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
79
69
def test_fetch_ghosts(self):
81
71
file('myfile', 'wb').write('hello')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
self.runbzr('fetch-ghosts my_branch')
73
self.run_bzr('commit -m hello')
74
self.run_bzr('branch . my_branch')
75
self.run_bzr('fetch-ghosts my_branch')
87
77
def test_zap(self):
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
78
self.run_bzr('init source')
79
self.run_bzr('checkout --lightweight source checkout')
80
self.run_bzr('zap checkout')
91
81
self.assertIs(False, os.path.exists('checkout'))
92
82
self.assertIs(True, os.path.exists('source'))
84
def test_zap_modified(self):
85
tree = self.make_branch_and_tree('source')
86
checkout = tree.branch.create_checkout('checkout', lightweight=True)
87
self.build_tree(['checkout/file'])
89
self.run_bzr_error(('This checkout has uncommitted changes',),
91
self.failUnlessExists('checkout')
92
self.run_bzr('zap checkout --force')
93
self.failIfExists('checkout')
94
self.failUnlessExists('source')
94
96
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)
97
self.run_bzr('init source')
98
self.run_bzr('checkout --lightweight source checkout')
99
self.run_bzr('zap --branch checkout', retcode=3)
98
100
self.assertIs(True, os.path.exists('checkout'))
99
101
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')
102
self.run_bzr('branch source source2')
103
self.run_bzr('checkout --lightweight source2 checkout2')
104
self.run_bzr('zap --branch checkout2')
103
105
self.assertIs(False, os.path.exists('checkout2'))
104
106
self.assertIs(False, os.path.exists('source2'))
106
108
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')
109
self.run_bzr('init source')
110
self.run_bzr('init source/subsource')
111
self.run_bzr('checkout --lightweight source checkout')
112
self.run_bzr('init checkout/subcheckout')
113
self.run_bzr('init checkout/.bzr/subcheckout')
114
out = self.run_bzr('branches')[0]
113
115
lines = out.split('\n')
114
116
self.assertIs(True, 'source' in lines)
115
117
self.assertIs(True, 'source/subsource' in lines)
116
118
self.assertIs(True, 'checkout/subcheckout' in lines)
117
119
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
120
121
def test_import_upstream(self):
121
self.runbzr('init source')
122
self.run_bzr('init source')
122
123
os.mkdir('source/src')
123
124
f = file('source/src/myfile', 'wb')
124
125
f.write('hello?')
126
127
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')
129
self.run_bzr('commit -m hello')
130
self.run_bzr('export ../source-0.1.tar.gz')
131
self.run_bzr('export ../source-0.1.tar.bz2')
132
self.run_bzr('export ../source-0.1')
133
self.run_bzr('init ../import')
132
134
os.chdir('../import')
133
self.runbzr('import ../source-0.1.tar.gz')
135
self.run_bzr('import ../source-0.1.tar.gz')
134
136
self.failUnlessExists('src/myfile')
135
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
137
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
136
138
self.assertContainsRe(result, 'Working tree has uncommitted changes')
137
self.runbzr('commit -m commit')
138
self.runbzr('import ../source-0.1.tar.gz')
139
self.run_bzr('commit -m commit')
140
self.run_bzr('import ../source-0.1.tar.gz')
140
self.runbzr('init import2')
141
self.runbzr('import source-0.1.tar.gz import2')
142
self.run_bzr('init import2')
143
self.run_bzr('import source-0.1.tar.gz import2')
142
144
self.failUnlessExists('import2/src/myfile')
143
self.runbzr('import source-0.1.tar.gz import3')
145
self.run_bzr('import source-0.1.tar.gz import3')
144
146
self.failUnlessExists('import3/src/myfile')
145
self.runbzr('import source-0.1.tar.bz2 import4')
147
self.run_bzr('import source-0.1.tar.bz2 import4')
146
148
self.failUnlessExists('import4/src/myfile')
149
self.run_bzr('import source-0.1 import5')
150
self.failUnlessExists('import5/src/myfile')
152
def test_cbranch(self):
153
source = self.make_branch_and_tree('source')
154
config = LocationConfig(osutils.abspath('target'))
155
config.set_user_option('cbranch_target', 'target_branch')
156
self.run_bzr('cbranch source target')
157
checkout = workingtree.WorkingTree.open('target')
158
self.assertEqual(checkout.branch.base,
159
get_transport('target').base)
160
self.assertEqual(checkout.branch.get_master_branch().base,
161
get_transport('target_branch').base)
162
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
163
get_transport('source').base)
165
def test_cbranch_hardlink(self):
166
self.requireFeature(HardlinkFeature)
167
# Later formats don't support hardlinks. Boo!
168
source = self.make_branch_and_tree('source', format='1.9')
169
self.build_tree(['source/file'])
171
source.commit('added file')
172
config = LocationConfig(osutils.abspath('target'))
173
config.set_user_option('cbranch_target', 'target_branch')
174
self.run_bzr('cbranch source target --lightweight')
175
checkout = workingtree.WorkingTree.open('target')
176
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
177
os.lstat(source.abspath('file')).st_ino)
178
config = LocationConfig(osutils.abspath('target2'))
179
config.set_user_option('cbranch_target', 'target_branch2')
180
self.run_bzr('cbranch source target2 --lightweight --hardlink')
181
checkout2 = workingtree.WorkingTree.open('target2')
182
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
183
os.lstat(source.abspath('file')).st_ino)
185
def test_create_mirror(self):
186
source = self.make_branch_and_tree('source')
187
source.commit('message')
188
self.run_bzr('create-mirror source target')
189
target = branch.Branch.open('target')
190
self.assertEqual(source.last_revision(), target.last_revision())
191
self.assertEqual(source.branch.base, target.get_public_branch())
148
194
def test_suite():
149
195
return makeSuite(TestBzrTools)