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.tests.matchers import ContainsNoVfsCalls
27
class TestRevno(tests.TestCaseWithTransport):
31
def bzr(*args, **kwargs):
32
return self.run_bzr(*args, **kwargs)[0]
37
self.assertEqual(int(bzr('revno')), 0)
39
with open('foo', 'wb') as f: f.write(b'foo\n')
42
self.assertEqual(int(bzr('revno')), 1)
47
self.assertEqual(int(bzr('revno')), 2)
50
self.assertEqual(int(bzr('revno a')), 2)
51
self.assertEqual(int(bzr('revno a/baz')), 2)
53
def test_revno_tree(self):
54
# Make branch and checkout
55
wt = self.make_branch_and_tree('branch')
56
checkout = wt.branch.create_checkout('checkout', lightweight=True)
58
# Get the checkout out of date
59
self.build_tree(['branch/file'])
63
# Make sure revno says we're on 1
64
out, err = self.run_bzr('revno checkout')
65
self.assertEqual(b'', err)
66
self.assertEqual(b'1\n', out)
68
# Make sure --tree knows it's still on 0
69
out, err = self.run_bzr('revno --tree checkout')
70
self.assertEqual(b'', err)
71
self.assertEqual(b'0\n', out)
73
def test_revno_tree_no_tree(self):
74
# Make treeless branch
75
b = self.make_branch('branch')
77
# Try getting it's --tree revno
78
out, err = self.run_bzr('revno --tree branch', retcode=3)
79
self.assertEqual(b'', out)
80
self.assertEqual(b'brz: ERROR: No WorkingTree exists for "branch".\n',
83
def test_dotted_revno_tree(self):
84
builder = self.make_branch_builder('branch')
85
builder.start_series()
86
builder.build_snapshot(None, [
87
('add', ('', b'root-id', 'directory', None)),
88
('add', ('file', b'file-id', 'file', b'content\n'))],
90
builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
91
builder.build_snapshot([b'A-id', b'B-id'], [], revision_id=b'C-id')
92
builder.finish_series()
93
b = builder.get_branch()
94
co_b = b.create_checkout('checkout_b', lightweight=True,
96
out, err = self.run_bzr('revno checkout_b')
97
self.assertEqual(b'', err)
98
self.assertEqual(b'2\n', out)
99
out, err = self.run_bzr('revno --tree checkout_b')
100
self.assertEqual(b'', err)
101
self.assertEqual(b'1.1.1\n', out)
103
def test_stale_revno_tree(self):
104
builder = self.make_branch_builder('branch')
105
builder.start_series()
106
builder.build_snapshot(None, [
107
('add', ('', b'root-id', 'directory', None)),
108
('add', ('file', b'file-id', 'file', b'content\n'))],
110
builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
111
builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
112
builder.finish_series()
113
b = builder.get_branch()
114
# The branch is now at "C-id", but the checkout is still at "B-id"
115
# which is no longer in the history
116
co_b = b.create_checkout('checkout_b', lightweight=True,
118
out, err = self.run_bzr('revno checkout_b')
119
self.assertEqual(b'', err)
120
self.assertEqual(b'2\n', out)
121
out, err = self.run_bzr('revno --tree checkout_b')
122
self.assertEqual(b'', err)
123
self.assertEqual(b'???\n', out)
125
def test_revno_with_revision(self):
126
wt = self.make_branch_and_tree('.')
127
revid1 = wt.commit('rev1')
128
revid2 = wt.commit('rev2')
130
out, err = self.run_bzr('revno -r-2 .')
131
self.assertEqual(b'1\n', out)
133
out, err = self.run_bzr('revno -rrevid:%s .' % revid1)
134
self.assertEqual(b'1\n', out)
136
def test_revno_and_tree_mutually_exclusive(self):
137
wt = self.make_branch_and_tree('.')
138
out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
139
self.assertEqual(b'', out)
141
b'brz: ERROR: --tree and --revision can not be used together\n',
145
class TestSmartServerRevno(tests.TestCaseWithTransport):
147
def test_simple_branch_revno(self):
148
self.setup_smart_server_with_call_log()
149
t = self.make_branch_and_tree('branch')
150
self.build_tree_contents([('branch/foo', b'thecontents')])
152
revid = t.commit("message")
153
self.reset_smart_call_log()
154
out, err = self.run_bzr(['revno', self.get_url('branch')])
155
# This figure represent the amount of work to perform this use case. It
156
# is entirely ok to reduce this number if a test fails due to rpc_count
157
# being too low. If rpc_count increases, more network roundtrips have
158
# become necessary for this use case. Please do not adjust this number
159
# upwards without agreement from bzr's network support maintainers.
160
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
161
self.assertLength(1, self.hpss_connections)
162
self.assertLength(6, self.hpss_calls)
164
def test_simple_branch_revno_lookup(self):
165
self.setup_smart_server_with_call_log()
166
t = self.make_branch_and_tree('branch')
167
self.build_tree_contents([('branch/foo', b'thecontents')])
169
revid1 = t.commit("message")
170
revid2 = t.commit("message")
171
self.reset_smart_call_log()
172
out, err = self.run_bzr(['revno', '-rrevid:' + revid1,
173
self.get_url('branch')])
174
# This figure represent the amount of work to perform this use case. It
175
# is entirely ok to reduce this number if a test fails due to rpc_count
176
# being too low. If rpc_count increases, more network roundtrips have
177
# become necessary for this use case. Please do not adjust this number
178
# upwards without agreement from bzr's network support maintainers.
179
self.assertLength(5, self.hpss_calls)
180
self.assertLength(1, self.hpss_connections)
181
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)