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
11
class TestBzrTools(TestCaseWithTransport):
6
13
def touch(filename):
7
14
file(filename, 'wb').write('')
9
16
def test_clean_tree(self):
18
self.run_bzr('ignore *~')
19
self.run_bzr('ignore *.pyc')
12
21
self.touch('name~')
13
22
assert os.path.lexists('name~')
14
23
self.touch('name.pyc')
15
self.runbzr('clean-tree')
24
self.run_bzr('clean-tree --force')
16
25
assert os.path.lexists('name~')
17
26
assert not os.path.lexists('name')
18
self.runbzr('clean-tree --detritus')
28
self.run_bzr('clean-tree --detritus --force')
29
assert os.path.lexists('name')
19
30
assert not os.path.lexists('name~')
20
31
assert os.path.lexists('name.pyc')
21
self.runbzr('clean-tree --ignored')
32
self.run_bzr('clean-tree --ignored --force')
33
assert os.path.lexists('name')
34
assert not os.path.lexists('name.pyc')
35
self.run_bzr('clean-tree --unknown --force')
36
assert not os.path.lexists('name')
39
self.touch('name.pyc')
40
self.run_bzr('clean-tree --unknown --ignored --force')
41
assert not os.path.lexists('name')
42
assert not os.path.lexists('name~')
22
43
assert not os.path.lexists('name.pyc')
24
45
def test_shelve(self):
26
self.runbzr('commit -m uc --unchanged')
27
self.runbzr('shelve -r 1 -m foo --all', retcode=3)
47
self.run_bzr('commit -m uc --unchanged')
48
self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
28
49
file('foo', 'wb').write('foo')
29
self.runbzr('add foo')
30
self.runbzr('commit -m foo')
31
self.runbzr('shelve -r 1 -m foo --all', retcode=0)
50
self.run_bzr('add foo')
51
self.run_bzr('commit -m foo')
52
self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
33
54
def test_fetch_ghosts(self):
35
self.runbzr('fetch-ghosts .')
56
self.run_bzr('fetch-ghosts .')
37
58
def test_patch(self):
39
60
file('myfile', 'wb').write('hello')
41
self.runbzr('commit -m hello')
62
self.run_bzr('commit -m hello')
42
63
file('myfile', 'wb').write('goodbye')
43
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
64
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
65
self.run_bzr('revert')
45
66
assert file('myfile', 'rb').read() == 'hello'
46
self.runbzr('patch mypatch')
67
self.run_bzr('patch --silent mypatch')
47
68
assert file('myfile', 'rb').read() == 'goodbye'
49
70
def test_branch_history(self):
51
72
file('myfile', 'wb').write('hello')
53
self.runbzr('commit -m hello')
54
self.runbzr('branch-history')
74
self.run_bzr('commit -m hello')
75
self.run_bzr('branch-history')
56
77
def test_branch_history(self):
58
79
file('myfile', 'wb').write('hello')
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')
81
self.run_bzr('commit -m hello')
82
self.run_bzr('graph-ancestry . graph.dot')
83
self.run_bzr('branch . my_branch')
84
self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
65
86
def test_fetch_ghosts(self):
67
88
file('myfile', 'wb').write('hello')
69
self.runbzr('commit -m hello')
70
self.runbzr('branch . my_branch')
71
self.runbzr('fetch-ghosts my_branch')
90
self.run_bzr('commit -m hello')
91
self.run_bzr('branch . my_branch')
92
self.run_bzr('fetch-ghosts my_branch')
95
self.run_bzr('init source')
96
self.run_bzr('checkout --lightweight source checkout')
97
self.run_bzr('zap checkout')
98
self.assertIs(False, os.path.exists('checkout'))
99
self.assertIs(True, os.path.exists('source'))
101
def test_zap_modified(self):
102
tree = self.make_branch_and_tree('source')
103
checkout = tree.branch.create_checkout('checkout', lightweight=True)
104
self.build_tree(['checkout/file'])
106
self.run_bzr_error(('This checkout has uncommitted changes',),
108
self.failUnlessExists('checkout')
109
self.run_bzr('zap checkout --force')
110
self.failIfExists('checkout')
111
self.failUnlessExists('source')
113
def test_zap_branch(self):
114
self.run_bzr('init source')
115
self.run_bzr('checkout --lightweight source checkout')
116
self.run_bzr('zap --branch checkout', retcode=3)
117
self.assertIs(True, os.path.exists('checkout'))
118
self.assertIs(True, os.path.exists('source'))
119
self.run_bzr('branch source source2')
120
self.run_bzr('checkout --lightweight source2 checkout2')
121
self.run_bzr('zap --branch checkout2')
122
self.assertIs(False, os.path.exists('checkout2'))
123
self.assertIs(False, os.path.exists('source2'))
125
def test_branches(self):
126
self.run_bzr('init source')
127
self.run_bzr('init source/subsource')
128
self.run_bzr('checkout --lightweight source checkout')
129
self.run_bzr('init checkout/subcheckout')
130
self.run_bzr('init checkout/.bzr/subcheckout')
131
out = self.run_bzr('branches')[0]
132
lines = out.split('\n')
133
self.assertIs(True, 'source' in lines)
134
self.assertIs(True, 'source/subsource' in lines)
135
self.assertIs(True, 'checkout/subcheckout' in lines)
136
self.assertIs(True, 'checkout' not in lines)
138
def test_import_upstream(self):
139
self.run_bzr('init source')
140
os.mkdir('source/src')
141
f = file('source/src/myfile', 'wb')
146
self.run_bzr('commit -m hello')
147
self.run_bzr('export ../source-0.1.tar.gz')
148
self.run_bzr('export ../source-0.1.tar.bz2')
149
self.run_bzr('export ../source-0.1')
150
self.run_bzr('init ../import')
151
os.chdir('../import')
152
self.run_bzr('import ../source-0.1.tar.gz')
153
self.failUnlessExists('src/myfile')
154
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
155
self.assertContainsRe(result, 'Working tree has uncommitted changes')
156
self.run_bzr('commit -m commit')
157
self.run_bzr('import ../source-0.1.tar.gz')
159
self.run_bzr('init import2')
160
self.run_bzr('import source-0.1.tar.gz import2')
161
self.failUnlessExists('import2/src/myfile')
162
self.run_bzr('import source-0.1.tar.gz import3')
163
self.failUnlessExists('import3/src/myfile')
164
self.run_bzr('import source-0.1.tar.bz2 import4')
165
self.failUnlessExists('import4/src/myfile')
166
self.run_bzr('import source-0.1 import5')
167
self.failUnlessExists('import5/src/myfile')
169
def test_cbranch(self):
170
source = self.make_branch_and_tree('source')
171
config = LocationConfig(osutils.abspath('target'))
172
config.set_user_option('cbranch_target', 'target_branch')
173
self.run_bzr('cbranch source target')
174
checkout = workingtree.WorkingTree.open('target')
175
self.assertEqual(checkout.branch.base,
176
get_transport('target').base)
177
self.assertEqual(checkout.branch.get_master_branch().base,
178
get_transport('target_branch').base)
179
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
180
get_transport('source').base)
182
def test_cbranch_hardlink(self):
183
self.requireFeature(HardlinkFeature)
184
source = self.make_branch_and_tree('source')
185
self.build_tree(['source/file'])
187
source.commit('added file')
188
config = LocationConfig(osutils.abspath('target'))
189
config.set_user_option('cbranch_target', 'target_branch')
190
self.run_bzr('cbranch source target --lightweight')
191
checkout = workingtree.WorkingTree.open('target')
192
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
193
os.lstat(source.abspath('file')).st_ino)
194
config = LocationConfig(osutils.abspath('target2'))
195
config.set_user_option('cbranch_target', 'target_branch2')
196
self.run_bzr('cbranch source target2 --lightweight --hardlink')
197
checkout2 = workingtree.WorkingTree.open('target2')
198
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
199
os.lstat(source.abspath('file')).st_ino)
74
203
return makeSuite(TestBzrTools)