/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
1
# Copyright (C) 2007 Canonical Ltd
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
2
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
17
18
"""Tests for interfacing with a Git Repository"""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.445 by Jelmer Vernooij
Import dulwich as dulwich, not as git.
22
import dulwich
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
23
from dulwich.repo import (
24
    Repo as GitRepo,
25
    )
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
26
import os
27
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
28
from .... import (
0.200.61 by Jelmer Vernooij
Fix tests.
29
    errors,
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
30
    revision,
31
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
32
from ....repository import (
0.200.357 by Jelmer Vernooij
Move push code to push.py.
33
    InterRepository,
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
34
    Repository,
35
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
36
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
37
from .. import (
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
38
    dir,
39
    repository,
0.200.97 by Jelmer Vernooij
use mapping object.
40
    tests,
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
41
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
42
from ..mapping import (
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
43
    default_mapping,
44
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
45
from ..object_store import (
0.235.2 by Jelmer Vernooij
Fix tests.
46
    BazaarObjectStore,
47
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
48
from ..push import (
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
49
    MissingObjectsIterator,
50
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
51
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
52
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
53
    """Feature tests for GitRepository."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
54
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
55
    def _do_commit(self):
56
        builder = tests.GitBranchBuilder()
57
        builder.set_file('a', 'text for a\n', False)
58
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
59
        mapping = builder.finish()
60
        return mapping[commit_handle]
61
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
62
    def test_open_existing(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
63
        GitRepo.init(self.test_dir)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
64
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
65
        repo = Repository.open('.')
66
        self.assertIsInstance(repo, repository.GitRepository)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
67
0.200.56 by Jelmer Vernooij
Switch to using GitPython rather than our own in-house stuff.
68
    def test_has_git_repo(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
69
        GitRepo.init(self.test_dir)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
70
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
71
        repo = Repository.open('.')
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
72
        self.assertIsInstance(repo._git, dulwich.repo.BaseRepo)
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
73
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
74
    def test_has_revision(self):
75
        GitRepo.init(self.test_dir)
76
        commit_id = self._do_commit()
77
        repo = Repository.open('.')
78
        self.assertFalse(repo.has_revision('foobar'))
79
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
80
        self.assertTrue(repo.has_revision(revid))
81
82
    def test_has_revisions(self):
83
        GitRepo.init(self.test_dir)
84
        commit_id = self._do_commit()
85
        repo = Repository.open('.')
86
        self.assertEquals(set(), repo.has_revisions(['foobar']))
87
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
88
        self.assertEquals(set([revid]), repo.has_revisions(['foobar', revid]))
89
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
90
    def test_get_revision(self):
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
91
        # GitRepository.get_revision gives a Revision object.
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
92
93
        # Create a git repository with a revision.
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
94
        GitRepo.init(self.test_dir)
0.200.902 by Jelmer Vernooij
Fix Repository.has_revision{s,}.
95
        commit_id = self._do_commit()
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
96
97
        # Get the corresponding Revision object.
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
98
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
99
        repo = Repository.open('.')
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
100
        rev = repo.get_revision(revid)
101
        self.assertIsInstance(rev, revision.Revision)
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
102
0.200.106 by Jelmer Vernooij
Test that getting an unknown revision fails.
103
    def test_get_revision_unknown(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
104
        GitRepo.init(self.test_dir)
0.200.106 by Jelmer Vernooij
Test that getting an unknown revision fails.
105
106
        repo = Repository.open('.')
107
        self.assertRaises(errors.NoSuchRevision, repo.get_revision, "bla")
108
0.200.79 by Jelmer Vernooij
Implement RevisionTree.get_revision_id().
109
    def simple_commit(self):
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
110
        # Create a git repository with some interesting files in a revision.
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
111
        GitRepo.init(self.test_dir)
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
112
        builder = tests.GitBranchBuilder()
113
        builder.set_file('data', 'text\n', False)
114
        builder.set_file('executable', 'content', True)
115
        builder.set_link('link', 'broken')
116
        builder.set_file('subdir/subfile', 'subdir text\n', False)
0.204.4 by James Westby
Make the inventory test match what the code produces.
117
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message',
118
            timestamp=1205433193)
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
119
        mapping = builder.finish()
0.200.79 by Jelmer Vernooij
Implement RevisionTree.get_revision_id().
120
        return mapping[commit_handle]
121
0.257.1 by Jelmer Vernooij
use transport repo objects even for local access.
122
    def test_pack(self):
123
        commit_id = self.simple_commit()
124
        repo = Repository.open('.')
125
        repo.pack()
126
0.200.79 by Jelmer Vernooij
Implement RevisionTree.get_revision_id().
127
    def test_revision_tree(self):
128
        commit_id = self.simple_commit()
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
129
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
130
        repo = Repository.open('.')
0.200.79 by Jelmer Vernooij
Implement RevisionTree.get_revision_id().
131
        tree = repo.revision_tree(revid)
132
        self.assertEquals(tree.get_revision_id(), revid)
0.200.1712 by Jelmer Vernooij
Add file_id prefix.
133
        self.assertEquals("text\n", tree.get_file_text("data"))
0.200.79 by Jelmer Vernooij
Implement RevisionTree.get_revision_id().
134
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
135
0.204.2 by James Westby
Switch to TestCaseWithTransport so that the cache dir can be
136
class TestGitRepository(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.
137
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
138
    def _do_commit(self):
139
        builder = tests.GitBranchBuilder()
140
        builder.set_file('a', 'text for a\n', False)
141
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
142
        mapping = builder.finish()
143
        return mapping[commit_handle]
144
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
145
    def setUp(self):
0.204.2 by James Westby
Switch to TestCaseWithTransport so that the cache dir can be
146
        tests.TestCaseWithTransport.setUp(self)
0.200.445 by Jelmer Vernooij
Import dulwich as dulwich, not as git.
147
        dulwich.repo.Repo.create(self.test_dir)
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
148
        self.git_repo = Repository.open(self.test_dir)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
149
0.200.40 by David Allouche
GitRepository.supports_rich_root() => False
150
    def test_supports_rich_root(self):
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
151
        repo = self.git_repo
0.200.131 by Jelmer Vernooij
Fix all tests but two, use rich roots by default.
152
        self.assertEqual(repo.supports_rich_root(), True)
0.200.40 by David Allouche
GitRepository.supports_rich_root() => False
153
0.200.60 by Jelmer Vernooij
Support signature functions.
154
    def test_get_signature_text(self):
0.200.61 by Jelmer Vernooij
Fix tests.
155
        self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
0.200.60 by Jelmer Vernooij
Support signature functions.
156
157
    def test_has_signature_for_revision_id(self):
158
        self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
159
0.200.75 by Jelmer Vernooij
Implement Repository.all_revision_ids().
160
    def test_all_revision_ids_none(self):
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
161
        self.assertEquals([], self.git_repo.all_revision_ids())
0.200.75 by Jelmer Vernooij
Implement Repository.all_revision_ids().
162
0.200.1282 by Jelmer Vernooij
Add tests for get_known_graph_ancestry.
163
    def test_get_known_graph_ancestry(self):
164
        cid = self._do_commit()
165
        revid = default_mapping.revision_id_foreign_to_bzr(cid)
166
        g = self.git_repo.get_known_graph_ancestry([revid])
167
        self.assertEquals(frozenset([revid]),
0.200.1329 by Jelmer Vernooij
Fix more tests.
168
            g.heads([revid]))
169
        self.assertEqual([(revid, 0, (1,), True)],
0.200.1284 by Jelmer Vernooij
Fix merge_sort test.
170
            [(n.key, n.merge_depth, n.revno, n.end_of_merge)
171
                 for n in g.merge_sort(revid)])
0.200.1282 by Jelmer Vernooij
Add tests for get_known_graph_ancestry.
172
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
173
    def test_all_revision_ids(self):
174
        commit_id = self._do_commit()
0.200.1030 by Jelmer Vernooij
More work on supporting roundtripping push.
175
        self.assertEquals(
0.200.1727 by Jelmer Vernooij
Change all_revision_ids type to list.
176
                [default_mapping.revision_id_foreign_to_bzr(commit_id)],
0.252.41 by Jelmer Vernooij
Fix Repository.all_revision_ids.
177
                self.git_repo.all_revision_ids())
178
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
179
    def assertIsNullInventory(self, inv):
180
        self.assertEqual(inv.root, None)
181
        self.assertEqual(inv.revision_id, revision.NULL_REVISION)
182
        self.assertEqual(list(inv.iter_entries()), [])
183
184
    def test_revision_tree_none(self):
185
        # GitRepository.revision_tree(None) returns the null tree.
186
        repo = self.git_repo
0.200.57 by Jelmer Vernooij
Fix more tests.
187
        tree = repo.revision_tree(revision.NULL_REVISION)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
188
        self.assertEqual(tree.get_revision_id(), revision.NULL_REVISION)
189
0.200.77 by Jelmer Vernooij
Handle NULL_REVISION in get_parent_map.
190
    def test_get_parent_map_null(self):
191
        self.assertEquals({revision.NULL_REVISION: ()}, 
192
                           self.git_repo.get_parent_map([revision.NULL_REVISION]))
193
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
194
195
class GitRepositoryFormat(tests.TestCase):
196
197
    def setUp(self):
198
        super(GitRepositoryFormat, self).setUp()
0.200.290 by Jelmer Vernooij
Fix tests.
199
        self.format = repository.GitRepositoryFormat()
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
200
201
    def test_get_format_description(self):
202
        self.assertEquals("Git Repository", self.format.get_format_description())
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
203
204
205
class RevisionGistImportTests(tests.TestCaseWithTransport):
206
207
    def setUp(self):
208
        tests.TestCaseWithTransport.setUp(self)
209
        self.git_path = os.path.join(self.test_dir, "git")
210
        os.mkdir(self.git_path)
0.200.445 by Jelmer Vernooij
Import dulwich as dulwich, not as git.
211
        dulwich.repo.Repo.create(self.git_path)
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
212
        self.git_repo = Repository.open(self.git_path)
213
        self.bzr_tree = self.make_branch_and_tree("bzr")
214
0.200.357 by Jelmer Vernooij
Move push code to push.py.
215
    def get_inter(self):
216
        return InterRepository.get(self.bzr_tree.branch.repository, 
217
                                   self.git_repo)
218
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
219
    def object_iter(self):
0.235.2 by Jelmer Vernooij
Fix tests.
220
        store = BazaarObjectStore(self.bzr_tree.branch.repository, default_mapping)
0.254.8 by Jelmer Vernooij
Fix tests.
221
        store_iterator = MissingObjectsIterator(store, self.bzr_tree.branch.repository)
222
        return store, store_iterator
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
223
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
224
    def import_rev(self, revid, parent_lookup=None):
0.254.8 by Jelmer Vernooij
Fix tests.
225
        store, store_iter = self.object_iter()
0.200.847 by Jelmer Vernooij
Add BzrGitCache object.
226
        store._cache.idmap.start_write_group()
0.254.8 by Jelmer Vernooij
Fix tests.
227
        try:
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
228
            return store_iter.import_revision(revid, lossy=True)
0.254.8 by Jelmer Vernooij
Fix tests.
229
        except:
0.200.847 by Jelmer Vernooij
Add BzrGitCache object.
230
            store._cache.idmap.abort_write_group()
0.254.8 by Jelmer Vernooij
Fix tests.
231
            raise
232
        else:
0.200.847 by Jelmer Vernooij
Add BzrGitCache object.
233
            store._cache.idmap.commit_write_group()
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
234
235
    def test_pointless(self):
0.200.257 by Jelmer Vernooij
Add more details for commit, to avoid checksum from changing.
236
        revid = self.bzr_tree.commit("pointless", timestamp=1205433193,
0.200.362 by Jelmer Vernooij
Fix tests.
237
                timezone=0,
0.200.257 by Jelmer Vernooij
Add more details for commit, to avoid checksum from changing.
238
                  committer="Jelmer Vernooij <jelmer@samba.org>")
0.200.443 by Jelmer Vernooij
Fix tests.
239
        self.assertEquals("2caa8094a5b794961cd9bf582e3e2bb090db0b14", 
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
240
                self.import_rev(revid))
0.200.443 by Jelmer Vernooij
Fix tests.
241
        self.assertEquals("2caa8094a5b794961cd9bf582e3e2bb090db0b14", 
0.200.256 by Jelmer Vernooij
Add tests for import_revision_gist.
242
                self.import_rev(revid))
0.200.658 by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib.
243
244
245
class ForeignTestsRepositoryFactory(object):
246
247
    def make_repository(self, transport):
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
248
        return dir.LocalGitControlDirFormat().initialize_on_transport(transport).open_repository()