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