/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_push.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
"""Tests for pushing revisions from Bazaar into Git."""
 
19
 
 
20
from ...controldir import (
 
21
    format_registry,
 
22
    )
 
23
from ...repository import (
 
24
    InterRepository,
 
25
    )
 
26
from ...tests import (
 
27
    TestCaseWithTransport,
 
28
    )
 
29
 
 
30
from ..mapping import (
 
31
    BzrGitMappingExperimental,
 
32
    BzrGitMappingv1,
 
33
    )
 
34
from ..interrepo import (
 
35
    InterToGitRepository,
 
36
    )
 
37
 
 
38
 
 
39
class InterToGitRepositoryTests(TestCaseWithTransport):
 
40
 
 
41
    def setUp(self):
 
42
        super(InterToGitRepositoryTests, self).setUp()
 
43
        self.git_repo = self.make_repository("git",
 
44
                                             format=format_registry.make_controldir("git"))
 
45
        self.bzr_repo = self.make_repository("bzr", shared=True)
 
46
 
 
47
    def _get_interrepo(self, mapping=None):
 
48
        self.bzr_repo.lock_read()
 
49
        self.addCleanup(self.bzr_repo.unlock)
 
50
        interrepo = InterRepository.get(self.bzr_repo, self.git_repo)
 
51
        if mapping is not None:
 
52
            interrepo.mapping = mapping
 
53
        return interrepo
 
54
 
 
55
    def test_instance(self):
 
56
        self.assertIsInstance(self._get_interrepo(), InterToGitRepository)
 
57
 
 
58
    def test_pointless_fetch_refs_old_mapping(self):
 
59
        interrepo = self._get_interrepo(mapping=BzrGitMappingv1())
 
60
        interrepo.fetch_refs(lambda x: {}, lossy=False)
 
61
 
 
62
    def test_pointless_fetch_refs(self):
 
63
        interrepo = self._get_interrepo(mapping=BzrGitMappingExperimental())
 
64
        revidmap, old_refs, new_refs = interrepo.fetch_refs(
 
65
            lambda x: {}, lossy=False)
 
66
        self.assertEqual(old_refs, {b'HEAD': (
 
67
            b'ref: refs/heads/master', None)})
 
68
        self.assertEqual(new_refs, {})
 
69
 
 
70
    def test_pointless_lossy_fetch_refs(self):
 
71
        revidmap, old_refs, new_refs = self._get_interrepo(
 
72
        ).fetch_refs(lambda x: {}, lossy=True)
 
73
        self.assertEqual(old_refs, {b'HEAD': (
 
74
            b'ref: refs/heads/master', None)})
 
75
        self.assertEqual(new_refs, {})
 
76
        self.assertEqual(revidmap, {})
 
77
 
 
78
    def test_pointless_missing_revisions(self):
 
79
        interrepo = self._get_interrepo()
 
80
        interrepo.source_store.lock_read()
 
81
        self.addCleanup(interrepo.source_store.unlock)
 
82
        self.assertEqual([], list(interrepo.missing_revisions([])))
 
83
 
 
84
    def test_missing_revisions_unknown_stop_rev(self):
 
85
        interrepo = self._get_interrepo()
 
86
        interrepo.source_store.lock_read()
 
87
        self.addCleanup(interrepo.source_store.unlock)
 
88
        self.assertEqual([],
 
89
                         list(interrepo.missing_revisions([(None, b"unknown")])))
 
90
 
 
91
    def test_odd_rename(self):
 
92
        # Add initial revision to bzr branch.
 
93
        branch = self.bzr_repo.controldir.create_branch()
 
94
        tree = branch.controldir.create_workingtree()
 
95
        self.build_tree(["bzr/bar/", "bzr/bar/foobar"])
 
96
        tree.add(["bar", "bar/foobar"])
 
97
        tree.commit("initial")
 
98
 
 
99
        # Add new directory and perform move in bzr branch.
 
100
        self.build_tree(["bzr/baz/"])
 
101
        tree.add(["baz"])
 
102
        tree.rename_one("bar", "baz/IrcDotNet")
 
103
        last_revid = tree.commit("rename")
 
104
 
 
105
        # Push bzr branch to git branch.
 
106
        def decide(x):
 
107
            return {b"refs/heads/master": (None, last_revid)}
 
108
        interrepo = self._get_interrepo()
 
109
        revidmap, old_refs, new_refs = interrepo.fetch_refs(decide, lossy=True)
 
110
        gitid = revidmap[last_revid][0]
 
111
        store = self.git_repo._git.object_store
 
112
        commit = store[gitid]
 
113
        tree = store[commit.tree]
 
114
        tree.check()
 
115
        self.assertIn(b"baz", tree, repr(tree.items()))
 
116
        self.assertIn(tree[b"baz"][1], store)
 
117
        baz = store[tree[b"baz"][1]]
 
118
        baz.check()
 
119
        ircdotnet = store[baz[b"IrcDotNet"][1]]
 
120
        ircdotnet.check()
 
121
        foobar = store[ircdotnet[b"foobar"][1]]
 
122
        foobar.check()