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