/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/git/tests/test_repository.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    MissingObjectsIterator,
51
51
    )
52
52
 
 
53
 
53
54
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
54
55
    """Feature tests for GitRepository."""
55
56
 
116
117
        builder.set_symlink(b'link', b'broken')
117
118
        builder.set_file(b'subdir/subfile', b'subdir text\n', False)
118
119
        commit_handle = builder.commit(b'Joe Foo <joe@foo.com>', b'message',
119
 
            timestamp=1205433193)
 
120
                                       timestamp=1205433193)
120
121
        mapping = builder.finish()
121
122
        return mapping[commit_handle]
122
123
 
153
154
        self.assertEqual(repo.supports_rich_root(), True)
154
155
 
155
156
    def test_get_signature_text(self):
156
 
        self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
 
157
        self.assertRaises(
 
158
            errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
157
159
 
158
160
    def test_has_signature_for_revision_id(self):
159
 
        self.assertEqual(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
 
161
        self.assertEqual(False, self.git_repo.has_signature_for_revision_id(
 
162
            revision.NULL_REVISION))
160
163
 
161
164
    def test_all_revision_ids_none(self):
162
165
        self.assertEqual([], self.git_repo.all_revision_ids())
166
169
        revid = default_mapping.revision_id_foreign_to_bzr(cid)
167
170
        g = self.git_repo.get_known_graph_ancestry([revid])
168
171
        self.assertEqual(frozenset([revid]),
169
 
            g.heads([revid]))
 
172
                         g.heads([revid]))
170
173
        self.assertEqual([(revid, 0, (1,), True)],
171
 
            [(n.key, n.merge_depth, n.revno, n.end_of_merge)
172
 
                 for n in g.merge_sort(revid)])
 
174
                         [(n.key, n.merge_depth, n.revno, n.end_of_merge)
 
175
                          for n in g.merge_sort(revid)])
173
176
 
174
177
    def test_all_revision_ids(self):
175
178
        commit_id = self._do_commit()
176
179
        self.assertEqual(
177
 
                [default_mapping.revision_id_foreign_to_bzr(commit_id)],
178
 
                self.git_repo.all_revision_ids())
 
180
            [default_mapping.revision_id_foreign_to_bzr(commit_id)],
 
181
            self.git_repo.all_revision_ids())
179
182
 
180
183
    def assertIsNullInventory(self, inv):
181
184
        self.assertEqual(inv.root, None)
191
194
 
192
195
    def test_get_parent_map_null(self):
193
196
        self.assertEqual({revision.NULL_REVISION: ()},
194
 
                           self.git_repo.get_parent_map([revision.NULL_REVISION]))
 
197
                         self.git_repo.get_parent_map([revision.NULL_REVISION]))
195
198
 
196
199
 
197
200
class SigningGitRepository(tests.TestCaseWithTransport):
202
205
        wt = self.make_branch_and_tree('.', format='git')
203
206
        branch = wt.branch
204
207
        revid = wt.commit("base", allow_pointless=True)
205
 
        self.assertFalse(branch.repository.has_signature_for_revision_id(revid))
 
208
        self.assertFalse(
 
209
            branch.repository.has_signature_for_revision_id(revid))
206
210
        try:
207
211
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
208
212
            conf = config.MemoryStack(b'''
209
213
create_signatures=always
210
214
''')
211
 
            revid2 = wt.commit(config=conf, message="base", allow_pointless=True)
 
215
            revid2 = wt.commit(config=conf, message="base",
 
216
                               allow_pointless=True)
 
217
 
212
218
            def sign(text):
213
219
                return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
214
 
            self.assertIsInstance(branch.repository.get_signature_text(revid2), bytes)
 
220
            self.assertIsInstance(
 
221
                branch.repository.get_signature_text(revid2), bytes)
215
222
        finally:
216
223
            breezy.gpg.GPGStrategy = oldstrategy
217
224
 
218
225
 
 
226
class RevpropsRepository(tests.TestCaseWithTransport):
 
227
 
 
228
    def test_author(self):
 
