1
# Copyright (C) 2005-2010, 2016 Canonical Ltd
1
# Copyright (C) 2004, 2005 by Canonical Ltd
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from breezy.errors import BzrCommandError, NoSuchRevision
20
from breezy.tests import TestCaseWithTransport
21
from breezy.workingtree import WorkingTree
24
class TestRevisionInfo(TestCaseWithTransport):
18
from bzrlib.selftest import TestCaseInTempDir
19
from bzrlib.errors import BzrCommandError, NoSuchRevision
20
from bzrlib.branch import Branch
21
from bzrlib.revisionspec import RevisionSpec
23
class TestRevisionInfo(TestCaseInTempDir):
25
def check_error(self, output, *args):
26
"""Verify that the expected error matches what bzr says.
28
The output is supplied first, so that you can supply a variable
29
number of arguments to bzr.
31
self.assertEquals(self.run_bzr_captured(args, retcode=1)[1], output)
26
33
def check_output(self, output, *args):
27
"""Verify that the expected output matches what brz says.
34
"""Verify that the expected output matches what bzr says.
29
36
The output is supplied first, so that you can supply a variable
30
37
number of arguments to bzr.
32
self.assertEqual(self.run_bzr(*args)[0], output)
39
self.assertEquals(self.run_bzr_captured(args)[0], output)
34
41
def test_revision_info(self):
35
"""Test that 'brz revision-info' reports the correct thing."""
36
wt = self.make_branch_and_tree('.')
38
# Make history with a non-mainline rev
39
wt.commit('Commit one', rev_id=b'a@r-0-1')
40
wt.commit('Commit two', rev_id=b'a@r-0-1.1.1')
41
wt.set_parent_ids([b'a@r-0-1', b'a@r-0-1.1.1'])
42
wt.branch.set_last_revision_info(1, b'a@r-0-1')
43
wt.commit('Commit three', rev_id=b'a@r-0-2')
45
# This is expected to work even if the working tree is removed
46
wt.controldir.destroy_workingtree()
48
# Expected return values
42
"""Test that 'bzr revision-info' reports the correct thing.
45
b = Branch.initialize('.')
47
b.commit('Commit one', rev_id='a@r-0-1')
48
b.commit('Commit two', rev_id='a@r-0-2')
49
b.commit('Commit three', rev_id='a@r-0-3')
51
# Make sure revision-info without any arguments throws an exception
52
self.check_error('bzr: ERROR: You must supply a revision identifier\n',
51
'1.1.1': '1.1.1 a@r-0-1.1.1\n',
55
# Make sure with no arg it defaults to the head
56
self.check_output(values['2'], 'revision-info')
58
61
# Check the results of just specifying a numeric revision
59
self.check_output(values['1'], 'revision-info 1')
60
self.check_output(values['1.1.1'], 'revision-info 1.1.1')
61
self.check_output(values['2'], 'revision-info 2')
62
self.check_output(values['1'] + values['2'], 'revision-info 1 2')
63
self.check_output(' ' + values['1']
66
'revision-info 1 1.1.1 2')
67
self.check_output(values['2'] + values['1'], 'revision-info 2 1')
62
self.check_output(values[1], 'revision-info', '1')
63
self.check_output(values[2], 'revision-info', '2')
64
self.check_output(values[3], 'revision-info', '3')
65
self.check_output(values[1]+values[2], 'revision-info', '1', '2')
66
self.check_output(values[1]+values[2]+values[3], 'revision-info', '1', '2', '3')
67
self.check_output(values[2]+values[1], 'revision-info', '2', '1')
69
69
# Check as above, only using the '--revision' syntax
71
self.check_output(values['1'], 'revision-info -r 1')
72
self.check_output(values['1.1.1'], 'revision-info --revision 1.1.1')
73
self.check_output(values['2'], 'revision-info -r 2')
74
self.check_output(values['1'] + values['2'], 'revision-info -r 1..2')
75
self.check_output(' ' + values['1']
78
'revision-info -r 1..1.1.1..2')
79
self.check_output(values['2'] + values['1'], 'revision-info -r 2..1')
71
self.check_output(' 1 a@r-0-1\n', 'revision-info', '-r', '1')
72
self.check_output(' 2 a@r-0-2\n', 'revision-info', '--revision', '2')
73
self.check_output(' 3 a@r-0-3\n', 'revision-info', '-r', '3')
74
self.check_output(' 1 a@r-0-1\n 2 a@r-0-2\n', 'revision-info', '-r', '1..2')
75
self.check_output(' 1 a@r-0-1\n 2 a@r-0-2\n 3 a@r-0-3\n'
76
, 'revision-info', '-r', '1..2..3')
77
self.check_output(' 2 a@r-0-2\n 1 a@r-0-1\n', 'revision-info', '-r', '2..1')
81
79
# Now try some more advanced revision specifications
83
self.check_output(values['1'], 'revision-info -r revid:a@r-0-1')
84
self.check_output(values['1.1.1'],
85
'revision-info --revision revid:a@r-0-1.1.1')
87
def test_revision_info_explicit_branch_dir(self):
88
"""Test that 'brz revision-info' honors the '-d' option."""
89
wt = self.make_branch_and_tree('branch')
91
wt.commit('Commit one', rev_id=b'a@r-0-1')
92
self.check_output('1 a@r-0-1\n', 'revision-info -d branch')
94
def test_revision_info_tree(self):
95
# Make branch and checkout
96
wt = self.make_branch_and_tree('branch')
97
wt.commit('Commit one', rev_id=b'a@r-0-1')
99
# Make checkout and move the branch forward
100
wt.branch.create_checkout('checkout', lightweight=True)
101
wt.commit('Commit two', rev_id=b'a@r-0-2')
103
# Make sure the checkout gives the right answer for branch and
105
self.check_output('2 a@r-0-2\n', 'revision-info -d checkout')
106
self.check_output('1 a@r-0-1\n', 'revision-info --tree -d checkout')
108
def test_revision_info_tree_no_working_tree(self):
109
# Make branch with no tree
110
b = self.make_branch('branch')
112
# Try getting the --tree revision-info
113
out, err = self.run_bzr('revision-info --tree -d branch', retcode=3)
114
self.assertEqual('', out)
115
self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
118
def test_revision_info_not_in_history(self):
119
builder = self.make_branch_builder('branch')
120
builder.start_series()
121
builder.build_snapshot(None, [
122
('add', ('', b'root-id', 'directory', None))],
124
builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
125
builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
126
builder.finish_series()
127
self.check_output(' 1 A-id\n??? B-id\n 2 C-id\n',
128
'revision-info -d branch'
129
' revid:A-id revid:B-id revid:C-id')
81
self.check_output(' 1 a@r-0-1\n', 'revision-info', '-r', 'revid:a@r-0-1')
82
self.check_output(' 2 a@r-0-2\n', 'revision-info', '--revision', 'revid:a@r-0-2')
84
def test_cat_revision(self):
85
"""Test bzr cat-revision.
87
b = Branch.initialize('.')
89
b.commit('Commit one', rev_id='a@r-0-1')
90
b.commit('Commit two', rev_id='a@r-0-2')
91
b.commit('Commit three', rev_id='a@r-0-3')
94
1:b.get_revision_xml_file('a@r-0-1').read(),
95
2:b.get_revision_xml_file('a@r-0-2').read(),
96
3:b.get_revision_xml_file('a@r-0-3').read()
99
self.check_output(revs[1], 'cat-revision', 'a@r-0-1')
100
self.check_output(revs[2], 'cat-revision', 'a@r-0-2')
101
self.check_output(revs[3], 'cat-revision', 'a@r-0-3')
103
self.check_output(revs[1], 'cat-revision', '-r', '1')
104
self.check_output(revs[2], 'cat-revision', '-r', '2')
105
self.check_output(revs[3], 'cat-revision', '-r', '3')
107
self.check_output(revs[1], 'cat-revision', '-r', 'revid:a@r-0-1')
108
self.check_output(revs[2], 'cat-revision', '-r', 'revid:a@r-0-2')
109
self.check_output(revs[3], 'cat-revision', '-r', 'revid:a@r-0-3')