~bzr/ubuntu/karmic/bzr-git/bzr-ppa

« back to all changes in this revision

Viewing changes to tests/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-22 23:40:04 UTC
  • mfrom: (17.25.364 trunk)
  • Revision ID: jelmer@samba.org-20100522234004-48r0bfkodp3xspgv
* New upstream release.
* Bump standards version to 3.8.4.

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())
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())
158
160
        os.chdir("..")
159
161
        return "d", gitsha
160
162
 
 
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
 
161
175
    def clone_git_branch(self, from_url, to_url):
162
176
        from_dir = BzrDir.open(from_url)
163
177
        to_dir = from_dir.sprout(to_url)
181
195
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
182
196
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
183
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
 
184
239
 
185
240
class ForeignTestsBranchFactory(object):
186
241
 
187
242
    def make_empty_branch(self, transport):
188
 
        return LocalGitBzrDirFormat().initialize_on_transport(transport).open_branch()
 
243
        d = LocalGitBzrDirFormat().initialize_on_transport(transport)
 
244
        return d.create_branch()
189
245
 
190
246
    make_branch = make_empty_branch
 
247
 
 
248
 
 
249