229
        wt = self.make_branch_and_tree('.', format='git')
 
230
        revid = wt.commit(
 
231
            "base", allow_pointless=True,
 
232
            revprops={'author': 'Joe Example <joe@example.com>'})
 
233
        rev = wt.branch.repository.get_revision(revid)
 
234
        r = dulwich.repo.Repo('.')
 
235
        self.assertEqual(b'Joe Example <joe@example.com>', r[r.head()].author)
 
236
 
 
237
    def test_authors(self):
 
238
        wt = self.make_branch_and_tree('.', format='git')
 
239
        revid = wt.commit(
 
240
            "base", allow_pointless=True,
 
241
            revprops={'authors': 'Joe Example <joe@example.com>'})
 
242
        rev = wt.branch.repository.get_revision(revid)
 
243
        r = dulwich.repo.Repo('.')
 
244
        self.assertEqual(b'Joe Example <joe@example.com>', r[r.head()].author)
 
245
 
 
246
    def test_multiple_authors(self):
 
247
        wt = self.make_branch_and_tree('.', format='git')
 
248
        self.assertRaises(
 
249
            Exception, wt.commit, "base", allow_pointless=True,
 
250
            revprops={'authors': 'Joe Example <joe@example.com>\n'
 
251
                                 'Jane Doe <jane@example.com\n>'})
 
252
 
 
253
    def test_bugs(self):
 
254
        wt = self.make_branch_and_tree('.', format='git')
 
255
        revid = wt.commit(
 
256
            "base", allow_pointless=True,
 
257
            revprops={
 
258
                'bugs': 'https://github.com/jelmer/dulwich/issues/123 fixed\n'
 
259
                })
 
260
        rev = wt.branch.repository.get_revision(revid)
 
261
        r = dulwich.repo.Repo('.')
 
262
        self.assertEqual(
 
263
            b'base\n'
 
264
            b'Fixes: https://github.com/jelmer/dulwich/issues/123\n',
 
265
            r[r.head()].message)
 
266
 
 
267
 
219
268
class GitRepositoryFormat(tests.TestCase):
220
269
 
221
270
    def setUp(self):
224
273
 
225
274
    def test_get_format_description(self):
226
275
        self.assertEqual("Git Repository",
227
 
                          self.format.get_format_description())
 
276
                         self.format.get_format_description())
228
277
 
229
278
 
230
279
class RevisionGistImportTests(tests.TestCaseWithTransport):
242
291
                                   self.git_repo)
243
292
 
244
293
    def object_iter(self):
245
 
        store = BazaarObjectStore(self.bzr_tree.branch.repository, default_mapping)
246
 
        store_iterator = MissingObjectsIterator(store, self.bzr_tree.branch.repository)
 
294
        store = BazaarObjectStore(
 
295
            self.bzr_tree.branch.repository, default_mapping)
 
296
        store_iterator = MissingObjectsIterator(
 
297
            store, self.bzr_tree.branch.repository)
247
298
        return store, store_iterator
248
299
 
249
300
    def import_rev(self, revid, parent_lookup=None):
259
310
 
260
311
    def test_pointless(self):
261
312
        revid = self.bzr_tree.commit("pointless", timestamp=1205433193,
262
 
                timezone=0, committer="Jelmer Vernooij <jelmer@samba.org>")
263
 
        self.assertEqual(b"2caa8094a5b794961cd9bf582e3e2bb090db0b14",
264
 
                self.import_rev(revid))
265
 
        self.assertEqual(b"2caa8094a5b794961cd9bf582e3e2bb090db0b14",
266
 
                self.import_rev(revid))
 
313
                                     timezone=0, committer="Jelmer Vernooij <jelmer@samba.org>")
 
314
        self.assertEqual(b"2caa8094a5b794961cd9bf582e3e2bb090db0b14",
 
315
                         self.import_rev(revid))
 
316
        self.assertEqual(b"2caa8094a5b794961cd9bf582e3e2bb090db0b14",
 
317
                         self.import_rev(revid))
267
318
 
268
319
 
269
320
class ForeignTestsRepositoryFactory(object):