/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_cat.py

  • Committer: Robert Collins
  • Date: 2007-09-19 05:14:14 UTC
  • mto: (2835.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2836.
  • Revision ID: robertc@robertcollins.net-20070919051414-2tgjqteg7k3ps4h0
* ``pull``, ``merge`` and ``push`` will no longer silently correct some
  repository index errors that occured as a result of the Weave disk format.
  Instead the ``reconcile`` command needs to be run to correct those
  problems if they exist (and it has been able to fix most such problems
  since bzr 0.8). Some new problems have been identified during this release
  and you should run ``bzr check`` once on every repository to see if you
  need to reconcile. If you cannot ``pull`` or ``merge`` from a remote
  repository due to mismatched parent errors - a symptom of index errors -
  you should simply take a full copy of that remote repository to a clean
  directory outside any local repositories, then run reconcile on it, and
  finally pull from it locally. (And naturally email the repositories owner
  to ask them to upgrade and run reconcile).
  (Robert Collins)

* ``VersionedFile.fix_parents`` has been removed as a harmful API.
  ``VersionedFile.join`` will no longer accept different parents on either
  side of a join - it will either ignore them, or error, depending on the
  implementation. See notes when upgrading for more information.
  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr cat.
 
20
"""
 
21
 
 
22
import os
 
23
 
 
24
from bzrlib.tests.blackbox import TestCaseWithTransport
 
25
 
 
26
class TestCat(TestCaseWithTransport):
 
27
 
 
28
    def test_cat(self):
 
29
        tree = self.make_branch_and_tree('branch')
 
30
        self.build_tree_contents([('branch/a', 'foo\n')])
 
31
        tree.add('a')
 
32
        os.chdir('branch')
 
33
        # 'bzr cat' without an option should cat the last revision
 
34
        self.run_bzr(['cat', 'a'], retcode=3)
 
35
 
 
36
        tree.commit(message='1')
 
37
        self.build_tree_contents([('a', 'baz\n')])
 
38
 
 
39
        # We use run_bzr_subprocess rather than run_bzr here so that we can
 
40
        # test mangling of line-endings on Windows.
 
41
        self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
 
42
 
 
43
        tree.commit(message='2')
 
44
        self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'baz\n')
 
45
        self.assertEquals(self.run_bzr_subprocess(
 
46
            ['cat', 'a', '-r', '1'])[0],
 
47
            'foo\n')
 
48
        self.assertEquals(self.run_bzr_subprocess(
 
49
            ['cat', 'a', '-r', '-1'])[0],
 
50
            'baz\n')
 
51
 
 
52
        rev_id = tree.branch.last_revision()
 
53
 
 
54
        self.assertEquals(self.run_bzr_subprocess(
 
55
            ['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
 
56
            'baz\n')
 
57
 
 
58
        os.chdir('..')
 
59
 
 
60
        self.assertEquals(self.run_bzr_subprocess(
 
61
            ['cat', 'branch/a', '-r', 'revno:1:branch'])[0],
 
62
            'foo\n')
 
63
        self.run_bzr(['cat', 'a'], retcode=3)
 
64
        self.run_bzr(
 
65
                ['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
 
66
                retcode=3)
 
67
 
 
68
    def test_cat_different_id(self):
 
69
        """'cat' works with old and new files"""
 
70
        tree = self.make_branch_and_tree('.')
 
71
        # the files are named after their path in the revision and
 
72
        # current trees later in the test case
 
73
        # a-rev-tree is special because it appears in both the revision
 
74
        # tree and the working tree
 
75
        self.build_tree_contents([('a-rev-tree', 'foo\n'),
 
76
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
 
77
        tree.lock_write()
 
78
        try:
 
79
            tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
 
80
            tree.commit('add test files')
 
81
            # remove currently uses self._write_inventory - 
 
82
            # work around that for now.
 
83
            tree.flush()
 
84
            tree.remove(['d-rev'])
 
85
            tree.rename_one('a-rev-tree', 'b-tree')
 
86
            tree.rename_one('c-rev', 'a-rev-tree')
 
87
        finally:
 
88
            # calling bzr as another process require free lock on win32
 
89
            tree.unlock()
 
90
 
 
91
        # 'b-tree' is not present in the old tree.
 
92
        self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
 
93
                            "is not present in revision .+$"],
 
94
                           'cat b-tree --name-from-revision')
 
95
 
 
96
        # get to the old file automatically
 
97
        out, err = self.run_bzr_subprocess('cat d-rev')
 
98
        self.assertEqual('bar\n', out)
 
99
        self.assertEqual('', err)
 
100
 
 
101
        out, err = \
 
102
                self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
 
103
        self.assertEqual('foo\n', out)
 
104
        self.assertEqual('', err)
 
105
 
 
106
        out, err = self.run_bzr_subprocess('cat a-rev-tree')
 
107
        self.assertEqual('baz\n', out)
 
108
        self.assertEqual('', err)
 
109
 
 
110
    def test_remote_cat(self):
 
111
        wt = self.make_branch_and_tree('.')
 
112
        self.build_tree(['README'])
 
113
        wt.add('README')
 
114
        wt.commit('Making sure there is a basis_tree available')
 
115
 
 
116
        url = self.get_readonly_url() + '/README'
 
117
        out, err = self.run_bzr_subprocess(['cat', url])
 
118
        self.assertEqual('contents of README\n', out)
 
119
 
 
120
    def test_cat_no_working_tree(self):
 
121
        wt = self.make_branch_and_tree('.')
 
122
        self.build_tree(['README'])
 
123
        wt.add('README')
 
124
        wt.commit('Making sure there is a basis_tree available')
 
125
        wt.branch.bzrdir.destroy_workingtree()
 
126
 
 
127
        url = self.get_readonly_url() + '/README'
 
128
        out, err = self.run_bzr_subprocess(['cat', url])
 
129
        self.assertEqual('contents of README\n', out)
 
130