1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
# -*- coding: utf-8 -*-
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.
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.
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests for pushing revisions from Bazaar into Git."""
20
from __future__ import absolute_import
22
from ....controldir import (
25
from ....repository import (
28
from ....tests import (
29
TestCaseWithTransport,
32
from ..mapping import (
33
BzrGitMappingExperimental,
36
from ..errors import NoPushSupport
37
from ..interrepo import (
42
class InterToGitRepositoryTests(TestCaseWithTransport):
45
super(InterToGitRepositoryTests, self).setUp()
46
self.git_repo = self.make_repository("git",
47
format=format_registry.make_controldir("git"))
48
self.bzr_repo = self.make_repository("bzr", shared=True)
50
def _get_interrepo(self, mapping=None):
51
self.bzr_repo.lock_read()
52
self.addCleanup(self.bzr_repo.unlock)
53
interrepo = InterRepository.get(self.bzr_repo, self.git_repo)
54
if mapping is not None:
55
interrepo.mapping = mapping
58
def test_instance(self):
59
self.assertIsInstance(self._get_interrepo(), InterToGitRepository)
61
def test_pointless_fetch_refs_old_mapping(self):
62
interrepo = self._get_interrepo(mapping=BzrGitMappingv1())
63
interrepo.fetch_refs(lambda x: {}, lossy=False)
65
def test_pointless_fetch_refs(self):
66
interrepo = self._get_interrepo(mapping=BzrGitMappingExperimental())
67
revidmap, old_refs, new_refs = interrepo.fetch_refs(lambda x: {}, lossy=False)
68
self.assertEquals(old_refs, {})
69
self.assertEquals(new_refs, {})
71
def test_pointless_lossy_fetch_refs(self):
72
revidmap, old_refs, new_refs = self._get_interrepo().fetch_refs(lambda x: {}, lossy=True)
73
self.assertEquals(old_refs, {})
74
self.assertEquals(new_refs, {})
75
self.assertEquals(revidmap, {})
77
def test_pointless_missing_revisions(self):
78
interrepo = self._get_interrepo()
79
interrepo.source_store.lock_read()
80
self.addCleanup(interrepo.source_store.unlock)
81
self.assertEquals([], list(interrepo.missing_revisions([])))
83
def test_missing_revisions_unknown_stop_rev(self):
84
interrepo = self._get_interrepo()
85
interrepo.source_store.lock_read()
86
self.addCleanup(interrepo.source_store.unlock)
88
list(interrepo.missing_revisions([(None, "unknown")])))
90
def test_odd_rename(self):
91
# Add initial revision to bzr branch.
92
branch = self.bzr_repo.controldir.create_branch()
93
tree = branch.controldir.create_workingtree()
94
self.build_tree(["bzr/bar/", "bzr/bar/foobar"])
95
tree.add(["bar", "bar/foobar"])
96
tree.commit("initial")
98
# Add new directory and perform move in bzr branch.
99
self.build_tree(["bzr/baz/"])
101
tree.rename_one("bar", "baz/IrcDotNet")
102
last_revid = tree.commit("rename")
104
# Push bzr branch to git branch.
106
return { "refs/heads/master": (None, last_revid) }
107
interrepo = self._get_interrepo()
108
revidmap, old_refs, new_refs = interrepo.fetch_refs(decide, lossy=True)
109
gitid = revidmap[last_revid][0]
110
store = self.git_repo._git.object_store
111
commit = store[gitid]
112
tree = store[commit.tree]
114
self.assertTrue(tree["baz"][1] in store)
115
baz = store[tree["baz"][1]]
117
ircdotnet = store[baz["IrcDotNet"][1]]
119
foobar = store[ircdotnet["foobar"][1]]