/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 NEWS entry about hg-git support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Tests for interfacing with a Git Branch"""
 
19
 
 
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
    )
 
41
 
 
42
from bzrlib.plugins.git import (
 
43
    branch,
 
44
    tests,
 
45
    )
 
46
from bzrlib.plugins.git.mapping import (
 
47
    default_mapping,
 
48
    )
 
49
 
 
50
 
 
51
class TestGitBranch(tests.TestCaseInTempDir):
 
52
 
 
53
    _test_needs_features = [tests.GitCommandFeature]
 
54
 
 
55
    def test_open_existing(self):
 
56
        GitRepo.init('.')
 
57
 
 
58
        thebranch = Branch.open('.')
 
59
        self.assertIsInstance(thebranch, branch.GitBranch)
 
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
 
 
66
    def test_last_revision_is_null(self):
 
67
        GitRepo.init('.')
 
68
 
 
69
        thebranch = Branch.open('.')
 
70
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
 
71
        self.assertEqual((0, revision.NULL_REVISION),
 
72
                         thebranch.last_revision_info())
 
73
 
 
74
    def simple_commit_a(self):
 
75
        GitRepo.init('.')
 
76
        self.build_tree(['a'])
 
77
        tests.run_git('add', 'a')
 
78
        tests.run_git('commit', '-m', 'a')
 
79
 
 
80
    def test_last_revision_is_valid(self):
 
81
        self.simple_commit_a()
 
82
        head = tests.run_git('rev-parse', 'HEAD').strip()
 
83
 
 
84
        thebranch = Branch.open('.')
 
85
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
 
86
                         thebranch.last_revision())
 
87
 
 
88
    def test_revision_history(self):
 
89
        self.simple_commit_a()
 
90
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
91
        self.build_tree(['b'])
 
92
        tests.run_git('add', 'b')
 
93
        tests.run_git('commit', '-m', 'b')
 
94
        revb = tests.run_git('rev-parse', 'HEAD').strip()
 
95
 
 
96
        thebranch = Branch.open('.')
 
97
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
 
98
                         thebranch.revision_history())
 
99
 
 
100
    def test_tag_annotated(self):
 
101
        self.simple_commit_a()
 
102
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
103
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
 
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
 
 
116
        
 
117
 
 
118
class TestWithGitBranch(tests.TestCaseWithTransport):
 
119
 
 
120
    def setUp(self):
 
121
        tests.TestCaseWithTransport.setUp(self)
 
122
        dulwich.repo.Repo.create(self.test_dir)
 
123
        self.git_branch = Branch.open(self.test_dir)
 
124
 
 
125
    def test_get_parent(self):
 
126
        self.assertIs(None, self.git_branch.get_parent())
 
127
 
 
128
    def test_get_stacked_on_url(self):
 
129
        self.assertRaises(errors.UnstackableBranchFormat, 
 
130
            self.git_branch.get_stacked_on_url)
 
131
 
 
132
    def test_get_physical_lock_status(self):
 
133
        self.assertFalse(self.git_branch.get_physical_lock_status())
 
134
 
 
135
 
 
136
class TestGitBranchFormat(tests.TestCase):
 
137
 
 
138
    def setUp(self):
 
139
        super(TestGitBranchFormat, self).setUp()
 
140
        self.format = branch.GitBranchFormat()
 
141
 
 
142
    def test_get_format_description(self):
 
143
        self.assertEquals("Git Branch", self.format.get_format_description())
 
144
 
 
145
 
 
146
 
 
147
class BranchTests(tests.TestCaseInTempDir):
 
148
 
 
149
    def make_onerev_branch(self):
 
150
        os.mkdir("d")
 
151
        os.chdir("d")
 
152
        GitRepo.init('.')
 
153
        bb = tests.GitBranchBuilder()
 
154
        bb.set_file("foobar", "foo\nbar\n", False)
 
155
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
156
        gitsha = bb.finish()[mark]
 
157
        os.chdir("..")
 
158
        return "d", gitsha
 
159
 
 
160
    def clone_git_branch(self, from_url, to_url):
 
161
        from_dir = BzrDir.open(from_url)
 
162
        to_dir = from_dir.sprout(to_url)
 
163
        return to_dir.open_branch()
 
164
 
 
165
    def test_single_rev(self):
 
166
        path, gitsha = self.make_onerev_branch()
 
167
        oldrepo = Repository.open(path)
 
168
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
169
        newbranch = self.clone_git_branch(path, "f")
 
170
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
 
171
 
 
172
    def test_sprouted_tags(self):
 
173
        path, gitsha = self.make_onerev_branch()
 
174
        os.chdir(path)
 
175
        tests.run_git("tag", "lala")
 
176
        os.chdir(self.test_dir)
 
177
        oldrepo = Repository.open(path)
 
178
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
179
        newbranch = self.clone_git_branch(path, "f")
 
180
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
 
181
        self.assertEquals([revid], newbranch.repository.all_revision_ids())