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