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