/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2007-2018 Jelmer Vernoij <jelmer@jelmer.uk>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
2
# Copyright (C) 2006, 2007 Canonical Ltd
3
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
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.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
8
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
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.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
13
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
17
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
18
"""The basic test suite for bzr-git."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
22
from cStringIO import StringIO
23
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
24
import time
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
25
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
26
from .... import (
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
27
    errors as bzr_errors,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
28
    tests,
29
    )
0.200.1297 by Jelmer Vernooij
Cope with older versions of bzr.
30
try:
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
31
    from ....tests.features import Feature
0.200.1297 by Jelmer Vernooij
Cope with older versions of bzr.
32
except ImportError: # bzr < 2.5
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
33
    from ....tests import Feature
34
from .. import (
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
35
    import_dulwich,
0.200.255 by Jelmer Vernooij
Fix formatting.
36
    )
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
37
from fastimport import (
38
    commands,
39
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
40
41
TestCase = tests.TestCase
42
TestCaseInTempDir = tests.TestCaseInTempDir
43
TestCaseWithTransport = tests.TestCaseWithTransport
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
44
TestCaseWithMemoryTransport = tests.TestCaseWithMemoryTransport
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
45
0.200.1296 by Jelmer Vernooij
Cope with Feature only being available from bzrlib.tests.features.
46
class _DulwichFeature(Feature):
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
47
48
    def _probe(self):
49
        try:
50
            import_dulwich()
51
        except bzr_errors.DependencyNotPresent:
52
            return False
53
        return True
54
55
    def feature_name(self):
56
        return 'dulwich'
57
58
59
DulwichFeature = _DulwichFeature()
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
60
61
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
62
class GitBranchBuilder(object):
63
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
64
    def __init__(self, stream=None):
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
65
        self.commit_info = []
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
66
        self.orig_stream = stream
67
        if stream is None:
68
            self.stream = StringIO()
69
        else:
70
            self.stream = stream
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
71
        self._counter = 0
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
72
        self._branch = 'refs/heads/master'
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
73
74
    def set_branch(self, branch):
75
        """Set the branch we are committing."""
76
        self._branch = branch
77
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
78
    def _write(self, text):
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
79
        self.stream.write(text)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
80
81
    def _writelines(self, lines):
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
82
        self.stream.writelines(lines)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
83
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
84
    def _create_blob(self, content):
85
        self._counter += 1
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
86
        blob = commands.BlobCommand(str(self._counter), content)
87
        self._write(str(blob)+"\n")
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
88
        return self._counter
89
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
90
    def set_symlink(self, path, content):
91
        """Create or update symlink at a given path."""
92
        mark = self._create_blob(content)
93
        mode = '120000'
94
        self.commit_info.append('M %s :%d %s\n'
95
                % (mode, mark, self._encode_path(path)))
96
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
97
    def set_file(self, path, content, executable):
98
        """Create or update content at a given path."""
99
        mark = self._create_blob(content)
100
        if executable:
101
            mode = '100755'
102
        else:
103
            mode = '100644'
104
        self.commit_info.append('M %s :%d %s\n'
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
105
                                % (mode, mark, self._encode_path(path)))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
106
107
    def set_link(self, path, link_target):
108
        """Create or update a link at a given path."""
109
        mark = self._create_blob(link_target)
110
        self.commit_info.append('M 120000 :%d %s\n'
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
111
                                % (mark, self._encode_path(path)))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
112
113
    def delete_entry(self, path):
114
        """This will delete files or symlinks at the given location."""
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
115
        self.commit_info.append('D %s\n' % (self._encode_path(path),))
116
117
    @staticmethod
118
    def _encode_path(path):
119
        if '\n' in path or path[0] == '"':
120
            path = path.replace('\\', '\\\\')
121
            path = path.replace('\n', '\\n')
122
            path = path.replace('"', '\\"')
123
            path = '"' + path + '"'
124
        return path.encode('utf-8')
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
125
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
126
    # TODO: Author
127
    # TODO: Author timestamp+timezone
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
128
    def commit(self, committer, message, timestamp=None,
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
129
               timezone='+0000', author=None,
130
               merge=None, base=None):
131
        """Commit the new content.
132
133
        :param committer: The name and address for the committer
134
        :param message: The commit message
