/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

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import os
27
27
 
28
28
from bzrlib import (
29
 
    errors,
30
29
    revision,
31
30
    )
32
31
from bzrlib.branch import (
33
32
    Branch,
34
 
    InterBranch,
35
33
    )
36
34
from bzrlib.bzrdir import (
37
35
    BzrDir,
41
39
    )
42
40
 
43
41
from bzrlib.plugins.git import (
44
 
    LocalGitBzrDirFormat,
45
42
    branch,
46
43
    tests,
47
44
    )
48
 
from bzrlib.plugins.git.mapping import (
49
 
    default_mapping,
50
 
    )
 
45
from bzrlib.plugins.git.mapping import default_mapping
51
46
 
52
47
 
53
48
class TestGitBranch(tests.TestCaseInTempDir):
56
51
 
57
52
    def test_open_existing(self):
58
53
        GitRepo.init('.')
59
 
        d = BzrDir.open('.')
60
 
        thebranch = d.create_branch()
 
54
 
 
55
        thebranch = Branch.open('.')
61
56
        self.assertIsInstance(thebranch, branch.GitBranch)
62
57
 
63
58
    def test_repr(self):
64
59
        GitRepo.init('.')
65
 
        d = BzrDir.open('.')
66
 
        thebranch = d.create_branch()
67
 
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
 
60
        thebranch = Branch.open('.')
 
61
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
68
62
 
69
63
    def test_last_revision_is_null(self):
70
64
        GitRepo.init('.')
71
 
        thedir = BzrDir.open('.')
72
 
        thebranch = thedir.create_branch()
 
65
 
 
66
        thebranch = Branch.open('.')
73
67
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
74
68
        self.assertEqual((0, revision.NULL_REVISION),
75
69
                         thebranch.last_revision_info())
83
77
    def test_last_revision_is_valid(self):
84
78
        self.simple_commit_a()
85
79
        head = tests.run_git('rev-parse', 'HEAD').strip()
 
80
 
86
81
        thebranch = Branch.open('.')
87
82
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
88
83
                         thebranch.last_revision())
122
117
    def setUp(self):
123
118
        tests.TestCaseWithTransport.setUp(self)
124
119
        dulwich.repo.Repo.create(self.test_dir)
125
 
        d = BzrDir.open(self.test_dir)
126
 
        self.git_branch = d.create_branch()
 
120
        self.git_branch = Branch.open(self.test_dir)
127
121
 
128
122
    def test_get_parent(self):
129
123
        self.assertIs(None, self.git_branch.get_parent())
130
124
 
131
125
    def test_get_stacked_on_url(self):
132
 
        self.assertRaises(errors.UnstackableBranchFormat, 
133
 
            self.git_branch.get_stacked_on_url)
 
126
        self.assertIs(None, self.git_branch.get_stacked_on_url())
134
127
 
135
128
    def test_get_physical_lock_status(self):
136
129
        self.assertFalse(self.git_branch.get_physical_lock_status())
160
153
        os.chdir("..")
161
154
        return "d", gitsha
162
155
 
163
 
    def make_tworev_branch(self):
164
 
        os.mkdir("d")
165
 
        os.chdir("d")
166
 
        GitRepo.init('.')
167
 
        bb = tests.GitBranchBuilder()
168
 
        bb.set_file("foobar", "foo\nbar\n", False)
169
 
        mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
170
 
        mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
171
 
        marks = bb.finish()
172
 
        os.chdir("..")
173
 
        return "d", (marks[mark1], marks[mark2])
174
 
 
175
156
    def clone_git_branch(self, from_url, to_url):
176
157
        from_dir = BzrDir.open(from_url)
177
158
        to_dir = from_dir.sprout(to_url)
194
175
        newbranch = self.clone_git_branch(path, "f")
195
176
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
196
177
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
197
 
 
198
 
    def test_interbranch_pull(self):
199
 
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
200
 
        oldrepo = Repository.open(path)
201
 
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
202
 
        newbranch = self.make_branch('g')
203
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
204
 
        inter_branch.pull()
205
 
        self.assertEquals(revid2, newbranch.last_revision())
206
 
 
207
 
    def test_interbranch_pull_noop(self):
208
 
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
209
 
        oldrepo = Repository.open(path)
210
 
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
211
 
        newbranch = self.make_branch('g')
212
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
213
 
        inter_branch.pull()
214
 
        # This is basically "assertNotRaises"
215
 
        inter_branch.pull()
216
 
        self.assertEquals(revid2, newbranch.last_revision())
217
 
 
218
 
    def test_interbranch_pull_stop_revision(self):
219
 
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
220
 
        oldrepo = Repository.open(path)
221
 
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
222
 
        newbranch = self.make_branch('g')
223
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
224
 
        inter_branch.pull(stop_revision=revid1)
225
 
        self.assertEquals(revid1, newbranch.last_revision())
226
 
 
227
 
    def test_interbranch_limited_pull(self):
228
 
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
229
 
        oldrepo = Repository.open(path)
230
 
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
231
 
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
232
 
        newbranch = self.make_branch('g')
233
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
234
 
        inter_branch.pull(limit=1)
235
 
        self.assertEquals(revid1, newbranch.last_revision())
236
 
        inter_branch.pull(limit=1)
237
 
        self.assertEquals(revid2, newbranch.last_revision())
238
 
 
239
 
 
240
 
class ForeignTestsBranchFactory(object):
241
 
 
242
 
    def make_empty_branch(self, transport):
243
 
        d = LocalGitBzrDirFormat().initialize_on_transport(transport)
244
 
        return d.create_branch()
245
 
 
246
 
    make_branch = make_empty_branch
247
 
 
248
 
 
249