/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

Don't claim control directories can be accessed directly, always open the
branch itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
import dulwich
22
 
from dulwich.objects import (
23
 
    Commit,
24
 
    Tag,
25
 
    )
26
22
from dulwich.repo import (
27
23
    Repo as GitRepo,
28
24
    )
45
41
    )
46
42
 
47
43
from bzrlib.plugins.git import (
48
 
    LocalGitControlDirFormat,
 
44
    LocalGitBzrDirFormat,
49
45
    branch,
50
46
    tests,
51
47
    )
56
52
 
57
53
class TestGitBranch(tests.TestCaseInTempDir):
58
54
 
 
55
    _test_needs_features = [tests.GitCommandFeature]
 
56
 
59
57
    def test_open_existing(self):
60
58
        GitRepo.init('.')
61
 
        d = BzrDir.open('.')
62
 
        thebranch = d.create_branch()
 
59
 
 
60
        thebranch = Branch.open('.')
63
61
        self.assertIsInstance(thebranch, branch.GitBranch)
64
62
 
65
63
    def test_repr(self):
66
64
        GitRepo.init('.')
67
 
        d = BzrDir.open('.')
68
 
        thebranch = d.create_branch()
69
 
        self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
 
65
        thebranch = Branch.open('.')
 
66
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
70
67
 
71
68
    def test_last_revision_is_null(self):
72
69
        GitRepo.init('.')
73
 
        thedir = BzrDir.open('.')
74
 
        thebranch = thedir.create_branch()
 
70
 
 
71
        thebranch = Branch.open('.')
75
72
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
76
73
        self.assertEqual((0, revision.NULL_REVISION),
77
74
                         thebranch.last_revision_info())
78
75
 
79
76
    def simple_commit_a(self):
80
 
        r = GitRepo.init('.')
 
77
        GitRepo.init('.')
81
78
        self.build_tree(['a'])
82
 
        r.stage(["a"])
83
 
        return r.do_commit("a", committer="Somebody <foo@example.com>")
 
79
        tests.run_git('add', 'a')
 
80
        tests.run_git('commit', '-m', 'a')
84
81
 
85
82
    def test_last_revision_is_valid(self):
86
 
        head = self.simple_commit_a()
 
83
        self.simple_commit_a()
 
84
        head = tests.run_git('rev-parse', 'HEAD').strip()
 
85
 
87
86
        thebranch = Branch.open('.')
88
87
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
89
88
                         thebranch.last_revision())
90
89
 
91
90
    def test_revision_history(self):
92
 
        reva = self.simple_commit_a()
 
91
        self.simple_commit_a()
 
92
        reva = tests.run_git('rev-parse', 'HEAD').strip()
93
93
        self.build_tree(['b'])
94
 
        r = GitRepo(".")
95
 
        r.stage("b")
96
 
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
 
94
        tests.run_git('add', 'b')
 
95
        tests.run_git('commit', '-m', 'b')
 
96
        revb = tests.run_git('rev-parse', 'HEAD').strip()
97
97
 
98
98
        thebranch = Branch.open('.')
99
99
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
100
                         thebranch.revision_history())
101
101
 
102
102
    def test_tag_annotated(self):
103
 
        reva = self.simple_commit_a()
104
 
        o = Tag()
105
 
        o.name = "foo"
106
 
        o.tagger = "Jelmer <foo@example.com>"
107
 
        o.message = "add tag"
108
 
        o.object = (Commit, reva)
109
 
        o.tag_timezone = 0
110
 
        o.tag_time = 42
111
 
        r = GitRepo(".")
112
 
        r.object_store.add_object(o)
113
 
        r['refs/tags/foo'] = o.id
 
103
        self.simple_commit_a()
 
104
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
105
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
114
106
        thebranch = Branch.open('.')
115
107
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
108
                          thebranch.tags.get_tag_dict())
117
109
 
118
110
    def test_tag(self):
119
 
        reva = self.simple_commit_a()
120
 
        r = GitRepo(".")
121
 
        r.refs["refs/tags/foo"] = reva
 
111
        self.simple_commit_a()
 
112
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
113
        tests.run_git('tag', '-m', 'add tag', 'foo')
122
114
        thebranch = Branch.open('.')
123
115
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
124
116
                          thebranch.tags.get_tag_dict())
125
117
 
126
 
 
 
118
        
127
119
 
128
120
class TestWithGitBranch(tests.TestCaseWithTransport):
129
121
 
130
122
    def setUp(self):
131
123
        tests.TestCaseWithTransport.setUp(self)
132
124
        dulwich.repo.Repo.create(self.test_dir)
133
 
        d = BzrDir.open(self.test_dir)
134
 
        self.git_branch = d.create_branch()
 
125
        self.git_branch = Branch.open(self.test_dir)
135
126
 
136
127
    def test_get_parent(self):
137
128
        self.assertIs(None, self.git_branch.get_parent())
138
129
 
139
130
    def test_get_stacked_on_url(self):
140
 
        self.assertRaises(errors.UnstackableBranchFormat,
 
131
        self.assertRaises(errors.UnstackableBranchFormat, 
141
132
            self.git_branch.get_stacked_on_url)
142
133
 
143
134
    def test_get_physical_lock_status(self):
153
144
    def test_get_format_description(self):
154
145
        self.assertEquals("Git Branch", self.format.get_format_description())
155
146
 
156
 
    def test_get_network_name(self):
157
 
        self.assertEquals("git", self.format.network_name())
158
 
 
159
 
    def test_supports_tags(self):
160
 
        self.assertTrue(self.format.supports_tags())
161
147
 
162
148
 
163
149
class BranchTests(tests.TestCaseInTempDir):
199
185
 
200
186
    def test_sprouted_tags(self):
201
187
        path, gitsha = self.make_onerev_branch()
202
 
        r = GitRepo(path)
203
 
        r.refs["refs/tags/lala"] = r.head()
 
188
        os.chdir(path)
 
189
        tests.run_git("tag", "lala")
 
190
        os.chdir(self.test_dir)
204
191
        oldrepo = Repository.open(path)
205
192
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
206
193
        newbranch = self.clone_git_branch(path, "f")
252
239
class ForeignTestsBranchFactory(object):
253
240
 
254
241
    def make_empty_branch(self, transport):
255
 
        d = LocalGitControlDirFormat().initialize_on_transport(transport)
256
 
        return d.create_branch()
 
242
        return LocalGitBzrDirFormat().initialize_on_transport(transport).open_branch()
257
243
 
258
244
    make_branch = make_empty_branch
259
 
 
260
 
 
261