/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

Merge a bunch of fixes from store-roundtrip-info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    )
29
29
 
30
30
import os
 
31
import urllib
31
32
 
32
33
from bzrlib import (
33
34
    errors,
34
35
    revision,
 
36
    urlutils,
 
37
    version_info as bzrlib_version,
35
38
    )
36
39
from bzrlib.branch import (
37
40
    Branch,
43
46
from bzrlib.repository import (
44
47
    Repository,
45
48
    )
 
49
from bzrlib.symbol_versioning import (
 
50
    deprecated_in,
 
51
    )
 
52
from bzrlib.tests import TestSkipped
46
53
 
47
54
from bzrlib.plugins.git import (
48
 
    LocalGitControlDirFormat,
49
55
    branch,
50
56
    tests,
51
57
    )
 
58
from bzrlib.plugins.git.dir import (
 
59
    LocalGitControlDirFormat,
 
60
    )
52
61
from bzrlib.plugins.git.mapping import (
53
62
    default_mapping,
54
63
    )
56
65
 
57
66
class TestGitBranch(tests.TestCaseInTempDir):
58
67
 
 
68
    def test_open_by_ref(self):
 
69
        GitRepo.init('.')
 
70
        url = "%s,ref=%s" % (
 
71
            urlutils.local_path_to_url(self.test_dir),
 
72
            urllib.quote("refs/remotes/origin/unstable", safe='')
 
73
            )
 
74
        if bzrlib_version < (2, 5, 0):
 
75
            self.assertRaises(errors.NotBranchError, BzrDir.open, url)
 
76
            raise TestSkipped("opening by ref not supported with bzr < 2.5")
 
77
        d = BzrDir.open(url)
 
78
        b = d.create_branch()
 
79
        self.assertEquals(b.ref, "refs/remotes/origin/unstable")
 
80
 
59
81
    def test_open_existing(self):
60
 
        GitRepo.init('.')
 
82
        r = GitRepo.init('.')
 
83
        del r.refs["HEAD"]
61
84
        d = BzrDir.open('.')
62
85
        thebranch = d.create_branch()
63
86
        self.assertIsInstance(thebranch, branch.GitBranch)
64
87
 
65
88
    def test_repr(self):
66
 
        GitRepo.init('.')
 
89
        r = GitRepo.init('.')
 
90
        del r.refs["HEAD"]
67
91
        d = BzrDir.open('.')
68
92
        thebranch = d.create_branch()
69
 
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
 
93
        self.assertEquals(
 
94
            "<LocalGitBranch('%s/', u'')>" % (
 
95
                urlutils.local_path_to_url(self.test_dir),),
 
96
            repr(thebranch))
70
97
 
71
98
    def test_last_revision_is_null(self):
72
 
        GitRepo.init('.')
 
99
        r = GitRepo.init('.')
 
100
        del r.refs["HEAD"]
73
101
        thedir = BzrDir.open('.')
74
102
        thebranch = thedir.create_branch()
75
103
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
96
124
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
97
125
 
98
126
        thebranch = Branch.open('.')
 
127
        (warnings, history) = self.callCatchWarnings(thebranch.revision_history)
 
128
        self.assertTrue(
 
129
            warnings == [] or 
 
130
            (len(warnings) == 1 and isinstance(warnings[0], DeprecationWarning)),
 
131
            warnings)
99
132
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
 
                         thebranch.revision_history())
 
133
                         history)
101
134
 
102
135
    def test_tag_annotated(self):
103
136
        reva = self.simple_commit_a()
129
162
 
130
163
    def setUp(self):
131
164
        tests.TestCaseWithTransport.setUp(self)
132
 
        dulwich.repo.Repo.create(self.test_dir)
 
165
        r = dulwich.repo.Repo.create(self.test_dir)
 
166
        del r.refs["HEAD"]
133
167
        d = BzrDir.open(self.test_dir)
134
168
        self.git_branch = d.create_branch()
135
169
 
171
205
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
172
206
        gitsha = bb.finish()[mark]
173
207
        os.chdir("..")
174
 
        return "d", gitsha
 
208
        return os.path.abspath("d"), gitsha
175
209
 
176
210
    def make_tworev_branch(self):
177
211
        os.mkdir("d")
194
228
        path, gitsha = self.make_onerev_branch()
195
229
        oldrepo = Repository.open(path)
196
230
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
231
        self.assertEquals(gitsha, oldrepo._git.get_refs()["refs/heads/master"])
197
232
        newbranch = self.clone_git_branch(path, "f")
198
233
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
199
234
 
236
271
        inter_branch.pull(stop_revision=revid1)
237
272
        self.assertEquals(revid1, newbranch.last_revision())
238
273
 
239
 
    def test_interbranch_limited_pull(self):
 
274
    def test_interbranch_pull_with_tags(self):
240
275
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
 
276
        gitrepo = GitRepo(path)
 
277
        gitrepo.refs["refs/tags/sometag"] = gitsha2
241
278
        oldrepo = Repository.open(path)
242
279
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
280
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
281
        newbranch = self.make_branch('g')
245
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
 
        inter_branch.pull(limit=1)
 
282
        source_branch = Branch.open(path)
 
283
        source_branch.get_config().set_user_option("branch.fetch_tags", True)
 
284
        inter_branch = InterBranch.get(source_branch, newbranch)
 
285
        inter_branch.pull(stop_revision=revid1)
247
286
        self.assertEquals(revid1, newbranch.last_revision())
248
 
        inter_branch.pull(limit=1)
249
 
        self.assertEquals(revid2, newbranch.last_revision())
 
287
        self.assertTrue(newbranch.repository.has_revision(revid2))
250
288
 
251
289
 
252
290
class ForeignTestsBranchFactory(object):
256
294
        return d.create_branch()
257
295
 
258
296
    make_branch = make_empty_branch
259
 
 
260
 
 
261