/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_branch.py

Raise exception on unknown keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
import dulwich
22
 
from dulwich.objects import (
23
 
    Commit,
24
 
    Tag,
25
 
    )
26
22
from dulwich.repo import (
27
23
    Repo as GitRepo,
28
24
    )
35
31
    )
36
32
from bzrlib.branch import (
37
33
    Branch,
38
 
    InterBranch,
39
34
    )
40
35
from bzrlib.bzrdir import (
41
36
    BzrDir,
45
40
    )
46
41
 
47
42
from bzrlib.plugins.git import (
48
 
    LocalGitControlDirFormat,
49
43
    branch,
50
44
    tests,
51
45
    )
56
50
 
57
51
class TestGitBranch(tests.TestCaseInTempDir):
58
52
 
 
53
    _test_needs_features = [tests.GitCommandFeature]
 
54
 
59
55
    def test_open_existing(self):
60
56
        GitRepo.init('.')
61
 
        d = BzrDir.open('.')
62
 
        thebranch = d.create_branch()
 
57
 
 
58
        thebranch = Branch.open('.')
63
59
        self.assertIsInstance(thebranch, branch.GitBranch)
64
60
 
65
61
    def test_repr(self):
66
62
        GitRepo.init('.')
67
 
        d = BzrDir.open('.')
68
 
        thebranch = d.create_branch()
69
 
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
 
63
        thebranch = Branch.open('.')
 
64
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
70
65
 
71
66
    def test_last_revision_is_null(self):
72
67
        GitRepo.init('.')
73
 
        thedir = BzrDir.open('.')
74
 
        thebranch = thedir.create_branch()
 
68
 
 
69
        thebranch = Branch.open('.')
75
70
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
76
71
        self.assertEqual((0, revision.NULL_REVISION),
77
72
                         thebranch.last_revision_info())
78
73
 
79
74
    def simple_commit_a(self):
80
 
        r = GitRepo.init('.')
 
75
        GitRepo.init('.')
81
76
        self.build_tree(['a'])
82
 
        r.stage(["a"])
83
 
        return r.do_commit("a", committer="Somebody <foo@example.com>")
 
77
        tests.run_git('add', 'a')
 
78
        tests.run_git('commit', '-m', 'a')
84
79
 
85
80
    def test_last_revision_is_valid(self):
86
 
        head = self.simple_commit_a()
 
81
        self.simple_commit_a()
 
82
        head = tests.run_git('rev-parse', 'HEAD').strip()
 
83
 
87
84
        thebranch = Branch.open('.')
88
85
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
89
86
                         thebranch.last_revision())
90
87
 
91
88
    def test_revision_history(self):
92
 
        reva = self.simple_commit_a()
 
89
        self.simple_commit_a()
 
90
        reva = tests.run_git('rev-parse', 'HEAD').strip()
93
91
        self.build_tree(['b'])
94
 
        r = GitRepo(".")
95
 
        r.stage("b")
96
 
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
 
92
        tests.run_git('add', 'b')
 
93
        tests.run_git('commit', '-m', 'b')
 
94
        revb = tests.run_git('rev-parse', 'HEAD').strip()
97
95
 
98
96
        thebranch = Branch.open('.')
99
97
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
98
                         thebranch.revision_history())
101
99
 
102
100
    def test_tag_annotated(self):
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
 
101
        self.simple_commit_a()
 
102
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
103
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
114
104
        thebranch = Branch.open('.')
115
105
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
106
                          thebranch.tags.get_tag_dict())
117
107
 
118
108
    def test_tag(self):
119
 
        reva = self.simple_commit_a()
120
 
        r = GitRepo(".")
121
 
        r.refs["refs/tags/foo"] = reva
 
109
        self.simple_commit_a()
 
110
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
111
        tests.run_git('tag', '-m', 'add tag', 'foo')
122
112
        thebranch = Branch.open('.')
123
113
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
124
114
                          thebranch.tags.get_tag_dict())
125
115
 
126
 
 
 
116
        
127
117
 
128
118
class TestWithGitBranch(tests.TestCaseWithTransport):
129
119
 
130
120
    def setUp(self):
131
121
        tests.TestCaseWithTransport.setUp(self)
132
122
        dulwich.repo.Repo.create(self.test_dir)
133
 
        d = BzrDir.open(self.test_dir)
134
 
        self.git_branch = d.create_branch()
 
123
        self.git_branch = Branch.open(self.test_dir)
135
124
 
136
125
    def test_get_parent(self):
137
126
        self.assertIs(None, self.git_branch.get_parent())
138
127
 
139
128
    def test_get_stacked_on_url(self):
140
 
        self.assertRaises(errors.UnstackableBranchFormat,
 
129
        self.assertRaises(errors.UnstackableBranchFormat, 
141
130
            self.git_branch.get_stacked_on_url)
142
131
 
143
132
    def test_get_physical_lock_status(self):
153
142
    def test_get_format_description(self):
154
143
        self.assertEquals("Git Branch", self.format.get_format_description())
155
144
 
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())
161
145
 
162
146
 
163
147
class BranchTests(tests.TestCaseInTempDir):
173
157
        os.chdir("..")
174
158
        return "d", gitsha
175
159
 
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
 
 
188
160
    def clone_git_branch(self, from_url, to_url):
189
161
        from_dir = BzrDir.open(from_url)
190
162
        to_dir = from_dir.sprout(to_url)
199
171
 
200
172
    def test_sprouted_tags(self):
201
173
        path, gitsha = self.make_onerev_branch()
202
 
        r = GitRepo(path)
203
 
        r.refs["refs/tags/lala"] = r.head()
 
174
        os.chdir(path)
 
175
        tests.run_git("tag", "lala")
 
176
        os.chdir(self.test_dir)
204
177
        oldrepo = Repository.open(path)
205
178
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
206
179
        newbranch = self.clone_git_branch(path, "f")
207
180
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
208
181
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
209
 
 
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
 
 
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
 
 
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
 
 
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
 
 
251
 
 
252
 
class ForeignTestsBranchFactory(object):
253
 
 
254
 
    def make_empty_branch(self, transport):
255
 
        d = LocalGitControlDirFormat().initialize_on_transport(transport)
256
 
        return d.create_branch()
257
 
 
258
 
    make_branch = make_empty_branch
259
 
 
260
 
 
261