/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
17
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
18
"""Tests for interfacing with a Git Branch"""
19
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
20
21
import dulwich
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
22
from dulwich.repo import (
23
    Repo as GitRepo,
24
    )
25
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
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
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
40
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
41
from bzrlib.plugins.git import (
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
42
    LocalGitBzrDirFormat,
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
43
    branch,
0.200.97 by Jelmer Vernooij
use mapping object.
44
    tests,
0.200.20 by John Arbash Meinel
All tests are passing again
45
    )
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
46
from bzrlib.plugins.git.mapping import (
47
    default_mapping,
48
    )
0.200.123 by Jelmer Vernooij
Use central git module.
49
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
50
51
class TestGitBranch(tests.TestCaseInTempDir):
52
53
    _test_needs_features = [tests.GitCommandFeature]
54
55
    def test_open_existing(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
56
        GitRepo.init('.')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
57
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
58
        thebranch = Branch.open('.')
59
        self.assertIsInstance(thebranch, branch.GitBranch)
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
60
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
61
    def test_repr(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
62
        GitRepo.init('.')
0.200.412 by Jelmer Vernooij
Implement GitBranch.__repr__.
63
        thebranch = Branch.open('.')
64
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
65
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
66
    def test_last_revision_is_null(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
67
        GitRepo.init('.')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
68
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
69
        thebranch = Branch.open('.')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
70
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
71
        self.assertEqual((0, revision.NULL_REVISION),
72
                         thebranch.last_revision_info())
0.200.20 by John Arbash Meinel
All tests are passing again
73
0.200.82 by Jelmer Vernooij
Support listing tags.
74
    def simple_commit_a(self):
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
75
        GitRepo.init('.')
0.200.82 by Jelmer Vernooij
Support listing tags.
76
        self.build_tree(['a'])
77
        tests.run_git('add', 'a')
78
        tests.run_git('commit', '-m', 'a')
79
0.200.20 by John Arbash Meinel
All tests are passing again
80
    def test_last_revision_is_valid(self):
0.200.82 by Jelmer Vernooij
Support listing tags.
81
        self.simple_commit_a()
0.200.20 by John Arbash Meinel
All tests are passing again
82
        head = tests.run_git('rev-parse', 'HEAD').strip()
83
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
84
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
85
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
0.200.20 by John Arbash Meinel
All tests are passing again
86
                         thebranch.last_revision())
0.200.58 by Jelmer Vernooij
Fix remaining tests.
87
88
    def test_revision_history(self):
0.200.82 by Jelmer Vernooij
Support listing tags.
89
        self.simple_commit_a()
0.200.59 by Jelmer Vernooij
Add more tests, fix revision history.
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()
0.200.58 by Jelmer Vernooij
Fix remaining tests.
95
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
96
        thebranch = Branch.open('.')
0.200.104 by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids.
97
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
0.200.58 by Jelmer Vernooij
Fix remaining tests.
98
                         thebranch.revision_history())
0.200.82 by Jelmer Vernooij
Support listing tags.
99
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
100
    def test_tag_annotated(self):
0.200.82 by Jelmer Vernooij
Support listing tags.
101
        self.simple_commit_a()
102
        reva = tests.run_git('rev-parse', 'HEAD').strip()
103
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
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
0.200.58 by Jelmer Vernooij
Fix remaining tests.
116
        
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
117
118
class TestWithGitBranch(tests.TestCaseWithTransport):
119
120
    def setUp(self):
121
        tests.TestCaseWithTransport.setUp(self)
0.200.411 by Jelmer Vernooij
Stop pretending dulwich has the same api as python-git.
122
        dulwich.repo.Repo.create(self.test_dir)
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
123
        self.git_branch = Branch.open(self.test_dir)
0.200.66 by Jelmer Vernooij
Implement branch.get_parent().
124
125
    def test_get_parent(self):
126
        self.assertIs(None, self.git_branch.get_parent())
0.200.67 by Jelmer Vernooij
Implement Branch.get_stacked_on_url.
127
128
    def test_get_stacked_on_url(self):
129
        self.assertIs(None, self.git_branch.get_stacked_on_url())
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
130
0.200.72 by Jelmer Vernooij
Implement Branch.get_physical_lock_status.
131
    def test_get_physical_lock_status(self):
132
        self.assertFalse(self.git_branch.get_physical_lock_status())
133
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
134
135
class TestGitBranchFormat(tests.TestCase):
136
137
    def setUp(self):
138
        super(TestGitBranchFormat, self).setUp()
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
139
        self.format = branch.GitBranchFormat()
0.200.70 by Jelmer Vernooij
Implement GitBranchFormat.get_format_description.
140
141
    def test_get_format_description(self):
142
        self.assertEquals("Git Branch", self.format.get_format_description())
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
143
144
145
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
146
class BranchTests(tests.TestCaseInTempDir):
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
147
148
    def make_onerev_branch(self):
149
        os.mkdir("d")
150
        os.chdir("d")
0.200.447 by Jelmer Vernooij
Rely less on command-line git.
151
        GitRepo.init('.')
0.200.270 by Jelmer Vernooij
add tests for branch sprouting.
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())
0.200.271 by Jelmer Vernooij
Stop importing tags as branches as part of git-import.
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())
0.243.1 by Jelmer Vernooij
Use foreign branch testing infrastructure.
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