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):
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')
23
38
def test_shelve(self):
25
self.run_bzr('commit -m uc --unchanged')
26
self.run_bzr('shelve1 -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)
27
42
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)
43
self.runbzr('add foo')
44
self.runbzr('commit -m foo')
45
self.runbzr('shelve -r 1 -m foo --all', retcode=0)
32
47
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')
49
self.runbzr('fetch-ghosts .')
41
51
def test_patch(self):
43
53
file('myfile', 'wb').write('hello')
45
self.run_bzr('commit -m hello')
55
self.runbzr('commit -m hello')
46
56
file('myfile', 'wb').write('goodbye')
47
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
48
self.run_bzr('revert')
57
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
49
59
assert file('myfile', 'rb').read() == 'hello'
50
self.run_bzr('patch --silent mypatch')
60
self.runbzr('patch mypatch')
51
61
assert file('myfile', 'rb').read() == 'goodbye'
53
63
def test_branch_history(self):
55
65
file('myfile', 'wb').write('hello')
57
self.run_bzr('commit -m hello')
58
self.run_bzr('branch-history')
67
self.runbzr('commit -m hello')
68
self.runbzr('branch-history')
60
70
def test_branch_history(self):
62
72
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')
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')
69
79
def test_fetch_ghosts(self):
71
81
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')
83
self.runbzr('commit -m hello')
84
self.runbzr('branch . my_branch')
85
self.runbzr('fetch-ghosts my_branch')
77
87
def test_zap(self):
78
self.run_bzr('init source')
79
self.run_bzr('checkout --lightweight source checkout')
80
self.run_bzr('zap checkout')
88
self.runbzr('init source')
89
self.runbzr('checkout --lightweight source checkout')
90
self.runbzr('zap checkout')
81
91
self.assertIs(False, os.path.exists('checkout'))
82
92
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
94
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)
95
self.runbzr('init source')
96
self.runbzr('checkout --lightweight source checkout')
97
self.runbzr('zap --branch checkout', retcode=3)
100
98
self.assertIs(True, os.path.exists('checkout'))
101
99
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')
100
self.runbzr('branch source source2')
101
self.runbzr('checkout --lightweight source2 checkout2')
102
self.runbzr('zap --branch checkout2')
105
103
self.assertIs(False, os.path.exists('checkout2'))
106
104
self.assertIs(False, os.path.exists('source2'))
108
106
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]
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')
115
113
lines = out.split('\n')
116
114
self.assertIs(True, 'source' in lines)
117
115
self.assertIs(True, 'source/subsource' in lines)
118
116
self.assertIs(True, 'checkout/subcheckout' in lines)
119
117
self.assertIs(True, 'checkout' not in lines)
118
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
121
120
def test_import_upstream(self):
122
self.run_bzr('init source')
121
self.runbzr('init source')
123
122
os.mkdir('source/src')
124
123
f = file('source/src/myfile', 'wb')
125
124
f.write('hello?')
127
126
os.chdir('source')
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')
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')
134
132
os.chdir('../import')
135
self.run_bzr('import ../source-0.1.tar.gz')
133
self.runbzr('import ../source-0.1.tar.gz')
136
134
self.failUnlessExists('src/myfile')
137
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
135
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
138
136
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')
137
self.runbzr('commit -m commit')
138
self.runbzr('import ../source-0.1.tar.gz')
142
self.run_bzr('init import2')
143
self.run_bzr('import source-0.1.tar.gz import2')
140
self.runbzr('init import2')
141
self.runbzr('import source-0.1.tar.gz import2')
144
142
self.failUnlessExists('import2/src/myfile')
145
self.run_bzr('import source-0.1.tar.gz import3')
143
self.runbzr('import source-0.1.tar.gz import3')
146
144
self.failUnlessExists('import3/src/myfile')
147
self.run_bzr('import source-0.1.tar.bz2 import4')
145
self.runbzr('import source-0.1.tar.bz2 import4')
148
146
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
def test_shove(self):
149
self.runbzr('init source')
150
f = file('source/file', 'wb')
153
self.runbzr('add source/file')
154
self.runbzr('commit source -m foo')
155
self.runbzr('branch source target1')
156
self.runbzr('branch source target2')
157
f = file('source/file', 'wb')
160
self.runbzr('shove target1 source')
161
f = file('target1/file', 'rb')
162
self.assertEqual(f.read(), 'goodbye\n')
165
self.runbzr('shove target2', retcode=3)
166
self.runbzr('shove ../target2')
167
f = file('../target2/file', 'rb')
168
self.assertEqual(f.read(), 'goodbye\n')
194
171
def test_suite():
195
172
return makeSuite(TestBzrTools)