/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 breezy/tests/blackbox/test_cat.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
 
 
18
"""Black-box tests for brz cat.
 
19
"""
 
20
 
 
21
from ... import tests
 
22
from ...transport import memory
 
23
 
 
24
 
 
25
class TestCat(tests.TestCaseWithTransport):
 
26
 
 
27
    def test_cat(self):
 
28
        tree = self.make_branch_and_tree('branch')
 
29
        self.build_tree_contents([('branch/a', b'foo\n')])
 
30
        tree.add('a')
 
31
        # 'brz cat' without an option should cat the last revision
 
32
        self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
 
33
 
 
34
        tree.commit(message='1')
 
35
        self.build_tree_contents([('branch/a', b'baz\n')])
 
36
 
 
37
        self.assertEqual('foo\n',
 
38
                         self.run_bzr(['cat', 'a'], working_dir='branch')[0])
 
39
 
 
40
        # On Windows, we used to have a bug where newlines got changed into
 
41
        # crlf, whereas cat ought to write out the file exactly as it's
 
42
        # recorded (by default.)  That problem can't be reproduced in-process,
 
43
        # so we need just one test here that
 
44
        self.assertEqual(b'foo\n',
 
45
                         self.run_bzr_subprocess(['cat', 'a'],
 
46
                                                 working_dir='branch')[0])
 
47
 
 
48
        tree.commit(message='2')
 
