1
# Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2016 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz revno.
23
from breezy import tests
24
from breezy.errors import NoSuchRevision
25
from breezy.tests.matchers import ContainsNoVfsCalls
28
class TestRevno(tests.TestCaseWithTransport):
32
def bzr(*args, **kwargs):
33
return self.run_bzr(*args, **kwargs)[0]
38
self.assertEqual(int(bzr('revno')), 0)
40
with open('foo', 'wb') as f:
44
self.assertEqual(int(bzr('revno')), 1)
49
self.assertEqual(int(bzr('revno')), 2)
52
self.assertEqual(int(bzr('revno a')), 2)
53
self.assertEqual(int(bzr('revno a/baz')), 2)
55
def test_revno_tree(self):
56
# Make branch and checkout
57
wt = self.make_branch_and_tree('branch')
58
checkout = wt.branch.create_checkout('checkout', lightweight=True)
60
# Get the checkout out of date
61
self.build_tree(['branch/file'])
65
# Make sure revno says we're on 1
66
out, err = self.run_bzr('revno checkout')
67
self.assertEqual('', err)
68
self.assertEqual('1\n', out)
70
# Make sure --tree knows it's still on 0
71
out, err = self.run_bzr('revno --tree checkout')
72
self.assertEqual('', err)
73
self.assertEqual('0\n', out)
75
def test_revno_tree_no_tree(self):
76
# Make treeless branch
77
b = self.make_branch('branch')
79
# Try getting it's --tree revno
80
out, err = self.run_bzr('revno --tree branch', retcode=3)
81
self.assertEqual('', out)
82
self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
85
def test_dotted_revno_tree(self):
86
builder = self.make_branch_builder('branch')
87
builder.start_series()
88
builder.build_snapshot(None, [
89
('add', ('', b'root-id', 'directory', None)),
90
('add', ('file', b'file-id', 'file', b'content\n'))],
92
builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
93
builder.build_snapshot([b'A-id', b'B-id'], [], revision_id=b'C-id')
94
builder.finish_series()
95
b = builder.get_branch()
96
co_b = b.create_checkout('checkout_b', lightweight=True,
98
out, err = self.run_bzr('revno checkout_b')
99
self.assertEqual('', err)
100
self.assertEqual('2\n', out)
101
out, err = self.run_bzr('revno --tree checkout_b')
102
self.assertEqual('', err)
103
self.assertEqual('1.1.1\n', out)
105
def test_stale_revno_tree(self):
106
builder = self.make_branch_builder('branch')
107
builder.start_series()
108
builder.build_snapshot(None, [
109
('add', ('', b'root-id', 'directory', None)),
110
('add', ('file', b'file-id', 'file', b'content\n'))],
112
builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
113
builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
114
builder.finish_series()
115
b = builder.get_branch()
116
# The branch is now at "C-id", but the checkout is still at "B-id"
117
# which is no longer in the history
118
co_b = b.create_checkout('checkout_b', lightweight=True,
120
out, err = self.run_bzr('revno checkout_b')
121
self.assertEqual('', err)
122
self.assertEqual('2\n', out)
123
out, err = self.run_bzr('revno --tree checkout_b')
124
self.assertEqual('', err)
125
self.assertEqual('???\n', out)
127
def test_revno_ghost(self):
128
builder = self.make_branch_builder('branch')
129
builder.start_series()
130
revid = builder.build_snapshot([b'aghost'], [
131
('add', ('', b'root-id', 'directory', None)),
132
('add', ('file', b'file-id', 'file', b'content\n'))],
133
revision_id=b'A-id', allow_leftmost_as_ghost=True)
134
builder.finish_series()
135
b = builder.get_branch()
137
def revision_id_to_revno(s, r):
138
raise NoSuchRevision(s, r)
139
self.overrideAttr(type(b), 'revision_id_to_dotted_revno', revision_id_to_revno)
140
self.overrideAttr(type(b), 'revision_id_to_revno', revision_id_to_revno)
141
out, err = self.run_bzr('revno branch')
142
self.assertEqual('', err)
143
self.assertEqual('???\n', out)
145
def test_revno_with_revision(self):
146
wt = self.make_branch_and_tree('.')
147
revid1 = wt.commit('rev1')
148
revid2 = wt.commit('rev2')
150
out, err = self.run_bzr('revno -r-2 .')
151
self.assertEqual('1\n', out)
153
out, err = self.run_bzr('revno -rrevid:%s .' % revid1.decode('utf-8'))
154
self.assertEqual('1\n', out)
156
def test_revno_and_tree_mutually_exclusive(self):
157
wt = self.make_branch_and_tree('.')
158
out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
159
self.assertEqual('', out)
161
'brz: ERROR: --tree and --revision can not be used together\n',
165
class TestSmartServerRevno(tests.TestCaseWithTransport):
167
def test_simple_branch_revno(self):
168
self.setup_smart_server_with_call_log()
169
t = self.make_branch_and_tree('branch')
170
self.build_tree_contents([('branch/foo', b'thecontents')])
172
revid = t.commit("message")
173
self.reset_smart_call_log()
174
out, err = self.run_bzr(['revno', self.get_url('branch')])
175
# This figure represent the amount of work to perform this use case. It
176
# is entirely ok to reduce this number if a test fails due to rpc_count
177
# being too low. If rpc_count increases, more network roundtrips have
178
# become necessary for this use case. Please do not adjust this number
179
# upwards without agreement from bzr's network support maintainers.
180
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
181
self.assertLength(1, self.hpss_connections)
182
self.assertLength(6, self.hpss_calls)
184
def test_simple_branch_revno_lookup(self):
185
self.setup_smart_server_with_call_log()
186
t = self.make_branch_and_tree('branch')
187
self.build_tree_contents([('branch/foo', b'thecontents')])
189
revid1 = t.commit("message")
190
revid2 = t.commit("message")
191
self.reset_smart_call_log()
192
out, err = self.run_bzr(['revno', '-rrevid:' + revid1.decode('utf-8'),
193
self.get_url('branch')])
194
# This figure represent the amount of work to perform this use case. It
195
# is entirely ok to reduce this number if a test fails due to rpc_count
196
# being too low. If rpc_count increases, more network roundtrips have
197
# become necessary for this use case. Please do not adjust this number
198
# upwards without agreement from bzr's network support maintainers.
199
self.assertLength(5, self.hpss_calls)
200
self.assertLength(1, self.hpss_connections)
201
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)