135
        :param timestamp: The timestamp for the commit
136
        :param timezone: The timezone of the commit, such as '+0000' or '-1000'
137
        :param author: The name and address of the author (if different from
138
            committer)
139
        :param merge: A list of marks if this should merge in another commit
140
        :param base: An id for the base revision (primary parent) if that
141
            is not the last commit.
142
        :return: A mark which can be used in the future to reference this
143
            commit.
144
        """
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
145
        self._counter += 1
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
146
        mark = str(self._counter)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
147
        if timestamp is None:
148
            timestamp = int(time.time())
149
        self._write('commit %s\n' % (self._branch,))
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
150
        self._write('mark :%s\n' % (mark,))
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
151
        self._write('committer %s %s %s\n'
152
                    % (committer, timestamp, timezone))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
153
        message = message.encode('UTF-8')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
154
        self._write('data %d\n' % (len(message),))
155
        self._write(message)
156
        self._write('\n')
157
        if base is not None:
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
158
            self._write('from :%s\n' % (base,))
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
159
        if merge is not None:
160
            for m in merge:
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
161
                self._write('merge :%s\n' % (m,))
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
162
        self._writelines(self.commit_info)
163
        self._write('\n')
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
164
        self.commit_info = []
165
        return mark
166
0.200.34 by David Allouche
GitBranchBuilder.reset()
167
    def reset(self, ref=None, mark=None):
168
        """Create or recreate the named branch.
169
170
        :param ref: branch name, defaults to the current branch.
171
        :param mark: commit the branch will point to.
172
        """
173
        if ref is None:
174
            ref = self._branch
175
        self._write('reset %s\n' % (ref,))
176
        if mark is not None:
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
177
            self._write('from :%s\n' % mark)
0.200.34 by David Allouche
GitBranchBuilder.reset()
178
        self._write('\n')
179
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
180
    def finish(self):
181
        """We are finished building, close the stream, get the id mapping"""
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
182
        self.stream.seek(0)
183
        if self.orig_stream is None:
184
            from dulwich.repo import Repo
185
            r = Repo(".")
0.200.1045 by Jelmer Vernooij
Use new fastexport import processor in Dulwich.
186
            from dulwich.fastexport import GitImportProcessor
187
            importer = GitImportProcessor(r)
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
188
            return importer.import_stream(self.stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
189
190
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
191
def test_suite():
0.200.1028 by Jelmer Vernooij
Fix imports of TestLoader on newer versions of bzr.
192
    loader = tests.TestUtil.TestLoader()
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
193
0.200.1028 by Jelmer Vernooij
Fix imports of TestLoader on newer versions of bzr.
194
    suite = tests.TestUtil.TestSuite()
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
195
196
    testmod_names = [
0.200.813 by Jelmer Vernooij
Add tests for revspec.
197
        'test_blackbox',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
198
        'test_builder',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
199
        'test_branch',
0.200.938 by Jelmer Vernooij
Rename shamap to cache, as it can also do content caching now.
200
        'test_cache',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
201
        'test_dir',
0.200.196 by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker.
202
        'test_fetch',
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
203
        'test_git_remote_helper',
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
204
        'test_mapping',
0.360.7 by Jelmer Vernooij
Add tests for memorytree.
205
        'test_memorytree',
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
206
        'test_object_store',
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
207
        'test_pristine_tar',
0.200.967 by Jelmer Vernooij
Add initial test for push.
208
        'test_push',
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
209
        'test_remote',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
210
        'test_repository',
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
211
        'test_refs',
0.200.813 by Jelmer Vernooij
Add tests for revspec.
212
        'test_revspec',
0.252.1 by Jelmer Vernooij
Support storing revision id data.
213
        'test_roundtrip',
0.200.1430 by Jelmer Vernooij
Add basic tests for server.
214
        'test_server',
0.200.936 by Jelmer Vernooij
Test transportgit.
215
        'test_transportgit',
0.200.1292 by Jelmer Vernooij
Fix repeeling objects when determining what to send.
216
        'test_unpeel_map',
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
217
        'test_workingtree',
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
218
        ]
219
    testmod_names = ['%s.%s' % (__name__, t) for t in testmod_names]
220
    suite.addTests(loader.loadTestsFromModuleNames(testmod_names))
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
221
222
    return suite