/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_revno.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz revno.
 
18
"""Black-box tests for bzr revno.
19
19
"""
20
20
 
21
21
import os
22
22
 
23
 
from breezy import tests
24
 
from breezy.errors import NoSuchRevision
25
 
from breezy.tests.matchers import ContainsNoVfsCalls
26
 
 
 
23
from bzrlib import tests
27
24
 
28
25
class TestRevno(tests.TestCaseWithTransport):
29
26
 
35
32
        os.mkdir('a')
36
33
        os.chdir('a')
37
34
        bzr('init')
38
 
        self.assertEqual(int(bzr('revno')), 0)
 
35
        self.assertEquals(int(bzr('revno')), 0)
39
36
 
40
 
        with open('foo', 'wb') as f:
41
 
            f.write(b'foo\n')
 
37
        open('foo', 'wb').write('foo\n')
42
38
        bzr('add foo')
43
39
        bzr('commit -m foo')
44
 
        self.assertEqual(int(bzr('revno')), 1)
 
40
        self.assertEquals(int(bzr('revno')), 1)
45
41
 
46
42
        os.mkdir('baz')
47
43
        bzr('add baz')
48
44
        bzr('commit -m baz')
49
 
        self.assertEqual(int(bzr('revno')), 2)
 
45
        self.assertEquals(int(bzr('revno')), 2)
50
46
 
51
47
        os.chdir('..')
52
 
        self.assertEqual(int(bzr('revno a')), 2)
53
 
        self.assertEqual(int(bzr('revno a/baz')), 2)
 
48
        self.assertEquals(int(bzr('revno a')), 2)
 
49
        self.assertEquals(int(bzr('revno a/baz')), 2)
54
50
 
55
51
    def test_revno_tree(self):
56
52
        # Make branch and checkout
63
59
        wt.commit('mkfile')
64
60
 
65
61
        # Make sure revno says we're on 1
66
 
        out, err = self.run_bzr('revno checkout')
 
62
        out,err = self.run_bzr('revno checkout')
67
63
        self.assertEqual('', err)
68
64
        self.assertEqual('1\n', out)
69
65
 
70
66
        # Make sure --tree knows it's still on 0
71
 
        out, err = self.run_bzr('revno --tree checkout')
 
67
        out,err = self.run_bzr('revno --tree checkout')
72
68
        self.assertEqual('', err)
73
69
        self.assertEqual('0\n', out)
74
70
 
77
73
        b = self.make_branch('branch')
78
74
 
79
75
        # Try getting it's --tree revno
80
 
        out, err = self.run_bzr('revno --tree branch', retcode=3)
 
76
        out,err = self.run_bzr('revno --tree branch', retcode=3)
81
77
        self.assertEqual('', out)
82
 
        self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
83
 
                         err)
 
78
        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
 
79
            err)
84
80
 
85
81
    def test_dotted_revno_tree(self):
86
82
        builder = self.make_branch_builder('branch')
87
83
        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'))],
91
 
            revision_id=b'A-id')
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')
 
84
        builder.build_snapshot('A-id', None, [
 
85
            ('add', ('', 'root-id', 'directory', None)),
 
86
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
87
        builder.build_snapshot('B-id', ['A-id'], [])
 
88
        builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
94
89
        builder.finish_series()
95
90
        b = builder.get_branch()
96
91
        co_b = b.create_checkout('checkout_b', lightweight=True,
97
 
                                 revision_id=b'B-id')
 
92
                                 revision_id='B-id')
98
93
        out, err = self.run_bzr('revno checkout_b')
99
94
        self.assertEqual('', err)
100
95
        self.assertEqual('2\n', out)
105
100
    def test_stale_revno_tree(self):
106
101
        builder = self.make_branch_builder('branch')
107
102
        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'))],
111
 
            revision_id=b'A-id')
112
 
        builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
113
 
        builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
 
103
        builder.build_snapshot('A-id', None, [
 
104
            ('add', ('', 'root-id', 'directory', None)),
 
105
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
106
        builder.build_snapshot('B-id', ['A-id'], [])
 
107
        builder.build_snapshot('C-id', ['A-id'], [])
114
108
        builder.finish_series()
115
109
        b = builder.get_branch()
116
110
        # The branch is now at "C-id", but the checkout is still at "B-id"
117
111
        # which is no longer in the history
118
112
        co_b = b.create_checkout('checkout_b', lightweight=True,
119
 
                                 revision_id=b'B-id')
 
113
                                 revision_id='B-id')
120
114
        out, err = self.run_bzr('revno checkout_b')
121
115
        self.assertEqual('', err)
122
116
        self.assertEqual('2\n', out)
123
117
        out, err = self.run_bzr('revno --tree checkout_b')
124
118
        self.assertEqual('', err)
125
119
        self.assertEqual('???\n', out)
126
 
 
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()
136
 
 
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)
144
 
 
145
 
    def test_revno_with_revision(self):
146
 
        wt = self.make_branch_and_tree('.')
147
 
        revid1 = wt.commit('rev1')
148
 
        revid2 = wt.commit('rev2')
149
 
 
150
 
        out, err = self.run_bzr('revno -r-2 .')
151
 
        self.assertEqual('1\n', out)
152
 
 
153
 
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1.decode('utf-8'))
154
 
        self.assertEqual('1\n', out)
155
 
 
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)
160
 
        self.assertEqual(
161
 
            'brz: ERROR: --tree and --revision can not be used together\n',
162
 
            err)
163
 
 
164
 
 
165
 
class TestSmartServerRevno(tests.TestCaseWithTransport):
166
 
 
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')])
171
 
        t.add("foo")
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)
183
 
 
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')])
188
 
        t.add("foo")
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)