/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

SupportĀ limitĀ argument.

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
82
        GitRepo.init('.')
61
83
        d = BzrDir.open('.')
66
88
        GitRepo.init('.')
67
89
        d = BzrDir.open('.')
68
90
        thebranch = d.create_branch()
69
 
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
 
91
        self.assertEquals(
 
92
            "<LocalGitBranch('%s/', u'master')>" % (
 
93
                urlutils.local_path_to_url(self.test_dir),),
 
94
            repr(thebranch))
70
95
 
71
96
    def test_last_revision_is_null(self):
72
97
        GitRepo.init('.')
96
121
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
97
122
 
98
123
        thebranch = Branch.open('.')
 
124
        (warnings, history) = self.callCatchWarnings(thebranch.revision_history)
 
125
        self.assertTrue(
 
126
            warnings == [] or 
 
127
            (len(warnings) == 1 and isinstance(warnings[0], DeprecationWarning)),
 
128
            warnings)
99
129
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
 
                         thebranch.revision_history())
 
130
                         history)
101
131
 
102
132
    def test_tag_annotated(self):
103
133
        reva = self.simple_commit_a()
171
201
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
172
202
        gitsha = bb.finish()[mark]
173
203
        os.chdir("..")
174
 
        return "d", gitsha
 
204
        return os.path.abspath("d"), gitsha
175
205
 
176
206
    def make_tworev_branch(self):
177
207
        os.mkdir("d")
194
224
        path, gitsha = self.make_onerev_branch()
195
225
        oldrepo = Repository.open(path)
196
226
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
227
        self.assertEquals(gitsha, oldrepo._git.get_refs()["refs/heads/master"])
197
228
        newbranch = self.clone_git_branch(path, "f")
198
229
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
199
230
 
236
267
        inter_branch.pull(stop_revision=revid1)
237
268
        self.assertEquals(revid1, newbranch.last_revision())
238
269
 
239
 
    def test_interbranch_limited_pull(self):
 
270
    def test_interbranch_pull_with_tags(self):
240
271
        path, (gitsha1, gitsha2) = self.make_tworev_branch()
 
272
        gitrepo = GitRepo(path)
 
273
        gitrepo.refs["refs/tags/sometag"] = gitsha2
241
274
        oldrepo = Repository.open(path)
242
275
        revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
276
        revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
277
        newbranch = self.make_branch('g')
245
 
        inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
 
        inter_branch.pull(limit=1)
 
278
        source_branch = Branch.open(path)
 
279
        source_branch.get_config().set_user_option("branch.fetch_tags", True)
 
280
        inter_branch = InterBranch.get(source_branch, newbranch)
 
281
        inter_branch.pull(stop_revision=revid1)
247
282
        self.assertEquals(revid1, newbranch.last_revision())
248
 
        inter_branch.pull(limit=1)
249
 
        self.assertEquals(revid2, newbranch.last_revision())
 
283
        self.assertTrue(newbranch.repository.has_revision(revid2))
250
284
 
251
285
 
252
286
class ForeignTestsBranchFactory(object):
256
290
        return d.create_branch()
257
291
 
258
292
    make_branch = make_empty_branch
259
 
 
260
 
 
261