/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.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
48
    branch,
0.200.97 by Jelmer Vernooij
use mapping object.
49
    tests,
0.200.20 by John Arbash Meinel
All tests are passing again
50
    )
0.200.1140 by Jelmer Vernooij
Update now that the control dir formats are no longer in __init__.
51
from bzrlib.plugins.git.dir import (
52
    LocalGitControlDirFormat,
53
    )
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
54
from bzrlib.plugins.git.mapping import (
55
    default_mapping,
56
    )
0.200.123 by Jelmer Vernooij
Use central git module.
57
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
58
59
class TestGitBranch(tests.TestCaseInTempDir):
60
61
    def test_open_existing(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
62
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
63
        d = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
64
        thebranch = d.create_branch()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
65
        self.assertIsInstance(thebranch, branch.GitBranch)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
66
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
67
    def test_repr(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
68
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
69
        d = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
70
        thebranch = d.create_branch()
0.200.920 by Jelmer Vernooij
Fix some more tests.
71
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
72
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
73
    def test_last_revision_is_null(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
74
        GitRepo.init('.')
0.200.1014 by Jelmer Vernooij
Fix tests.
75
        thedir = BzrDir.open('.')
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
76
        thebranch = thedir.create_branch()
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
77
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
78
        self.assertEqual((0, revision.NULL_REVISION),
79
                         thebranch.last_revision_info())
0.200.20 by John Arbash Meinel
All tests are passing again
80
0.200.82 by Jelmer Vernooij
Support listing tags.
81
    def simple_commit_a(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
82
        r = GitRepo.init('.')
0.200.82 by Jelmer Vernooij
Support listing tags.
83
        self.build_tree(['a'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
84
        r.stage(["a"])
85
        return r.do_commit("a", committer="Somebody <foo@example.com>")
0.200.82 by Jelmer Vernooij
Support listing tags.
86
0.200.20 by John Arbash Meinel
All tests are passing again
87
    def test_last_revision_is_valid(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
88
        head = self.simple_commit_a()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
89
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
90
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
0.200.20 by John Arbash Meinel
All tests are passing again
91
                         thebranch.last_revision())
0.200.58 by Jelmer Vernooij
Fix remaining tests.
92
93
    def test_revision_history(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
94
        reva = self.simple_commit_a()
0.200.59 by Jelmer Vernooij
Add more tests, fix revision history.
95
        self.build_tree(['b'])
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
96
        r = GitRepo(".")
97
        r.stage("b")
98
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
0.200.58 by Jelmer Vernooij
Fix remaining tests.
99
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
100
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
101
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
0.200.58 by Jelmer Vernooij
Fix remaining tests.
102
                         thebranch.revision_history())
0.200.82 by Jelmer Vernooij
Support listing tags.
103
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
104
    def test_tag_annotated(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
105
        reva = self.simple_commit_a()
106
        o = Tag()
107
        o.name = "foo"
108
        o.tagger = "Jelmer <foo@example.com>"
109
        o.message = "add tag"
110
        o.object = (Commit, reva)
111
        o.tag_timezone = 0
112
        o.tag_time = 42
113
        r = GitRepo(".")
114
        r.object_store.add_object(o)
115
        r['refs/tags/foo'] = o.id
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
116
        thebranch = Branch.open('.')
117
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
118
                          thebranch.tags.get_tag_dict())
119
120
    def test_tag(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
121
        reva = self.simple_commit_a()
122
        r = GitRepo(".")
123
        r.refs["refs/tags/foo"] = reva
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
124
        thebranch = Branch.open('.')
125
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
126
                          thebranch.tags.get_tag_dict())
127
0.200.956 by Jelmer Vernooij
Add some more format tests.
128
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
129
130
class TestWithGitBranch(tests.TestCaseWithTransport):
131
132
    def setUp(self):
133
        tests.TestCaseWithTransport.setUp(self)
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
134
        dulwich.repo.Repo.create(self.test_dir)
0.200.1014 by Jelmer Vernooij
Fix tests.
135
        d = BzrDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
136
        self.git_branch = d.create_branch()
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
137
138
    def test_get_parent(self):
139
        self.assertIs(None, self.git_branch.get_parent())
0.200.67 by Jelmer Vernooij
Implement Branch.get_stacked_on_url.
140
141
    def test_get_stacked_on_url(self):
0.200.956 by Jelmer Vernooij
Add some more format tests.
142
        self.assertRaises(errors.UnstackableBranchFormat,
0.200.633 by Jelmer Vernooij
Fix Branch.get_stacked_on_url() test.
143
            self.git_branch.get_stacked_on_url)
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
144
0.200.72 by Jelmer Vernooij
Implement Branch.get_physical_lock_status.
145
    def test_get_physical_lock_status(self):
146
        self.assertFalse(self.git_branch.get_physical_lock_status())
147
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
148
149
class TestGitBranchFormat(tests.TestCase):
150
151
    def setUp(self):
152
        super(TestGitBranchFormat, self).setUp()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
153
        self.format = branch.GitBranchFormat()
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
154
155
    def test_get_format_description(self):
156
        self.assertEquals("Git Branch", self.format.get_format_description())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
157
0.200.956 by Jelmer Vernooij
Add some more format tests.
158
    def test_get_network_name(self):
159
        self.assertEquals("git", self.format.network_name())
160
161
    def test_supports_tags(self):
162
        self.assertTrue(self.format.supports_tags())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
163
164
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
165
class BranchTests(tests.TestCaseInTempDir):
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
166
167
    def make_onerev_branch(self):
168
        os.mkdir("d")
169
        os.chdir("d")
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
170
        GitRepo.init('.')
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
171
        bb = tests.GitBranchBuilder()
172
        bb.set_file("foobar", "foo\nbar\n", False)
173
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
174
        gitsha = bb.finish()[mark]
175
        os.chdir("..")
176
        return "d", gitsha
177
0.247.1 by Michael Hudson
test
178
    def make_tworev_branch(self):
179
        os.mkdir("d")
180
        os.chdir("d")
181
        GitRepo.init('.')
182
        bb = tests.GitBranchBuilder()
183
        bb.set_file("foobar", "foo\nbar\n", False)
184
        mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
185
        mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
186
        marks = bb.finish()
187
        os.chdir("..")
188
        return "d", (marks[mark1], marks[mark2])
189
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
190
    def clone_git_branch(self, from_url, to_url):
0.200.1014 by Jelmer Vernooij
Fix tests.
191
        from_dir = BzrDir.open(from_url)
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
192
        to_dir = from_dir.sprout(to_url)
193
        return to_dir.open_branch()
194
195
    def test_single_rev(self):
196
        path, gitsha = self.make_onerev_branch()
197
        oldrepo = Repository.open(path)
198
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
199
        newbranch = self.clone_git_branch(path, "f")
200
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
201
202
    def test_sprouted_tags(self):
203
        path, gitsha = self.make_onerev_branch()
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
204
        r = GitRepo(path)
205
        r.refs["refs/tags/lala"] = r.head()
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
206
        oldrepo = Repository.open(path)
207
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
208
        newbranch = self.clone_git_branch(path, "f")
209
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
210
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
211
0.247.1 by Michael Hudson
test
212
    def test_interbranch_pull(self):
213
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
214
        oldrepo = Repository.open(path)
215
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
216
        newbranch = self.make_branch('g')
217
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
218
        inter_branch.pull()
219
        self.assertEquals(revid2, newbranch.last_revision())
220
0.247.5 by Michael Hudson
test and fix for noop pull case
221
    def test_interbranch_pull_noop(self):
222
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
223
        oldrepo = Repository.open(path)
224
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
225
        newbranch = self.make_branch('g')
226
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
227
        inter_branch.pull()
228
        # This is basically "assertNotRaises"
229
        inter_branch.pull()
230
        self.assertEquals(revid2, newbranch.last_revision())
231
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
232
    def test_interbranch_pull_stop_revision(self):
233
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
234
        oldrepo = Repository.open(path)
235
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
236
        newbranch = self.make_branch('g')
237
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
238
        inter_branch.pull(stop_revision=revid1)
239
        self.assertEquals(revid1, newbranch.last_revision())
240
0.259.8 by Jelmer Vernooij
Add test.
241
    def test_interbranch_pull_with_tags(self):
242
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
243
        gitrepo = GitRepo(path)
244
        gitrepo.refs["refs/tags/sometag"] = gitsha2
245
        oldrepo = Repository.open(path)
246
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
247
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
248
        newbranch = self.make_branch('g')
249
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
250
        inter_branch.pull(stop_revision=revid1)
251
        self.assertEquals(revid1, newbranch.last_revision())
252
        self.assertTrue(newbranch.repository.has_revision(revid2))
253
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
254
255
class ForeignTestsBranchFactory(object):
256
257
    def make_empty_branch(self, transport):
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
258
        d = LocalGitControlDirFormat().initialize_on_transport(transport)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
259
        return d.create_branch()
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
260
261
    make_branch = make_empty_branch
0.200.770 by Jelmer Vernooij
Proper branch names.
262
263
0.200.833 by Jelmer Vernooij
Fix handling of remote branches.
264