/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

Use BZR_PLUGINS_AT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    )
32
32
from bzrlib.branch import (
33
33
    Branch,
 
34
    InterBranch,
34
35
    )
35
36
from bzrlib.bzrdir import (
36
37
    BzrDir,
55
56
 
56
57
    def test_open_existing(self):
57
58
        GitRepo.init('.')
58
 
 
59
 
        thebranch = Branch.open('.')
 
59
        d = BzrDir.open('.')
 
60
        thebranch = d.create_branch()
60
61
        self.assertIsInstance(thebranch, branch.GitBranch)
61
62
 
62
63
    def test_repr(self):
63
64
        GitRepo.init('.')
64
 
        thebranch = Branch.open('.')
65
 
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
 
65
        d = BzrDir.open('.')
 
66
        thebranch = d.create_branch()
 
67
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
66
68
 
67
69
    def test_last_revision_is_null(self):
68
70
        GitRepo.init('.')
69
 
 
70
 
        thebranch = Branch.open('.')
 
71
        thedir = BzrDir.open('.')
 
72
        thebranch = thedir.create_branch()
71
73
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
72
74
        self.assertEqual((0, revision.NULL_REVISION),
73
75
                         thebranch.last_revision_info())
81
83
    def test_last_revision_is_valid(self):
82
84
        self.simple_commit_a()
83
85
        head = tests.run_git('rev-parse', 'HEAD').strip()
84
 
 
85
86
        thebranch = Branch.open('.')
86
87
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
87
88
                         thebranch.last_revision())
114
115
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
115
116
                          thebranch.tags.get_tag_dict())
116
117
 
117
 
        
 
118
 
118
119
 
119
120
class TestWithGitBranch(tests.TestCaseWithTransport):
120
121
 
121
122
    def setUp(self):
122
123
        tests.TestCaseWithTransport.setUp(self)
123
124
        dulwich.repo.Repo.create(self.test_dir)
124
 
        self.git_branch = Branch.open(self.test_dir)
 
125
        d = BzrDir.open(self.test_dir)
 
126
        self.git_branch = d.create_branch()
125
127
 
126
128
    def test_get_parent(self):
127
129
        self.assertIs(None, self.git_branch.get_parent())
128
130
 
129
131
    def test_get_stacked_on_url(self):
130
 
        self.assertRaises(errors.UnstackableBranchFormat, 
 
132
        self.assertRaises(errors.UnstackableBranchFormat,
131
133
            self.git_branch.get_stacked_on_url)
132
134
 
133
135
    def test_get_physical_lock_status(self):
143
145
    def test_get_format_description(self):
144
146
        self.assertEquals("Git Branch", self.format.get_format_description())
145
147
 
 
148
    def test_get_network_name(self):
 
149
        self.assertEquals("git", self.format.network_name())
 
150
 
 
151
    def test_supports_tags(self):
 
152
        self.assertTrue(self.format.supports_tags())
146
153
 
147
154
 
148
155
class BranchTests(tests.TestCaseInTempDir):
158
165
        os.chdir("..")
159
166
        return "d", gitsha
160
167
 
 
168
    def make_tworev_branch(self):
 
169
        os.mkdir("d")
 
170
        os.chdir("d")
 
171
        GitRepo.init('.')
 
172
        bb = tests.GitBranchBuilder()
 
173
        bb.set_file("foobar", "foo\nbar\n", False)
 
174
        mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
175
        mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
176
        marks = bb.finish()
 
177
        os.chdir("..")
 
178
        return "d", (marks[mark1], marks[mark2])
 
179
 
161
180
    def clone_git_branch(self, from_url, to_url):
162
181
        from_dir = BzrDir.open(from_url)
163
182
        to_dir = from_dir.sprout(to_url)
181
200
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
182
201
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
183
202
 
 
203
    def test_interbranch_pull(self):
 
204
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
 
205
        oldrepo = Repository.open(path)
 
206
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
 
207
        newbranch = self.make_branch('g')
 
208
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
 
209
        inter_branch.pull()
 
210
        self.assertEquals(revid2, newbranch.last_revision())
 
211
 
 
212
    def test_interbranch_pull_noop(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
        # This is basically "assertNotRaises"
 
220
        inter_branch.pull()
 
221
        self.assertEquals(revid2, newbranch.last_revision())
 
222
 
 
223
    def test_interbranch_pull_stop_revision(self):
 
224
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
 
225
        oldrepo = Repository.open(path)
 
226
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
 
227
        newbranch = self.make_branch('g')
 
228
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
 
229
        inter_branch.pull(stop_revision=revid1)
 
230
        self.assertEquals(revid1, newbranch.last_revision())
 
231
 
 
232
    def test_interbranch_limited_pull(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
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
 
237
        newbranch = self.make_branch('g')
 
238
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
 
239
        inter_branch.pull(limit=1)
 
240
        self.assertEquals(revid1, newbranch.last_revision())
 
241
        inter_branch.pull(limit=1)
 
242
        self.assertEquals(revid2, newbranch.last_revision())
 
243
 
184
244
 
185
245
class ForeignTestsBranchFactory(object):
186
246
 
187
247
    def make_empty_branch(self, transport):
188
 
        return LocalGitBzrDirFormat().initialize_on_transport(transport).open_branch()
 
248
        d = LocalGitBzrDirFormat().initialize_on_transport(transport)
 
249
        return d.create_branch()
189
250
 
190
251
    make_branch = make_empty_branch
 
252
 
 
253
 
 
254