/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
17
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
18
"""Tests for interfacing with a Git Branch"""
19
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
20
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
32
from bzrlib import (
0.200.633 by Jelmer Vernooij
Fix Branch.get_stacked_on_url() test.
33
    errors,
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
34
    revision,
35
    )
36
from bzrlib.branch import (
37
    Branch,
0.247.1 by Michael Hudson
test
38
    InterBranch,
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
39
    )
0.200.1014 by Jelmer Vernooij
Fix tests.
40
from bzrlib.bzrdir import (
41
    BzrDir,
42
    )
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
43
from bzrlib.repository import (
44
    Repository,
45
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
46
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
47
from bzrlib.plugins.git import (
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
48
    LocalGitControlDirFormat,
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
49
    branch,
0.200.97 by Jelmer Vernooij
use mapping object.
50
    tests,
0.200.20 by John Arbash Meinel
All tests are passing again
51
    )
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
52
from bzrlib.plugins.git.mapping import (
53
    default_mapping,
54
    )
0.200.123 by Jelmer Vernooij
Use central git module.
55
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
56
57
class TestGitBranch(tests.TestCaseInTempDir):
58
59
    def test_open_existing(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
60
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
61
        d = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
62
        thebranch = d.create_branch()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
63
        self.assertIsInstance(thebranch, branch.GitBranch)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
64
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
65
    def test_repr(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
66
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
67
        d = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
68
        thebranch = d.create_branch()
0.200.920 by Jelmer Vernooij
Fix some more tests.
69
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
70
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
71
    def test_last_revision_is_null(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
72
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
73
        thedir = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
74
        thebranch = thedir.create_branch()
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
75
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
76
        self.assertEqual((0, revision.NULL_REVISION),
77
                         thebranch.last_revision_info())
0.200.20 by John Arbash Meinel
All tests are passing again
78
0.200.82 by Jelmer Vernooij
Support listing tags.
79
    def simple_commit_a(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
80
        r = GitRepo.init('.')
0.200.82 by Jelmer Vernooij
Support listing tags.
81
        self.build_tree(['a'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
82
        r.stage(["a"])
83
        return r.do_commit("a", committer="Somebody <foo@example.com>")
0.200.82 by Jelmer Vernooij
Support listing tags.
84
0.200.20 by John Arbash Meinel
All tests are passing again
85
    def test_last_revision_is_valid(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
86
        head = self.simple_commit_a()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
87
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
88
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
0.200.20 by John Arbash Meinel
All tests are passing again
89
                         thebranch.last_revision())
0.200.58 by Jelmer Vernooij
Fix remaining tests.
90
91
    def test_revision_history(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
92
        reva = self.simple_commit_a()
0.200.59 by Jelmer Vernooij
Add more tests, fix revision history.
93
        self.build_tree(['b'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
94
        r = GitRepo(".")
95
        r.stage("b")
96
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
0.200.58 by Jelmer Vernooij
Fix remaining tests.
97
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
98
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
99
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
0.200.58 by Jelmer Vernooij
Fix remaining tests.
100
                         thebranch.revision_history())
0.200.82 by Jelmer Vernooij
Support listing tags.
101
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
102
    def test_tag_annotated(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
103
        reva = self.simple_commit_a()
104
        o = Tag()
105
        o.name = "foo"
106
        o.tagger = "Jelmer <foo@example.com>"
107
        o.message = "add tag"
108
        o.object = (Commit, reva)
109
        o.tag_timezone = 0
110
        o.tag_time = 42
111
        r = GitRepo(".")
112
        r.object_store.add_object(o)
113
        r['refs/tags/foo'] = o.id
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
114
        thebranch = Branch.open('.')
115
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
                          thebranch.tags.get_tag_dict())
117
118
    def test_tag(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
119
        reva = self.simple_commit_a()
120
        r = GitRepo(".")
121
        r.refs["refs/tags/foo"] = reva
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
122
        thebranch = Branch.open('.')
123
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
124
                          thebranch.tags.get_tag_dict())
125
0.200.956 by Jelmer Vernooij
Add some more format tests.
126
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
127
128
class TestWithGitBranch(tests.TestCaseWithTransport):
129
130
    def setUp(self):
131
        tests.TestCaseWithTransport.setUp(self)
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
132
        dulwich.repo.Repo.create(self.test_dir)
0.200.1014 by Jelmer Vernooij
Fix tests.
133
        d = BzrDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
134
        self.git_branch = d.create_branch()
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
135
136
    def test_get_parent(self):
137
        self.assertIs(None, self.git_branch.get_parent())
0.200.67 by Jelmer Vernooij
Implement Branch.get_stacked_on_url.
138
139
    def test_get_stacked_on_url(self):
0.200.956 by Jelmer Vernooij
Add some more format tests.
140
        self.assertRaises(errors.UnstackableBranchFormat,
0.200.633 by Jelmer Vernooij
Fix Branch.get_stacked_on_url() test.
141
            self.git_branch.get_stacked_on_url)
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
142
0.200.72 by Jelmer Vernooij
Implement Branch.get_physical_lock_status.
143
    def test_get_physical_lock_status(self):
144
        self.assertFalse(self.git_branch.get_physical_lock_status())
145
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
146
147
class TestGitBranchFormat(tests.TestCase):
148
149
    def setUp(self):
150
        super(TestGitBranchFormat, self).setUp()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
151
        self.format = branch.GitBranchFormat()
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
152
153
    def test_get_format_description(self):
154
        self.assertEquals("Git Branch", self.format.get_format_description())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
155
0.200.956 by Jelmer Vernooij
Add some more format tests.
156
    def test_get_network_name(self):
157
        self.assertEquals("git", self.format.network_name())
158
159
    def test_supports_tags(self):
160
        self.assertTrue(self.format.supports_tags())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
161
162
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
163
class BranchTests(tests.TestCaseInTempDir):
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
164
165
    def make_onerev_branch(self):
166
        os.mkdir("d")
167
        os.chdir("d")
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
168
        GitRepo.init('.')
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
169
        bb = tests.GitBranchBuilder()
170
        bb.set_file("foobar", "foo\nbar\n", False)
171
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
172
        gitsha = bb.finish()[mark]
173
        os.chdir("..")
174
        return "d", gitsha
175
0.247.1 by Michael Hudson
test
176
    def make_tworev_branch(self):
177
        os.mkdir("d")
178
        os.chdir("d")
179
        GitRepo.init('.')
180
        bb = tests.GitBranchBuilder()
181
        bb.set_file("foobar", "foo\nbar\n", False)
182
        mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
183
        mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
184
        marks = bb.finish()
185
        os.chdir("..")
186
        return "d", (marks[mark1], marks[mark2])
187
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
188
    def clone_git_branch(self, from_url, to_url):
0.200.1014 by Jelmer Vernooij
Fix tests.
189
        from_dir = BzrDir.open(from_url)
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
190
        to_dir = from_dir.sprout(to_url)
191
        return to_dir.open_branch()
192
193
    def test_single_rev(self):
194
        path, gitsha = self.make_onerev_branch()
195
        oldrepo = Repository.open(path)
196
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
197
        newbranch = self.clone_git_branch(path, "f")
198
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
199
200
    def test_sprouted_tags(self):
201
        path, gitsha = self.make_onerev_branch()
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
202
        r = GitRepo(path)
203
        r.refs["refs/tags/lala"] = r.head()
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
204
        oldrepo = Repository.open(path)
205
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
206
        newbranch = self.clone_git_branch(path, "f")
207
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
208
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
209
0.247.1 by Michael Hudson
test
210
    def test_interbranch_pull(self):
211
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
212
        oldrepo = Repository.open(path)
213
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
214
        newbranch = self.make_branch('g')
215
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
216
        inter_branch.pull()
217
        self.assertEquals(revid2, newbranch.last_revision())
218
0.247.5 by Michael Hudson
test and fix for noop pull case
219
    def test_interbranch_pull_noop(self):
220
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
221
        oldrepo = Repository.open(path)
222
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
223
        newbranch = self.make_branch('g')
224
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
225
        inter_branch.pull()
226
        # This is basically "assertNotRaises"
227
        inter_branch.pull()
228
        self.assertEquals(revid2, newbranch.last_revision())
229
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
230
    def test_interbranch_pull_stop_revision(self):
231
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
232
        oldrepo = Repository.open(path)
233
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
234
        newbranch = self.make_branch('g')
235
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
236
        inter_branch.pull(stop_revision=revid1)
237
        self.assertEquals(revid1, newbranch.last_revision())
238
0.247.1 by Michael Hudson
test
239
    def test_interbranch_limited_pull(self):
240
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
241
        oldrepo = Repository.open(path)
242
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
        newbranch = self.make_branch('g')
245
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
        inter_branch.pull(limit=1)
247
        self.assertEquals(revid1, newbranch.last_revision())
248
        inter_branch.pull(limit=1)
249
        self.assertEquals(revid2, newbranch.last_revision())
250
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
251
252
class ForeignTestsBranchFactory(object):
253
254
    def make_empty_branch(self, transport):
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
255
        d = LocalGitControlDirFormat().initialize_on_transport(transport)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
256
        return d.create_branch()
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
257
258
    make_branch = make_empty_branch
0.200.770 by Jelmer Vernooij
Proper branch names.
259
260
0.200.833 by Jelmer Vernooij
Fix handling of remote branches.
261