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 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)
4
class TestBzrTools(ExternalBase):
20
6
def touch(filename):
21
7
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')
23
24
def test_shelve(self):
25
self.run_bzr('commit -m uc --unchanged')
26
self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
26
self.runbzr('commit -m uc --unchanged')
27
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
27
28
file('foo', 'wb').write('foo')
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)
29
self.runbzr('add foo')
30
self.runbzr('commit -m foo')
31
self.runbzr('shelve -r 1 -m foo --all', retcode=0)
32
33
def test_fetch_ghosts(self):
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')
35
self.runbzr('fetch-ghosts .')
41
37
def test_patch(self):
43
39
file('myfile', 'wb').write('hello')
45
self.run_bzr('commit -m hello')
41
self.runbzr('commit -m hello')
46
42
file('myfile', 'wb').write('goodbye')
47
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
48
self.run_bzr('revert')
43
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
49
45
assert file('myfile', 'rb').read() == 'hello'
50
self.run_bzr('patch --silent mypatch')
46
self.runbzr('patch mypatch')
51
47
assert file('myfile', 'rb').read() == 'goodbye'
53
49
def test_branch_history(self):
55
51
file('myfile', 'wb').write('hello')
57
self.run_bzr('commit -m hello')
58
self.run_bzr('branch-history')
53
self.runbzr('commit -m hello')
54
self.runbzr('branch-history')
60
56
def test_branch_history(self):
62
58
file('myfile', 'wb').write('hello')
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')
60
self.runbzr('commit -m hello')
61
self.runbzr('graph-ancestry . graph.dot')
62
self.runbzr('branch . my_branch')
63
self.runbzr('graph-ancestry . graph.dot --merge-branch my_branch')
69
65
def test_fetch_ghosts(self):
71
67
file('myfile', 'wb').write('hello')
73
self.run_bzr('commit -m hello')
74
self.run_bzr('branch . my_branch')
75
self.run_bzr('fetch-ghosts my_branch')
78
self.run_bzr('init source')
79
self.run_bzr('checkout --lightweight source checkout')
80
self.run_bzr('zap checkout')
81
self.assertIs(False, os.path.exists('checkout'))
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')
96
def test_zap_branch(self):
97
self.run_bzr('init source')
98
self.run_bzr('checkout --lightweight source checkout')
99
self.run_bzr('zap --branch checkout', retcode=3)
100
self.assertIs(True, os.path.exists('checkout'))
101
self.assertIs(True, os.path.exists('source'))
102
self.run_bzr('branch source source2')
103
self.run_bzr('checkout --lightweight source2 checkout2')
104
self.run_bzr('zap --branch checkout2')
105
self.assertIs(False, os.path.exists('checkout2'))
106
self.assertIs(False, os.path.exists('source2'))
108
def test_branches(self):
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]
115
lines = out.split('\n')
116
self.assertIs(True, 'source' in lines)
117
self.assertIs(True, 'source/subsource' in lines)
118
self.assertIs(True, 'checkout/subcheckout' in lines)
119
self.assertIs(True, 'checkout' not in lines)
121
def test_import_upstream(self):
122
self.run_bzr('init source')
123
os.mkdir('source/src')
124
f = file('source/src/myfile', 'wb')
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')
134
os.chdir('../import')
135
self.run_bzr('import ../source-0.1.tar.gz')
136
self.failUnlessExists('src/myfile')
137
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
138
self.assertContainsRe(result, 'Working tree has uncommitted changes')
139
self.run_bzr('commit -m commit')
140
self.run_bzr('import ../source-0.1.tar.gz')
142
self.run_bzr('init import2')
143
self.run_bzr('import source-0.1.tar.gz import2')
144
self.failUnlessExists('import2/src/myfile')
145
self.run_bzr('import source-0.1.tar.gz import3')
146
self.failUnlessExists('import3/src/myfile')
147
self.run_bzr('import source-0.1.tar.bz2 import4')
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())
69
self.runbzr('commit -m hello')
70
self.runbzr('branch . my_branch')
71
self.runbzr('fetch-ghosts my_branch')
195
74
return makeSuite(TestBzrTools)