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