/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

Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
 
18
17
"""Tests for interfacing with a Git Branch"""
19
18
 
20
 
 
21
 
import dulwich
22
 
from dulwich.repo import (
23
 
    Repo as GitRepo,
24
 
    )
25
 
 
26
 
import os
27
 
 
28
 
from bzrlib import (
29
 
    errors,
30
 
    revision,
31
 
    )
32
 
from bzrlib.branch import (
33
 
    Branch,
34
 
    )
35
 
from bzrlib.bzrdir import (
36
 
    BzrDir,
37
 
    )
38
 
from bzrlib.repository import (
39
 
    Repository,
40
 
    )
 
19
from bzrlib import revision
 
20
from bzrlib.branch import Branch
41
21
 
42
22
from bzrlib.plugins.git import (
43
 
    LocalGitBzrDirFormat,
44
23
    branch,
45
24
    tests,
46
25
    )
47
 
from bzrlib.plugins.git.mapping import (
48
 
    default_mapping,
49
 
    )
 
26
from bzrlib.plugins.git.mapping import default_mapping
 
27
 
 
28
import dulwich as git
50
29
 
51
30
 
52
31
class TestGitBranch(tests.TestCaseInTempDir):
54
33
    _test_needs_features = [tests.GitCommandFeature]
55
34
 
56
35
    def test_open_existing(self):
57
 
        GitRepo.init('.')
 
36
        tests.run_git('init')
58
37
 
59
38
        thebranch = Branch.open('.')
60
39
        self.assertIsInstance(thebranch, branch.GitBranch)
61
40
 
62
 
    def test_repr(self):
63
 
        GitRepo.init('.')
64
 
        thebranch = Branch.open('.')
65
 
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
66
 
 
67
41
    def test_last_revision_is_null(self):
68
 
        GitRepo.init('.')
 
42
        tests.run_git('init')
69
43
 
70
44
        thebranch = Branch.open('.')
71
45
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
73
47
                         thebranch.last_revision_info())
74
48
 
75
49
    def simple_commit_a(self):
76
 
        GitRepo.init('.')
 
50
        tests.run_git('init')
77
51
        self.build_tree(['a'])
78
52
        tests.run_git('add', 'a')
79
53
        tests.run_git('commit', '-m', 'a')
98
72
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
99
73
                         thebranch.revision_history())
100
74
 
101
 
    def test_tag_annotated(self):
 
75
    def test_tags(self):
102
76
        self.simple_commit_a()
103
77
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
78
        
104
79
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
105
 
        thebranch = Branch.open('.')
106
 
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
107
 
                          thebranch.tags.get_tag_dict())
108
 
 
109
 
    def test_tag(self):
110
 
        self.simple_commit_a()
111
 
        reva = tests.run_git('rev-parse', 'HEAD').strip()
112
 
        tests.run_git('tag', '-m', 'add tag', 'foo')
113
 
        thebranch = Branch.open('.')
114
 
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
115
 
                          thebranch.tags.get_tag_dict())
116
 
 
 
80
        
 
81
        thebranch = Branch.open('.')
 
82
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
 
83
                          thebranch.tags.get_tag_dict())
117
84
        
118
85
 
119
86
class TestWithGitBranch(tests.TestCaseWithTransport):
120
87
 
121
88
    def setUp(self):
122
89
        tests.TestCaseWithTransport.setUp(self)
123
 
        dulwich.repo.Repo.create(self.test_dir)
 
90
        git.repo.Repo.create(self.test_dir)
124
91
        self.git_branch = Branch.open(self.test_dir)
125
92
 
126
93
    def test_get_parent(self):
127
94
        self.assertIs(None, self.git_branch.get_parent())
128
95
 
129
96
    def test_get_stacked_on_url(self):
130
 
        self.assertRaises(errors.UnstackableBranchFormat, 
131
 
            self.git_branch.get_stacked_on_url)
 
97
        self.assertIs(None, self.git_branch.get_stacked_on_url())
132
98
 
133
99
    def test_get_physical_lock_status(self):
134
100
        self.assertFalse(self.git_branch.get_physical_lock_status())
142
108
 
143
109
    def test_get_format_description(self):
144
110
        self.assertEquals("Git Branch", self.format.get_format_description())
145
 
 
146
 
 
147
 
 
148
 
class BranchTests(tests.TestCaseInTempDir):
149
 
 
150
 
    def make_onerev_branch(self):
151
 
        os.mkdir("d")
152
 
        os.chdir("d")
153
 
        GitRepo.init('.')
154
 
        bb = tests.GitBranchBuilder()
155
 
        bb.set_file("foobar", "foo\nbar\n", False)
156
 
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
157
 
        gitsha = bb.finish()[mark]
158
 
        os.chdir("..")
159
 
        return "d", gitsha
160
 
 
161
 
    def clone_git_branch(self, from_url, to_url):
162
 
        from_dir = BzrDir.open(from_url)
163
 
        to_dir = from_dir.sprout(to_url)
164
 
        return to_dir.open_branch()
165
 
 
166
 
    def test_single_rev(self):
167
 
        path, gitsha = self.make_onerev_branch()
168
 
        oldrepo = Repository.open(path)
169
 
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
170
 
        newbranch = self.clone_git_branch(path, "f")
171
 
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
172
 
 
173
 
    def test_sprouted_tags(self):
174
 
        path, gitsha = self.make_onerev_branch()
175
 
        os.chdir(path)
176
 
        tests.run_git("tag", "lala")
177
 
        os.chdir(self.test_dir)
178
 
        oldrepo = Repository.open(path)
179
 
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
180
 
        newbranch = self.clone_git_branch(path, "f")
181
 
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
182
 
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
183
 
 
184
 
 
185
 
class ForeignTestsBranchFactory(object):
186
 
 
187
 
    def make_empty_branch(self, transport):
188
 
        return LocalGitBzrDirFormat().initialize_on_transport(transport).open_branch()
189
 
 
190
 
    make_branch = make_empty_branch