/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
1
# vim: expandtab
2
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
3
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
4
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
"""Tests for the git remote helper."""
20
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
21
from io import BytesIO
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
22
import os
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
23
import subprocess
7290.11.6 by Jelmer Vernooij
Use the same python executable as for brz.
24
import sys
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
25
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
26
from dulwich.repo import Repo
27
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
28
from ...tests import (
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
29
    TestCaseWithTransport,
30
    )
7290.11.4 by Jelmer Vernooij
Check whether git-remote-bzr actually exists.
31
from ...tests.features import PathFeature
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
32
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
33
from ..object_store import get_object_store
34
from ..git_remote_helper import (
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
35
    RemoteHelper,
36
    open_local_dir,
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
37
    fetch,
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
38
    )
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
39
7045.4.17 by Jelmer Vernooij
Fix tests.
40
from . import FastimportFeature
41
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
42
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
43
def map_to_git_sha1(dir, bzr_revid):
44
    object_store = get_object_store(dir.open_repository())
0.200.1788 by Jelmer Vernooij
Use context managers.
45
    with object_store.lock_read():
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
46
        return object_store._lookup_revision_sha1(bzr_revid)
47
48
7290.11.4 by Jelmer Vernooij
Check whether git-remote-bzr actually exists.
49
git_remote_bzr_path = os.path.abspath(
50
    os.path.join(os.path.dirname(__file__), '..', 'git-remote-bzr'))
51
git_remote_bzr_feature = PathFeature(git_remote_bzr_path)
52
53
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
54
class OpenLocalDirTests(TestCaseWithTransport):
55
56
    def test_from_env_dir(self):
57
        self.make_branch_and_tree('bla', format='git')
58
        self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git'))
59
        open_local_dir()
60
61
    def test_from_dir(self):
62
        self.make_branch_and_tree('.', format='git')
63
        open_local_dir()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
64
65
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
66
class FetchTests(TestCaseWithTransport):
67
68
    def setUp(self):
69
        super(FetchTests, self).setUp()
7143.15.2 by Jelmer Vernooij
Run autopep8.
70
        self.local_dir = self.make_branch_and_tree(
71
            'local', format='git').controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
72
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
73
        self.remote_dir = self.remote_tree.controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
74
        self.shortname = 'bzr'
75
76
    def fetch(self, wants):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
77
        outf = BytesIO()
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
78
        fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir)
79
        return outf.getvalue()
80
81
    def test_no_wants(self):
82
        r = self.fetch([])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
83
        self.assertEqual(b"\n", r)
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
84
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
85
    def test_simple(self):
86
        self.build_tree(['remote/foo'])
87
        self.remote_tree.add("foo")
88
        revid = self.remote_tree.commit("msg")
89
        git_sha1 = map_to_git_sha1(self.remote_dir, revid)
90
        out = self.fetch([(git_sha1, 'HEAD')])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
91
        self.assertEqual(out, b"\n")
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
92
        r = Repo('local')
93
        self.assertTrue(git_sha1 in r.object_store)
7290.11.5 by Jelmer Vernooij
don't check for import, fastimport may not be installed.
94
        self.assertEqual({}, r.get_refs())
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
95
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
96
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
97
class ExecuteRemoteHelperTests(TestCaseWithTransport):
98
99
    def test_run(self):
7290.11.4 by Jelmer Vernooij
Check whether git-remote-bzr actually exists.
100
        self.requireFeature(git_remote_bzr_feature)
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
101
        local_dir = self.make_branch_and_tree('local', format='git').controldir
102
        local_path = local_dir.control_transport.local_abspath('.')
103
        remote_tree = self.make_branch_and_tree('remote')
104
        remote_dir = remote_tree.controldir
105
        shortname = 'bzr'
106
        env = dict(os.environ)
107
        env['GIT_DIR'] = local_path
7290.11.7 by Jelmer Vernooij
Set PYTHONPATH.
108
        env['PYTHONPATH'] = ':'.join(sys.path)
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
109
        p = subprocess.Popen(
7290.11.6 by Jelmer Vernooij
Use the same python executable as for brz.
110
            [sys.executable, git_remote_bzr_path, local_path, remote_dir.user_url],
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
111
            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
112
            stderr=subprocess.PIPE, env=env)
113
        (out, err) = p.communicate(b'capabilities\n')
114
        lines = out.splitlines()
7290.11.5 by Jelmer Vernooij
don't check for import, fastimport may not be installed.
115
        self.assertIn(b'push', lines, "no 'push' in %r, error: %r" % (lines, err))
7490.57.2 by Jelmer Vernooij
Fix test.
116
        self.assertEqual(
117
            b"git-remote-bzr is experimental and has not been optimized "
118
            b"for performance. Use 'brz fast-export' and 'git fast-import' "
119
            b"for large repositories.\n", err)
7290.11.3 by Jelmer Vernooij
Add test for remote helper.
120
121
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
122
class RemoteHelperTests(TestCaseWithTransport):
123
124
    def setUp(self):
125
        super(RemoteHelperTests, self).setUp()
7143.15.2 by Jelmer Vernooij
Run autopep8.
126
        self.local_dir = self.make_branch_and_tree(
127
            'local', format='git').controldir
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
128
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
129
        self.remote_dir = self.remote_tree.controldir
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
130
        self.shortname = 'bzr'
7143.15.2 by Jelmer Vernooij
Run autopep8.
131
        self.helper = RemoteHelper(
132
            self.local_dir, self.shortname, self.remote_dir)
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
133
134
    def test_capabilities(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
135
        f = BytesIO()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
136
        self.helper.cmd_capabilities(f, [])
137
        capabs = f.getvalue()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
138
        base = b"fetch\noption\npush\n"
7463.3.8 by Jelmer Vernooij
Fix test.
139
        self.assertTrue(capabs in (base + b"\n", base + b"import\nrefspec *:*\n\n"), capabs)
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
140
141
    def test_option(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
142
        f = BytesIO()
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
143
        self.helper.cmd_option(f, [])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
144
        self.assertEqual(b"unsupported\n", f.getvalue())
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
145
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
146
    def test_list_basic(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
147
        f = BytesIO()
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
148
        self.helper.cmd_list(f, [])
6964.2.3 by Jelmer Vernooij
Review comments.
149
        self.assertEqual(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
150
            b'\n',
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
151
            f.getvalue())
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
152
153
    def test_import(self):
7045.4.17 by Jelmer Vernooij
Fix tests.
154
        self.requireFeature(FastimportFeature)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
155
        self.build_tree_contents([("remote/afile", b"somecontent")])
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
156
        self.remote_tree.add(["afile"])
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
157
        self.remote_tree.commit(b"A commit message", timestamp=1330445983,
7143.15.2 by Jelmer Vernooij
Run autopep8.
158
                                timezone=0, committer=b'Somebody <jrandom@example.com>')
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
159
        f = BytesIO()
7027.5.2 by Jelmer Vernooij
Fix some more git tests.
160
        self.helper.cmd_import(f, ["import", "refs/heads/master"])
6964.2.3 by Jelmer Vernooij
Review comments.
161
        self.assertEqual(
7194.1.3 by Jelmer Vernooij
Fix test.
162
            b'reset refs/heads/master\n'
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
163
            b'commit refs/heads/master\n'
164
            b'mark :1\n'
165
            b'committer Somebody <jrandom@example.com> 1330445983 +0000\n'
166
            b'data 16\n'
167
            b'A commit message\n'
168
            b'M 644 inline afile\n'
169
            b'data 11\n'
170
            b'somecontent\n',
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
171
            f.getvalue())