/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

  • Committer: Jelmer Vernooij
  • Date: 2009-10-12 09:41:06 UTC
  • mto: (0.200.644 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20091012094106-4ubc41ms0mr22v52
Use foreign branch testing infrastructure.

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