1
# Copyright (C) 2005, 2006, 2007, 2009 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 bzr revno.
23
from bzrlib import tests
24
from bzrlib.tests.matchers import ContainsNoVfsCalls
27
class TestRevno(tests.TestCaseWithTransport):
31
def bzr(*args, **kwargs):
32
return self.run_bzr(*args, **kwargs)[0]
37
self.assertEquals(int(bzr('revno')), 0)
39
with open('foo', 'wb') as f: f.write('foo\n')
42
self.assertEquals(int(bzr('revno')), 1)
47
self.assertEquals(int(bzr('revno')), 2)
50
self.assertEquals(int(bzr('revno a')), 2)
51
self.assertEquals(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('', err)
66
self.assertEqual('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('', err)
71
self.assertEqual('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('', out)
80
self.assertEqual('bzr: 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('A-id', None, [
87
('add', ('', 'root-id', 'directory', None)),
88
('add', ('file', 'file-id', 'file', 'content\n'))])
89
builder.build_snapshot('B-id', ['A-id'], [])
90
builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
91
builder.finish_series()
92
b = builder.get_branch()
93
co_b = b.create_checkout('checkout_b', lightweight=True,
95
out, err = self.run_bzr('revno checkout_b')
96
self.assertEqual('', err)
97
self.assertEqual('2\n', out)
98
out, err = self.run_bzr('revno --tree checkout_b')
99
self.assertEqual('', err)
100
self.assertEqual('1.1.1\n', out)
102
def test_stale_revno_tree(self):
103
builder = self.make_branch_builder('branch')
104
builder.start_series()
105
builder.build_snapshot('A-id', None, [
106
('add', ('', 'root-id', 'directory', None)),
107
('add', ('file', 'file-id', 'file', 'content\n'))])
108
builder.build_snapshot('B-id', ['A-id'], [])
109
builder.build_snapshot('C-id', ['A-id'], [])
110
builder.finish_series()
111
b = builder.get_branch()
112
# The branch is now at "C-id", but the checkout is still at "B-id"
113
# which is no longer in the history
114
co_b = b.create_checkout('checkout_b', lightweight=True,
116
out, err = self.run_bzr('revno checkout_b')
117
self.assertEqual('', err)
118
self.assertEqual('2\n', out)
119
out, err = self.run_bzr('revno --tree checkout_b')
120
self.assertEqual('', err)
121
self.assertEqual('???\n', out)
123
def test_revno_with_revision(self):
124
wt = self.make_branch_and_tree('.')
125
revid1 = wt.commit('rev1')
126
revid2 = wt.commit('rev2')
128
out, err = self.run_bzr('revno -r-2 .')
129
self.assertEqual('1\n', out)
131
out, err = self.run_bzr('revno -rrevid:%s .' % revid1)
132
self.assertEqual('1\n', out)
134
def test_revno_and_tree_mutually_exclusive(self):
135
wt = self.make_branch_and_tree('.')
136
out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
137
self.assertEqual('', out)
139
'bzr: ERROR: --tree and --revision can not be used together\n',
143
class TestSmartServerRevno(tests.TestCaseWithTransport):
145
def test_simple_branch_revno(self):
146
self.setup_smart_server_with_call_log()
147
t = self.make_branch_and_tree('branch')
148
self.build_tree_contents([('branch/foo', 'thecontents')])
150
revid = t.commit("message")
151
self.reset_smart_call_log()
152
out, err = self.run_bzr(['revno', self.get_url('branch')])
153
# This figure represent the amount of work to perform this use case. It
154
# is entirely ok to reduce this number if a test fails due to rpc_count
155
# being too low. If rpc_count increases, more network roundtrips have
156
# become necessary for this use case. Please do not adjust this number
157
# upwards without agreement from bzr's network support maintainers.
158
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
159
self.assertLength(1, self.hpss_connections)
160
self.assertLength(6, self.hpss_calls)
162
def test_simple_branch_revno_lookup(self):
163
self.setup_smart_server_with_call_log()
164
t = self.make_branch_and_tree('branch')
165
self.build_tree_contents([('branch/foo', 'thecontents')])
167
revid1 = t.commit("message")
168
revid2 = t.commit("message")
169
self.reset_smart_call_log()
170
out, err = self.run_bzr(['revno', '-rrevid:' + revid1,
171
self.get_url('branch')])
172
# This figure represent the amount of work to perform this use case. It
173
# is entirely ok to reduce this number if a test fails due to rpc_count
174
# being too low. If rpc_count increases, more network roundtrips have
175
# become necessary for this use case. Please do not adjust this number
176
# upwards without agreement from bzr's network support maintainers.
177
self.assertLength(5, self.hpss_calls)
178
self.assertLength(1, self.hpss_connections)
179
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)