49
        self.assertEqual(
 
50
            'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0])
 
51
        self.assertEqual(
 
52
            'foo\n', self.run_bzr(['cat', 'a', '-r', '1'],
 
53
                                  working_dir='branch')[0])
 
54
        self.assertEqual(
 
55
            'baz\n', self.run_bzr(['cat', 'a', '-r', '-1'],
 
56
                                  working_dir='branch')[0])
 
57
 
 
58
        rev_id = tree.branch.last_revision()
 
59
 
 
60
        self.assertEqual(
 
61
            'baz\n', self.run_bzr(
 
62
                ['cat', 'a', '-r', 'revid:%s' % rev_id.decode('utf-8')],
 
63
                working_dir='branch')[0])
 
64
 
 
65
        self.assertEqual('foo\n',
 
66
                         self.run_bzr(['cat', 'branch/a',
 
67
                                       '-r', 'revno:1:branch'])[0])
 
68
        self.run_bzr(['cat', 'a'], retcode=3)
 
69
        self.run_bzr(['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
 
70
                     retcode=3)
 
71
 
 
72
    def test_cat_different_id(self):
 
73
        """'cat' works with old and new files"""
 
74
        self.disable_missing_extensions_warning()
 
75
        tree = self.make_branch_and_tree('.')
 
76
        # the files are named after their path in the revision and
 
77
        # current trees later in the test case
 
78
        # a-rev-tree is special because it appears in both the revision
 
79
        # tree and the working tree
 
80
        self.build_tree_contents([('a-rev-tree', b'foo\n'),
 
81
                                  ('c-rev', b'baz\n'), ('d-rev', b'bar\n'), ('e-rev', b'qux\n')])
 
82
        with tree.lock_write():
 
83
            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
 
84
            tree.commit('add test files', rev_id=b'first')
 
85
            # remove currently uses self._write_inventory -
 
86
            # work around that for now.
 
87
            tree.flush()
 
88
            tree.remove(['d-rev'])
 
89
            tree.rename_one('a-rev-tree', 'b-tree')
 
90
            tree.rename_one('c-rev', 'a-rev-tree')
 
91
            tree.rename_one('e-rev', 'old-rev')
 
92
            self.build_tree_contents([('e-rev', b'new\n')])
 
93
            tree.add(['e-rev'])
 
94
 
 
95
        # 'b-tree' is not present in the old tree.
 
96
        self.run_bzr_error(["^brz: ERROR: u?'b-tree' "
 
97
                            "is not present in revision .+$"],
 
98
                           'cat b-tree --name-from-revision')
 
99
 
 
100
        # get to the old file automatically
 
101
        out, err = self.run_bzr('cat d-rev')
 
102
        self.assertEqual('', err)
 
103
        self.assertEqual('bar\n', out)
 
104
 
 
105
        out, err = \
 
106
            self.run_bzr('cat a-rev-tree --name-from-revision')
 
107
        self.assertEqual('foo\n', out)
 
108
        self.assertEqual('', err)
 
109
 
 
110
        out, err = self.run_bzr('cat a-rev-tree')
 
111
        self.assertEqual('baz\n', out)
 
112
        self.assertEqual('', err)
 
113
 
 
114
        # the actual file-id for e-rev doesn't exist in the old tree
 
115
        out, err = self.run_bzr('cat e-rev -rrevid:first')
 
116
        self.assertEqual('qux\n', out)
 
117
        self.assertEqual('', err)
 
118
 
 
119
    def test_remote_cat(self):
 
120
        wt = self.make_branch_and_tree('.')
 
121
        self.build_tree(['README'])
 
122
        wt.add('README')
 
123
        wt.commit('Making sure there is a basis_tree available')
 
124
 
 
125
        url = self.get_readonly_url() + '/README'
 
126
        out, err = self.run_bzr(['cat', url])
 
127
        self.assertEqual('contents of README\n', out)
 
128
 
 
129
    def test_cat_branch_revspec(self):
 
130
        wt = self.make_branch_and_tree('a')
 
131
        self.build_tree(['a/README'])
 
132
        wt.add('README')
 
133
        wt.commit('Making sure there is a basis_tree available')
 
134
        wt = self.make_branch_and_tree('b')
 
135
 
 
136
        out, err = self.run_bzr(['cat', '-r', 'branch:../a', 'README'],
 
137
                                working_dir='b')
 
138
        self.assertEqual('contents of a/README\n', out)
 
139
 
 
140
    def test_cat_filters(self):
 
141
        wt = self.make_branch_and_tree('.')
 
142
        self.build_tree(['README'])
 
143
        wt.add('README')
 
144
        wt.commit('Making sure there is a basis_tree available')
 
145
        url = self.get_readonly_url() + '/README'
 
146
 
 
147
        # Test unfiltered output
 
148
        out, err = self.run_bzr(['cat', url])
 
149
        self.assertEqual('contents of README\n', out)
 
150
 
 
151
        # Test --filters option is legal but has no impact if no filters
 
152
        out, err = self.run_bzr(['cat', '--filters', url])
 
153
        self.assertEqual('contents of README\n', out)
 
154
 
 
155
    def test_cat_filters_applied(self):
 
156
        # Test filtering applied to output. This is tricky to do in a
 
157
        # subprocess because we really need to patch in a plugin that
 
158
        # registers the filters. Instead, we patch in a custom
 
159
        # filter_stack and use run_bzr() ...
 
160
        from ..test_filters import _stack_2
 
161
        from ...tree import Tree
 
162
        wt = self.make_branch_and_tree('.')
 
163
        self.build_tree_contents([
 
164
            ('README', b"junk\nline 1 of README\nline 2 of README\n"),
 
165
            ])
 
166
        wt.add('README')
 
167
        wt.commit('Making sure there is a basis_tree available')
 
168
        url = self.get_readonly_url() + '/README'
 
169
        real_content_filter_stack = Tree._content_filter_stack
 
170
 
 
171
        def _custom_content_filter_stack(tree, path=None, file_id=None):
 
172
            return _stack_2
 
173
        Tree._content_filter_stack = _custom_content_filter_stack
 
174
        try:
 
175
            out, err = self.run_bzr(['cat', url, '--filters'])
 
176
            # The filter stack will remove the first line and swapcase the rest
 
177
            self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
 
178
            self.assertEqual('', err)
 
179
        finally:
 
180
            Tree._content_filter_stack = real_content_filter_stack
 
181
 
 
182
    def test_cat_no_working_tree(self):
 
183
        wt = self.make_branch_and_tree('.')
 
184
        self.build_tree(['README'])
 
185
        wt.add('README')
 
186
        wt.commit('Making sure there is a basis_tree available')
 
187
        wt.branch.controldir.destroy_workingtree()
 
188
 
 
189
        url = self.get_readonly_url() + '/README'
 
190
        out, err = self.run_bzr(['cat', url])
 
191
        self.assertEqual('contents of README\n', out)
 
192
 
 
193
    def test_cat_nonexistent_branch(self):
 
194
        self.vfs_transport_factory = memory.MemoryServer
 
195
        self.run_bzr_error(['^brz: ERROR: Not a branch'],
 
196
                           ['cat', self.get_url()])
 
197
 
 
198
    def test_cat_directory(self):
 
199
        wt = self.make_branch_and_tree('a')
 
200
        self.build_tree(['a/README'])
 
201
        wt.add('README')
 
202
        wt.commit('Making sure there is a basis_tree available')
 
203
 
 
204
        out, err = self.run_bzr(['cat', '--directory=a', 'README'])
 
205
        self.assertEqual('contents of a/README\n', out)
 
206
 
 
207
    def test_cat_remote_directory(self):
 
208
        wt = self.make_branch_and_tree('a')
 
209
        self.build_tree(['a/README'])
 
210
        wt.add('README')
 
211
        wt.commit('Making sure there is a basis_tree available')
 
212
 
 
213
        url = self.get_readonly_url() + '/a'
 
214
        out, err = self.run_bzr(['cat', '-d', url, 'README'])
 
215
        self.assertEqual('contents of a/README\n', out)