/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) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
2
# Copyright (C) 2007 Canonical Ltd
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.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
17
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
18
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
19
"""Tests for interfacing with a Git Branch"""
20
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
21
import dulwich
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
22
from dulwich.objects import (
23
    Commit,
24
    Tag,
25
    )
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
26
from dulwich.repo import (
27
    Repo as GitRepo,
28
    )
29
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
30
import os
31
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
32
from ... import (
7131.14.4 by Jelmer Vernooij
Fix test.
33
    errors,
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
34
    revision,
0.266.1 by Martin
Expect native-style file urls in branch object reprs
35
    urlutils,
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
36
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
37
from ...branch import (
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
38
    Branch,
0.247.1 by Michael Hudson
test
39
    InterBranch,
0.200.1660 by Jelmer Vernooij
Fix imports.
40
    UnstackableBranchFormat,
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
41
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
42
from ...controldir import (
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
43
    ControlDir,
0.200.1014 by Jelmer Vernooij
Fix tests.
44
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
45
from ...repository import (
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
46
    Repository,
47
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
48
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
49
from .. import (
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
50
    branch,
0.200.97 by Jelmer Vernooij
use mapping object.
51
    tests,
0.200.20 by John Arbash Meinel
All tests are passing again
52
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
53
from ..dir import (
0.200.1140 by Jelmer Vernooij
Update now that the control dir formats are no longer in __init__.
54
    LocalGitControlDirFormat,
55
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
56
from ..mapping import (
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
57
    default_mapping,
58
    )
0.200.123 by Jelmer Vernooij
Use central git module.
59
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
60
61
class TestGitBranch(tests.TestCaseInTempDir):
62
0.200.1361 by Jelmer Vernooij
Support branches where the ref can't be mapped back to a branch name.
63
    def test_open_by_ref(self):
64
        GitRepo.init('.')
0.200.1427 by Jelmer Vernooij
fix 2.3 and 2.4 compatibility.
65
        url = "%s,ref=%s" % (
0.200.1361 by Jelmer Vernooij
Support branches where the ref can't be mapped back to a branch name.
66
            urlutils.local_path_to_url(self.test_dir),
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
67
            urlutils.quote("refs/remotes/origin/unstable", safe='')
0.200.1427 by Jelmer Vernooij
fix 2.3 and 2.4 compatibility.
68
            )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
69
        d = ControlDir.open(url)
0.200.1361 by Jelmer Vernooij
Support branches where the ref can't be mapped back to a branch name.
70
        b = d.create_branch()
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
71
        self.assertEqual(b.ref, b"refs/remotes/origin/unstable")
0.200.1361 by Jelmer Vernooij
Support branches where the ref can't be mapped back to a branch name.
72
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
73
    def test_open_existing(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
74
        r = GitRepo.init('.')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
75
        d = ControlDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
76
        thebranch = d.create_branch()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
77
        self.assertIsInstance(thebranch, branch.GitBranch)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
78
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
79
    def test_repr(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
80
        r = GitRepo.init('.')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
81
        d = ControlDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
82
        thebranch = d.create_branch()
6964.2.3 by Jelmer Vernooij
Review comments.
83
        self.assertEqual(
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
84
            "<LocalGitBranch('%s/', %r)>" % (
85
                urlutils.local_path_to_url(self.test_dir),
86
                u'master'),
0.266.1 by Martin
Expect native-style file urls in branch object reprs
87
            repr(thebranch))
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
88
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
89
    def test_last_revision_is_null(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
90
        r = GitRepo.init('.')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
91
        thedir = ControlDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
92
        thebranch = thedir.create_branch()
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
93
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
94
        self.assertEqual((0, revision.NULL_REVISION),
95
                         thebranch.last_revision_info())
0.200.20 by John Arbash Meinel
All tests are passing again
96
0.200.82 by Jelmer Vernooij
Support listing tags.
97
    def simple_commit_a(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
98
        r = GitRepo.init('.')
0.200.82 by Jelmer Vernooij
Support listing tags.
99
        self.build_tree(['a'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
100
        r.stage(["a"])
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
101
        return r.do_commit(b"a", committer=b"Somebody <foo@example.com>")
0.200.82 by Jelmer Vernooij
Support listing tags.
102
0.200.20 by John Arbash Meinel
All tests are passing again
103
    def test_last_revision_is_valid(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
104
        head = self.simple_commit_a()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
105
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
106
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
0.200.20 by John Arbash Meinel
All tests are passing again
107
                         thebranch.last_revision())
0.200.58 by Jelmer Vernooij
Fix remaining tests.
108
0.200.1602 by Jelmer Vernooij
Remove Branch.revision_history.
109
    def test_last_revision_info(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
110
        reva = self.simple_commit_a()
0.200.59 by Jelmer Vernooij
Add more tests, fix revision history.
111
        self.build_tree(['b'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
112
        r = GitRepo(".")
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
113
        self.addCleanup(r.close)
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
114
        r.stage("b")
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
115
        revb = r.do_commit(b"b", committer=b"Somebody <foo@example.com>")
0.200.58 by Jelmer Vernooij
Fix remaining tests.
116
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
117
        thebranch = Branch.open('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
        self.assertEqual((2, default_mapping.revision_id_foreign_to_bzr(
119
            revb)), thebranch.last_revision_info())
0.200.82 by Jelmer Vernooij
Support listing tags.
120
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
121
    def test_tag_annotated(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
122
        reva = self.simple_commit_a()
123
        o = Tag()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
124
        o.name = b"foo"
125
        o.tagger = b"Jelmer <foo@example.com>"
126
        o.message = b"add tag"
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
127
        o.object = (Commit, reva)
128
        o.tag_timezone = 0
129
        o.tag_time = 42
130
        r = GitRepo(".")
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
131
        self.addCleanup(r.close)
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
132
        r.object_store.add_object(o)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
133
        r[b'refs/tags/foo'] = o.id
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
134
        thebranch = Branch.open('.')
6964.2.3 by Jelmer Vernooij
Review comments.
135
        self.assertEqual({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
7143.15.2 by Jelmer Vernooij
Run autopep8.
136
                         thebranch.tags.get_tag_dict())
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
137
138
    def test_tag(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
139
        reva = self.simple_commit_a()
140
        r = GitRepo(".")
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
141
        self.addCleanup(r.close)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
142
        r.refs[b"refs/tags/foo"] = reva
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
143
        thebranch = Branch.open('.')
6964.2.3 by Jelmer Vernooij
Review comments.
144
        self.assertEqual({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
7143.15.2 by Jelmer Vernooij
Run autopep8.
145
                         thebranch.tags.get_tag_dict())
0.200.956 by Jelmer Vernooij
Add some more format tests.
146
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
147
148
class TestWithGitBranch(tests.TestCaseWithTransport):
149
150
    def setUp(self):
151
        tests.TestCaseWithTransport.setUp(self)
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
152
        r = dulwich.repo.Repo.create(self.test_dir)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
153
        d = ControlDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
154
        self.git_branch = d.create_branch()
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
155
156
    def test_get_parent(self):
157
        self.assertIs(None, self.git_branch.get_parent())
0.200.67 by Jelmer Vernooij
Implement Branch.get_stacked_on_url.
158
159
    def test_get_stacked_on_url(self):
0.200.1660 by Jelmer Vernooij
Fix imports.
160
        self.assertRaises(UnstackableBranchFormat,
7143.15.2 by Jelmer Vernooij
Run autopep8.
161
                          self.git_branch.get_stacked_on_url)
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
162
0.200.72 by Jelmer Vernooij
Implement Branch.get_physical_lock_status.
163
    def test_get_physical_lock_status(self):
164
        self.assertFalse(self.git_branch.get_physical_lock_status())
165
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
166
0.295.1 by Jelmer Vernooij
Split up branch formats.
167
class TestLocalGitBranchFormat(tests.TestCase):
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
168
169
    def setUp(self):
0.295.1 by Jelmer Vernooij
Split up branch formats.
170
        super(TestLocalGitBranchFormat, self).setUp()
171
        self.format = branch.LocalGitBranchFormat()
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
172
173
    def test_get_format_description(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
174
        self.assertEqual("Local Git Branch",
175
                         self.format.get_format_description())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
176
0.200.956 by Jelmer Vernooij
Add some more format tests.
177
    def test_get_network_name(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
178
        self.assertEqual(b"git", self.format.network_name())
0.200.956 by Jelmer Vernooij
Add some more format tests.
179
180
    def test_supports_tags(self):
181
        self.assertTrue(self.format.supports_tags())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
182
183
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
184
class BranchTests(tests.TestCaseInTempDir):
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
185
186
    def make_onerev_branch(self):
187
        os.mkdir("d")
188
        os.chdir("d")
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
189
        GitRepo.init('.')
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
190
        bb = tests.GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
191
        bb.set_file("foobar", b"foo\nbar\n", False)
192
        mark = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
193
        gitsha = bb.finish()[mark]
194
        os.chdir("..")
0.200.1373 by Jelmer Vernooij
Prevent accidentally removing branch.
195
        return os.path.abspath("d"), gitsha
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
196
0.247.1 by Michael Hudson
test
197
    def make_tworev_branch(self):
198
        os.mkdir("d")
199
        os.chdir("d")
200
        GitRepo.init('.')
201
        bb = tests.GitBranchBuilder()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
202
        bb.set_file("foobar", b"foo\nbar\n", False)
203
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
204
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
0.247.1 by Michael Hudson
test
205
        marks = bb.finish()
206
        os.chdir("..")
207
        return "d", (marks[mark1], marks[mark2])
208
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
209
    def clone_git_branch(self, from_url, to_url):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
210
        from_dir = ControlDir.open(from_url)
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
211
        to_dir = from_dir.sprout(to_url)
212
        return to_dir.open_branch()
213
214
    def test_single_rev(self):
215
        path, gitsha = self.make_onerev_branch()
216
        oldrepo = Repository.open(path)
217
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
218
        self.assertEqual(gitsha, oldrepo._git.get_refs()[b"refs/heads/master"])
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
219
        newbranch = self.clone_git_branch(path, "f")
6964.2.3 by Jelmer Vernooij
Review comments.
220
        self.assertEqual([revid], newbranch.repository.all_revision_ids())
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
221
222
    def test_sprouted_tags(self):
223
        path, gitsha = self.make_onerev_branch()
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
224
        r = GitRepo(path)
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
225
        self.addCleanup(r.close)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
226
        r.refs[b"refs/tags/lala"] = r.head()
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
227
        oldrepo = Repository.open(path)
228
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
229
        newbranch = self.clone_git_branch(path, "f")
6964.2.3 by Jelmer Vernooij
Review comments.
230
        self.assertEqual({"lala": revid}, newbranch.tags.get_tag_dict())
231
        self.assertEqual([revid], newbranch.repository.all_revision_ids())
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
232
7240.2.1 by Jelmer Vernooij
Don't copy tags that don't point to valid objects.
233
    def test_sprouted_ghost_tags(self):
234
        path, gitsha = self.make_onerev_branch()
235
        r = GitRepo(path)
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
236
        self.addCleanup(r.close)
7240.2.1 by Jelmer Vernooij
Don't copy tags that don't point to valid objects.
237
        r.refs[b"refs/tags/lala"] = b"aa" * 20
238
        oldrepo = Repository.open(path)
239
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
240
        warnings, newbranch = self.callCatchWarnings(
241
            self.clone_git_branch, path, "f")
242
        self.assertEqual({}, newbranch.tags.get_tag_dict())
243
        # Dulwich raises a UserWarning for tags with invalid target
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
244
        self.assertIn(('ref refs/tags/lala points at non-present sha ' + ("aa" * 20), ), [w.args for w in warnings])
7240.2.1 by Jelmer Vernooij
Don't copy tags that don't point to valid objects.
245
7458.1.1 by Jelmer Vernooij
Support importing Git submodules as tree references.
246
    def test_interbranch_pull_submodule(self):
247
        path = "d"
248
        os.mkdir(path)
249
        os.chdir(path)
250
        GitRepo.init('.')
251
        bb = tests.GitBranchBuilder()
252
        bb.set_file("foobar", b"foo\nbar\n", False)
253
        mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
254
        bb.set_submodule("core", b'102ee7206ebc4227bec8ac02450972e6738f4a33')
255
        bb.set_file('.gitmodules', b"""\
256
[submodule "core"]
257
  path = core
258
  url = https://github.com/phhusson/QuasselC.git
259
""", False)
260
        mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
261
        marks = bb.finish()
262
        os.chdir("..")
263
        gitsha1 = marks[mark1]
264
        gitsha2 = marks[mark2]
265
        oldrepo = Repository.open(path)
266
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
267
        newbranch = self.make_branch('g')
268
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
269
        inter_branch.pull()
270
        self.assertEqual(revid2, newbranch.last_revision())
271
        self.assertEqual(
272
            ('https://github.com/phhusson/QuasselC.git', 'core'),
273
            newbranch.get_reference_info(newbranch.basis_tree().path2id('core')))
274
0.247.1 by Michael Hudson
test
275
    def test_interbranch_pull(self):
276
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
277
        oldrepo = Repository.open(path)
278
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
279
        newbranch = self.make_branch('g')
280
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
281
        inter_branch.pull()
6964.2.3 by Jelmer Vernooij
Review comments.
282
        self.assertEqual(revid2, newbranch.last_revision())
0.247.1 by Michael Hudson
test
283
0.247.5 by Michael Hudson
test and fix for noop pull case
284
    def test_interbranch_pull_noop(self):
285
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
286
        oldrepo = Repository.open(path)
287
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
288
        newbranch = self.make_branch('g')
289
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
290
        inter_branch.pull()
291
        # This is basically "assertNotRaises"
292
        inter_branch.pull()
6964.2.3 by Jelmer Vernooij
Review comments.
293
        self.assertEqual(revid2, newbranch.last_revision())
0.247.5 by Michael Hudson
test and fix for noop pull case
294
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
295
    def test_interbranch_pull_stop_revision(self):
296
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
297
        oldrepo = Repository.open(path)
298
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
299
        newbranch = self.make_branch('g')
300
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
301
        inter_branch.pull(stop_revision=revid1)
6964.2.3 by Jelmer Vernooij
Review comments.
302
        self.assertEqual(revid1, newbranch.last_revision())
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
303
0.259.8 by Jelmer Vernooij
Add test.
304
    def test_interbranch_pull_with_tags(self):
305
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
306
        gitrepo = GitRepo(path)
7288.2.2 by Jelmer Vernooij
Check for specific warning rather than total number of warnings.
307
        self.addCleanup(gitrepo.close)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
308
        gitrepo.refs[b"refs/tags/sometag"] = gitsha2
0.259.8 by Jelmer Vernooij
Add test.
309
        oldrepo = Repository.open(path)
310
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
311
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
312
        newbranch = self.make_branch('g')
0.200.1305 by Jelmer Vernooij
Only actually fetch tags if "branch.fetch_tags" is set to true.
313
        source_branch = Branch.open(path)
314
        source_branch.get_config().set_user_option("branch.fetch_tags", True)
315
        inter_branch = InterBranch.get(source_branch, newbranch)
0.259.8 by Jelmer Vernooij
Add test.
316
        inter_branch.pull(stop_revision=revid1)
6964.2.3 by Jelmer Vernooij
Review comments.
317
        self.assertEqual(revid1, newbranch.last_revision())
0.259.8 by Jelmer Vernooij
Add test.
318
        self.assertTrue(newbranch.repository.has_revision(revid2))
319
7131.14.1 by Jelmer Vernooij
Fix committing to a bzr branch bound to a git branch.
320
    def test_bzr_branch_bound_to_git(self):
321
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
7131.14.2 by Jelmer Vernooij
Make sure resulting branch is correct too.
322
        wt = Branch.open(path).create_checkout('co')
7131.14.1 by Jelmer Vernooij
Fix committing to a bzr branch bound to a git branch.
323
        self.build_tree_contents([('co/foobar', b'blah')])
7131.14.4 by Jelmer Vernooij
Fix test.
324
        self.assertRaises(
325
            errors.NoRoundtrippingSupport, wt.commit,
7131.14.1 by Jelmer Vernooij
Fix committing to a bzr branch bound to a git branch.
326
            'commit from bound branch.')
7131.14.2 by Jelmer Vernooij
Make sure resulting branch is correct too.
327
        revid = wt.commit('commit from bound branch.', lossy=True)
328
        self.assertEqual(revid, wt.branch.last_revision())
329
        self.assertEqual(
7131.14.4 by Jelmer Vernooij
Fix test.
330
            revid,
331
            wt.branch.get_master_branch().last_revision())
7131.14.1 by Jelmer Vernooij
Fix committing to a bzr branch bound to a git branch.
332
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
333
334
class ForeignTestsBranchFactory(object):
335
336
    def make_empty_branch(self, transport):
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
337
        d = LocalGitControlDirFormat().initialize_on_transport(transport)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
338
        return d.create_branch()
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
339
340
    make_branch = make_empty_branch