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

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

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 __future__ import absolute_import
 
21
 
 
22
from ....controldir import (
 
23
    format_registry,
 
24
    )
 
25
from ....repository import (
 
26
    InterRepository,
 
27
    )
 
28
from ....tests import (
 
29
    TestCaseWithTransport,
 
30
    )
 
31
 
 
32
from ..mapping import (
 
33
    BzrGitMappingExperimental,
 
34
    BzrGitMappingv1,
 
35
    )
 
36
from ..errors import NoPushSupport
 
37
from ..interrepo import (
 
38
    InterToGitRepository,
 
39
    )
 
40
 
 
41
 
 
42
class InterToGitRepositoryTests(TestCaseWithTransport):
 
43
 
 
44
    def setUp(self):
 
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)
 
49
 
 
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
 
56
        return interrepo
 
57
 
 
58
    def test_instance(self):
 
59
        self.assertIsInstance(self._get_interrepo(), InterToGitRepository)
 
60
 
 
61
    def test_pointless_fetch_refs_old_mapping(self):
 
62
        interrepo = self._get_interrepo(mapping=BzrGitMappingv1())
 
63
        interrepo.fetch_refs(lambda x: {}, lossy=False)
 
64
 
 
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, {})
 
70
 
 
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, {})
 
76
 
 
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([])))
 
82
 
 
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)
 
87
        self.assertEquals([],
 
88
                list(interrepo.missing_revisions([(None, "unknown")])))
 
89
 
 
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")
 
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()
 
114
        self.assertTrue(tree["baz"][1] in store)
 
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()