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):
11
self.runbzr('ignore *~')
12
self.runbzr('ignore *.pyc')
18
self.run_bzr('ignore *~')
19
self.run_bzr('ignore *.pyc')
14
21
self.touch('name~')
15
22
assert os.path.lexists('name~')
16
23
self.touch('name.pyc')
17
self.runbzr('clean-tree')
24
self.run_bzr('clean-tree --force')
18
25
assert os.path.lexists('name~')
19
26
assert not os.path.lexists('name')
21
self.runbzr('clean-tree --detritus')
28
self.run_bzr('clean-tree --detritus --force')
22
29
assert os.path.lexists('name')
23
30
assert not os.path.lexists('name~')
24
31
assert os.path.lexists('name.pyc')
25
self.runbzr('clean-tree --ignored')
32
self.run_bzr('clean-tree --ignored --force')
26
33
assert os.path.lexists('name')
27
34
assert not os.path.lexists('name.pyc')
28
self.runbzr('clean-tree --unknown')
35
self.run_bzr('clean-tree --unknown --force')
29
36
assert not os.path.lexists('name')
31
38
self.touch('name~')
32
39
self.touch('name.pyc')
33
self.runbzr('clean-tree --unknown --ignored')
40
self.run_bzr('clean-tree --unknown --ignored --force')
34
41
assert not os.path.lexists('name')
35
42
assert not os.path.lexists('name~')
36
43
assert not os.path.lexists('name.pyc')
38
45
def test_shelve(self):
40
self.runbzr('commit -m uc --unchanged')
41
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)
42
49
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)
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)
47
54
def test_fetch_ghosts(self):
49
self.runbzr('fetch-ghosts .')
56
self.run_bzr('fetch-ghosts .')
51
58
def test_patch(self):
53
60
file('myfile', 'wb').write('hello')
55
self.runbzr('commit -m hello')
62
self.run_bzr('commit -m hello')
56
63
file('myfile', 'wb').write('goodbye')
57
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')
59
66
assert file('myfile', 'rb').read() == 'hello'
60
self.runbzr('patch --silent mypatch')
67
self.run_bzr('patch --silent mypatch')
61
68
assert file('myfile', 'rb').read() == 'goodbye'
63
70
def test_branch_history(self):
65
72
file('myfile', 'wb').write('hello')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
74
self.run_bzr('commit -m hello')
75
self.run_bzr('branch-history')
70
77
def test_branch_history(self):
72
79
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')
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')
79
86
def test_fetch_ghosts(self):
81
88
file('myfile', 'wb').write('hello')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
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')
87
94
def test_zap(self):
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
95
self.run_bzr('init source')
96
self.run_bzr('checkout --lightweight source checkout')
97
self.run_bzr('zap checkout')
91
98
self.assertIs(False, os.path.exists('checkout'))
92
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')
94
113
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)
114
self.run_bzr('init source')
115
self.run_bzr('checkout --lightweight source checkout')
116
self.run_bzr('zap --branch checkout', retcode=3)
98
117
self.assertIs(True, os.path.exists('checkout'))
99
118
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')
119
self.run_bzr('branch source source2')
120
self.run_bzr('checkout --lightweight source2 checkout2')
121
self.run_bzr('zap --branch checkout2')
103
122
self.assertIs(False, os.path.exists('checkout2'))
104
123
self.assertIs(False, os.path.exists('source2'))
106
125
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')
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]
113
132
lines = out.split('\n')
114
133
self.assertIs(True, 'source' in lines)
115
134
self.assertIs(True, 'source/subsource' in lines)
116
135
self.assertIs(True, 'checkout/subcheckout' in lines)
117
136
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
120
138
def test_import_upstream(self):
121
self.runbzr('init source')
139
self.run_bzr('init source')
122
140
os.mkdir('source/src')
123
141
f = file('source/src/myfile', 'wb')
124
142
f.write('hello?')
126
144
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')
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')
133
151
os.chdir('../import')
134
self.runbzr('import ../source-0.1.tar.gz')
152
self.run_bzr('import ../source-0.1.tar.gz')
135
153
self.failUnlessExists('src/myfile')
136
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
154
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
137
155
self.assertContainsRe(result, 'Working tree has uncommitted changes')
138
self.runbzr('commit -m commit')
139
self.runbzr('import ../source-0.1.tar.gz')
156
self.run_bzr('commit -m commit')
157
self.run_bzr('import ../source-0.1.tar.gz')
141
self.runbzr('init import2')
142
self.runbzr('import source-0.1.tar.gz import2')
159
self.run_bzr('init import2')
160
self.run_bzr('import source-0.1.tar.gz import2')
143
161
self.failUnlessExists('import2/src/myfile')
144
self.runbzr('import source-0.1.tar.gz import3')
162
self.run_bzr('import source-0.1.tar.gz import3')
145
163
self.failUnlessExists('import3/src/myfile')
146
self.runbzr('import source-0.1.tar.bz2 import4')
164
self.run_bzr('import source-0.1.tar.bz2 import4')
147
165
self.failUnlessExists('import4/src/myfile')
148
self.runbzr('import source-0.1 import5')
166
self.run_bzr('import source-0.1 import5')
149
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)
151
202
def test_suite():
152
203
return makeSuite(TestBzrTools)