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('')
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')
16
24
def test_shelve(self):
18
self.run_bzr('commit -m uc --unchanged')
19
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)
20
28
file('foo', 'wb').write('foo')
21
self.run_bzr('add foo')
22
self.run_bzr('commit -m foo')
23
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)
25
33
def test_fetch_ghosts(self):
27
self.run_bzr('fetch-ghosts .')
35
self.runbzr('fetch-ghosts .')
29
37
def test_patch(self):
31
39
file('myfile', 'wb').write('hello')
33
self.run_bzr('commit -m hello')
41
self.runbzr('commit -m hello')
34
42
file('myfile', 'wb').write('goodbye')
35
file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
36
self.run_bzr('revert')
43
file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
37
45
assert file('myfile', 'rb').read() == 'hello'
38
self.run_bzr('patch --silent mypatch')
46
self.runbzr('patch mypatch')
39
47
assert file('myfile', 'rb').read() == 'goodbye'
41
49
def test_branch_history(self):
43
51
file('myfile', 'wb').write('hello')
45
self.run_bzr('commit -m hello')
46
self.run_bzr('branch-history')
53
self.runbzr('commit -m hello')
54
self.runbzr('branch-history')
48
56
def test_branch_history(self):
50
58
file('myfile', 'wb').write('hello')
52
self.run_bzr('commit -m hello')
53
self.run_bzr('graph-ancestry . graph.dot')
54
self.run_bzr('branch . my_branch')
55
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')
57
65
def test_fetch_ghosts(self):
59
67
file('myfile', 'wb').write('hello')
61
self.run_bzr('commit -m hello')
62
self.run_bzr('branch . my_branch')
63
self.run_bzr('fetch-ghosts my_branch')
69
self.runbzr('commit -m hello')
70
self.runbzr('branch . my_branch')
71
self.runbzr('fetch-ghosts my_branch')
65
73
def test_zap(self):
66
self.run_bzr('init source')
67
self.run_bzr('checkout --lightweight source checkout')
68
self.run_bzr('zap checkout')
74
self.runbzr('init source')
75
self.runbzr('checkout --lightweight source checkout')
76
self.runbzr('zap checkout')
69
77
self.assertIs(False, os.path.exists('checkout'))
70
78
self.assertIs(True, os.path.exists('source'))
72
def test_zap_modified(self):
73
tree = self.make_branch_and_tree('source')
74
checkout = tree.branch.create_checkout('checkout', lightweight=True)
75
self.build_tree(['checkout/file'])
77
self.run_bzr_error(('This checkout has uncommitted changes',),
79
self.failUnlessExists('checkout')
80
self.run_bzr('zap checkout --force')
81
self.failIfExists('checkout')
82
self.failUnlessExists('source')
84
80
def test_zap_branch(self):
85
self.run_bzr('init source')
86
self.run_bzr('checkout --lightweight source checkout')
87
self.run_bzr('zap --branch checkout', retcode=3)
88
self.assertIs(True, os.path.exists('checkout'))
89
self.assertIs(True, os.path.exists('source'))
90
self.run_bzr('branch source source2')
91
self.run_bzr('checkout --lightweight source2 checkout2')
92
self.run_bzr('zap --branch checkout2')
93
self.assertIs(False, os.path.exists('checkout2'))
94
self.assertIs(False, os.path.exists('source2'))
81
self.runbzr('init source')
82
self.runbzr('checkout --lightweight source checkout')
83
self.runbzr('zap --branch checkout')
84
self.assertIs(False, os.path.exists('checkout'))
85
self.assertIs(False, os.path.exists('source'))
96
87
def test_branches(self):
97
self.run_bzr('init source')
98
self.run_bzr('init source/subsource')
99
self.run_bzr('checkout --lightweight source checkout')
100
self.run_bzr('init checkout/subcheckout')
101
self.run_bzr('init checkout/.bzr/subcheckout')
102
out = self.run_bzr('branches')[0]
88
self.runbzr('init source')
89
self.runbzr('init source/subsource')
90
self.runbzr('checkout --lightweight source checkout')
91
self.runbzr('init checkout/subcheckout')
92
self.runbzr('init checkout/.bzr/subcheckout')
93
out = self.capture('branches')
103
94
lines = out.split('\n')
104
95
self.assertIs(True, 'source' in lines)
105
96
self.assertIs(True, 'source/subsource' in lines)
106
97
self.assertIs(True, 'checkout/subcheckout' in lines)
107
98
self.assertIs(True, 'checkout' not in lines)
99
self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
109
101
def test_import_upstream(self):
110
self.run_bzr('init source')
102
self.runbzr('init source')
111
103
os.mkdir('source/src')
112
104
f = file('source/src/myfile', 'wb')
113
105
f.write('hello?')
115
107
os.chdir('source')
117
self.run_bzr('commit -m hello')
118
self.run_bzr('export ../source-0.1.tar.gz')
119
self.run_bzr('export ../source-0.1.tar.bz2')
120
self.run_bzr('export ../source-0.1')
121
self.run_bzr('init ../import')
109
self.runbzr('commit -m hello')
110
self.runbzr('export ../source-0.1.tar.gz')
111
self.runbzr('export ../source-0.1.tar.bz2')
112
self.runbzr('init ../import')
122
113
os.chdir('../import')
123
self.run_bzr('import ../source-0.1.tar.gz')
114
self.runbzr('import ../source-0.1.tar.gz')
124
115
self.failUnlessExists('src/myfile')
125
result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
116
result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
126
117
self.assertContainsRe(result, 'Working tree has uncommitted changes')
127
self.run_bzr('commit -m commit')
128
self.run_bzr('import ../source-0.1.tar.gz')
118
self.runbzr('commit -m commit')
119
self.runbzr('import ../source-0.1.tar.gz')
130
self.run_bzr('init import2')
131
self.run_bzr('import source-0.1.tar.gz import2')
121
self.runbzr('init import2')
122
self.runbzr('import source-0.1.tar.gz import2')
132
123
self.failUnlessExists('import2/src/myfile')
133
self.run_bzr('import source-0.1.tar.gz import3')
124
self.runbzr('import source-0.1.tar.gz import3')
134
125
self.failUnlessExists('import3/src/myfile')
135
self.run_bzr('import source-0.1.tar.bz2 import4')
126
self.runbzr('import source-0.1.tar.bz2 import4')
136
127
self.failUnlessExists('import4/src/myfile')
137
self.run_bzr('import source-0.1 import5')
138
self.failUnlessExists('import5/src/myfile')
140
def test_cbranch(self):
141
source = self.make_branch_and_tree('source')
142
config = LocationConfig(osutils.abspath('target'))
143
config.set_user_option('cbranch_target', 'target_branch')
144
self.run_bzr('cbranch source target')
145
checkout = workingtree.WorkingTree.open('target')
146
self.assertEqual(checkout.branch.base,
147
get_transport('target').base)
148
self.assertEqual(checkout.branch.get_master_branch().base,
149
get_transport('target_branch').base)
150
self.assertEqual(checkout.branch.get_master_branch().get_parent(),
151
get_transport('source').base)
153
def test_cbranch_hardlink(self):
154
self.requireFeature(HardlinkFeature)
155
# Later formats don't support hardlinks. Boo!
156
source = self.make_branch_and_tree('source', format='1.9')
157
self.build_tree(['source/file'])
159
source.commit('added file')
160
config = LocationConfig(osutils.abspath('target'))
161
config.set_user_option('cbranch_target', 'target_branch')
162
self.run_bzr('cbranch source target --lightweight')
163
checkout = workingtree.WorkingTree.open('target')
164
self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
165
os.lstat(source.abspath('file')).st_ino)
166
config = LocationConfig(osutils.abspath('target2'))
167
config.set_user_option('cbranch_target', 'target_branch2')
168
self.run_bzr('cbranch source target2 --lightweight --hardlink')
169
checkout2 = workingtree.WorkingTree.open('target2')
170
self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
171
os.lstat(source.abspath('file')).st_ino)
173
def test_create_mirror(self):
174
source = self.make_branch_and_tree('source')
175
source.commit('message')
176
self.run_bzr('create-mirror source target')
177
target = branch.Branch.open('target')
178
self.assertEqual(source.last_revision(), target.last_revision())
179
self.assertEqual(source.branch.base, target.get_public_branch())
182
130
def test_suite():