/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.967 by Jelmer Vernooij
Add initial test for push.
2
# -*- coding: utf-8 -*-
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.967 by Jelmer Vernooij
Add initial test for push.
17
18
"""Tests for pushing revisions from Bazaar into Git."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
22
from ....controldir import (
0.200.967 by Jelmer Vernooij
Add initial test for push.
23
    format_registry,
24
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from ....repository import (
0.200.967 by Jelmer Vernooij
Add initial test for push.
26
    InterRepository,
27
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
28
from ....tests import (
0.200.967 by Jelmer Vernooij
Add initial test for push.
29
    TestCaseWithTransport,
30
    )
31
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
32
from ..mapping import (
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
33
    BzrGitMappingExperimental,
34
    BzrGitMappingv1,
35
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
36
from ..errors import NoPushSupport
0.401.2 by Jelmer Vernooij
Move all InterRepository implementations into interrepo.
37
from ..interrepo import (
0.200.967 by Jelmer Vernooij
Add initial test for push.
38
    InterToGitRepository,
39
    )
40
41
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
42
class InterToGitRepositoryTests(TestCaseWithTransport):
0.200.967 by Jelmer Vernooij
Add initial test for push.
43
44
    def setUp(self):
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
45
        super(InterToGitRepositoryTests, self).setUp()
0.200.967 by Jelmer Vernooij
Add initial test for push.
46
        self.git_repo = self.make_repository("git",
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
47
                format=format_registry.make_controldir("git"))
0.273.1 by Jelmer Vernooij
add test for bug 818318.
48
        self.bzr_repo = self.make_repository("bzr", shared=True)
49
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
50
    def _get_interrepo(self, mapping=None):
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
51
        self.bzr_repo.lock_read()
52
        self.addCleanup(self.bzr_repo.unlock)
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
53
        interrepo = InterRepository.get(self.bzr_repo, self.git_repo)
54
        if mapping is not None:
55
            interrepo.mapping = mapping
56
        return interrepo
0.200.967 by Jelmer Vernooij
Add initial test for push.
57
58
    def test_instance(self):
0.273.1 by Jelmer Vernooij
add test for bug 818318.
59
        self.assertIsInstance(self._get_interrepo(), InterToGitRepository)
0.200.967 by Jelmer Vernooij
Add initial test for push.
60
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
61
    def test_pointless_fetch_refs_old_mapping(self):
62
        interrepo = self._get_interrepo(mapping=BzrGitMappingv1())
0.320.2 by Jelmer Vernooij
Only complain about roundtripping if revisions being pushed didn't originally come from git.
63
        interrepo.fetch_refs(lambda x: {}, lossy=False)
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
64
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
65
    def test_pointless_fetch_refs(self):
0.200.1509 by Jelmer Vernooij
Properly raise exception when pulling from git into bzr without experimental mappings.
66
        interrepo = self._get_interrepo(mapping=BzrGitMappingExperimental())
67
        revidmap, old_refs, new_refs = interrepo.fetch_refs(lambda x: {}, lossy=False)
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
68
        self.assertEquals(old_refs, {})
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
69
        self.assertEquals(new_refs, {})
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
70
0.200.1422 by Jelmer Vernooij
Remove unused dfetch method.
71
    def test_pointless_lossy_fetch_refs(self):
0.273.1 by Jelmer Vernooij
add test for bug 818318.
72
        revidmap, old_refs, new_refs = self._get_interrepo().fetch_refs(lambda x: {}, lossy=True)
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
73
        self.assertEquals(old_refs, {})
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
74
        self.assertEquals(new_refs, {})
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
75
        self.assertEquals(revidmap, {})
76
77
    def test_pointless_missing_revisions(self):
0.273.1 by Jelmer Vernooij
add test for bug 818318.
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([])))
0.200.968 by Jelmer Vernooij
Add more tests, simplify push code.
82
83
    def test_missing_revisions_unknown_stop_rev(self):
0.273.1 by Jelmer Vernooij
add test for bug 818318.
84
        interrepo = self._get_interrepo()
85
        interrepo.source_store.lock_read()
86
        self.addCleanup(interrepo.source_store.unlock)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
87
        self.assertEquals([],
0.273.1 by Jelmer Vernooij
add test for bug 818318.
88
                list(interrepo.missing_revisions([(None, "unknown")])))
89
90
    def test_odd_rename(self):
91
        # Add initial revision to bzr branch.
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
92
        branch = self.bzr_repo.controldir.create_branch()
93
        tree = branch.controldir.create_workingtree()
0.273.1 by Jelmer Vernooij
add test for bug 818318.
94
        self.build_tree(["bzr/bar/", "bzr/bar/foobar"])
95
        tree.add(["bar", "bar/foobar"])
96
        tree.commit("initial")
97
98
        # Add new directory and perform move in bzr branch.
99
        self.build_tree(["bzr/baz/"])
100
        tree.add(["baz"])
101
        tree.rename_one("bar", "baz/IrcDotNet")
102
        last_revid = tree.commit("rename")
103
104
        # Push bzr branch to git branch.
105
        def decide(x):
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]
113
        tree.check()
0.282.2 by William Grant
Always dirty both parents, fixing weird directory rename cases.
114
        self.assertTrue(tree["baz"][1] in store)
0.273.1 by Jelmer Vernooij
add test for bug 818318.
115
        baz = store[tree["baz"][1]]
116
        baz.check()
117
        ircdotnet = store[baz["IrcDotNet"][1]]
118
        ircdotnet.check()
119
        foobar = store[ircdotnet["foobar"][1]]
120
        foobar.check()