/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

Add basic infrastructure for dpush.

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