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