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,  | 
|
| 
0.247.1
by Michael Hudson
 test  | 
34  | 
InterBranch,  | 
| 
0.200.270
by Jelmer Vernooij
 add tests for branch sprouting.  | 
35  | 
    )
 | 
36  | 
from bzrlib.bzrdir import (  | 
|
37  | 
BzrDir,  | 
|
38  | 
    )
 | 
|
39  | 
from bzrlib.repository import (  | 
|
40  | 
Repository,  | 
|
41  | 
    )
 | 
|
| 
0.200.18
by John Arbash Meinel
 Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.  | 
42  | 
|
| 
0.200.27
by David Allouche
 Flat is better than nested, remove the gitlib hierarchy.  | 
43  | 
from bzrlib.plugins.git import (  | 
| 
0.243.1
by Jelmer Vernooij
 Use foreign branch testing infrastructure.  | 
44  | 
LocalGitBzrDirFormat,  | 
| 
0.200.94
by Jelmer Vernooij
 Eliminate (duplicate) git_ prefix.  | 
45  | 
branch,  | 
| 
0.200.97
by Jelmer Vernooij
 use mapping object.  | 
46  | 
tests,  | 
| 
0.200.20
by John Arbash Meinel
 All tests are passing again  | 
47  | 
    )
 | 
| 
0.243.1
by Jelmer Vernooij
 Use foreign branch testing infrastructure.  | 
48  | 
from bzrlib.plugins.git.mapping import (  | 
49  | 
default_mapping,  | 
|
50  | 
    )
 | 
|
| 
0.200.123
by Jelmer Vernooij
 Use central git module.  | 
51  | 
|
| 
0.200.18
by John Arbash Meinel
 Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.  | 
52  | 
|
53  | 
class TestGitBranch(tests.TestCaseInTempDir):  | 
|
54  | 
||
55  | 
_test_needs_features = [tests.GitCommandFeature]  | 
|
56  | 
||
57  | 
def test_open_existing(self):  | 
|
| 
0.200.447
by Jelmer Vernooij
 Rely less on command-line git.  | 
58  | 
GitRepo.init('.')  | 
| 
0.200.769
by Jelmer Vernooij
 Cope with open_branch() actually checking whether there is a branch present.  | 
59  | 
d = BzrDir.open('.')  | 
60  | 
thebranch = d.create_branch()  | 
|
| 
0.200.94
by Jelmer Vernooij
 Eliminate (duplicate) git_ prefix.  | 
61  | 
self.assertIsInstance(thebranch, branch.GitBranch)  | 
| 
0.200.19
by John Arbash Meinel
 More refactoring. Add some direct tests for GitModel.  | 
62  | 
|
| 
0.200.412
by Jelmer Vernooij
 Implement GitBranch.__repr__.  | 
63  | 
def test_repr(self):  | 
| 
0.200.447
by Jelmer Vernooij
 Rely less on command-line git.  | 
64  | 
GitRepo.init('.')  | 
| 
0.200.769
by Jelmer Vernooij
 Cope with open_branch() actually checking whether there is a branch present.  | 
65  | 
d = BzrDir.open('.')  | 
66  | 
thebranch = d.create_branch()  | 
|
| 
0.200.770
by Jelmer Vernooij
 Proper branch names.  | 
67  | 
self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))  | 
| 
0.200.412
by Jelmer Vernooij
 Implement GitBranch.__repr__.  | 
68  | 
|
| 
0.200.19
by John Arbash Meinel
 More refactoring. Add some direct tests for GitModel.  | 
69  | 
def test_last_revision_is_null(self):  | 
| 
0.200.447
by Jelmer Vernooij
 Rely less on command-line git.  | 
70  | 
GitRepo.init('.')  | 
| 
0.200.769
by Jelmer Vernooij
 Cope with open_branch() actually checking whether there is a branch present.  | 
71  | 
thedir = BzrDir.open('.')  | 
72  | 
thebranch = thedir.create_branch()  | 
|
| 
0.200.19
by John Arbash Meinel
 More refactoring. Add some direct tests for GitModel.  | 
73  | 
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())  | 
74  | 
self.assertEqual((0, revision.NULL_REVISION),  | 
|
75  | 
thebranch.last_revision_info())  | 
|
| 
0.200.20
by John Arbash Meinel
 All tests are passing again  | 
76  | 
|
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
77  | 
def simple_commit_a(self):  | 
| 
0.200.447
by Jelmer Vernooij
 Rely less on command-line git.  | 
78  | 
GitRepo.init('.')  | 
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
79  | 
self.build_tree(['a'])  | 
80  | 
tests.run_git('add', 'a')  | 
|
81  | 
tests.run_git('commit', '-m', 'a')  | 
|
82  | 
||
| 
0.200.20
by John Arbash Meinel
 All tests are passing again  | 
83  | 
def test_last_revision_is_valid(self):  | 
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
84  | 
self.simple_commit_a()  | 
| 
0.200.20
by John Arbash Meinel
 All tests are passing again  | 
85  | 
head = tests.run_git('rev-parse', 'HEAD').strip()  | 
| 
0.200.94
by Jelmer Vernooij
 Eliminate (duplicate) git_ prefix.  | 
86  | 
thebranch = Branch.open('.')  | 
| 
0.200.104
by Jelmer Vernooij
 Use bzr-foreign function names for converting between git and bzr revids.  | 
87  | 
self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),  | 
| 
0.200.20
by John Arbash Meinel
 All tests are passing again  | 
88  | 
thebranch.last_revision())  | 
| 
0.200.58
by Jelmer Vernooij
 Fix remaining tests.  | 
89  | 
|
90  | 
def test_revision_history(self):  | 
|
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
91  | 
self.simple_commit_a()  | 
| 
0.200.59
by Jelmer Vernooij
 Add more tests, fix revision history.  | 
92  | 
reva = tests.run_git('rev-parse', 'HEAD').strip()  | 
93  | 
self.build_tree(['b'])  | 
|
94  | 
tests.run_git('add', 'b')  | 
|
95  | 
tests.run_git('commit', '-m', 'b')  | 
|
96  | 
revb = tests.run_git('rev-parse', 'HEAD').strip()  | 
|
| 
0.200.58
by Jelmer Vernooij
 Fix remaining tests.  | 
97  | 
|
| 
0.200.94
by Jelmer Vernooij
 Eliminate (duplicate) git_ prefix.  | 
98  | 
thebranch = Branch.open('.')  | 
| 
0.200.104
by Jelmer Vernooij
 Use bzr-foreign function names for converting between git and bzr revids.  | 
99  | 
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],  | 
| 
0.200.58
by Jelmer Vernooij
 Fix remaining tests.  | 
100  | 
thebranch.revision_history())  | 
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
101  | 
|
| 
0.200.271
by Jelmer Vernooij
 Stop importing tags as branches as part of git-import.  | 
102  | 
def test_tag_annotated(self):  | 
| 
0.200.82
by Jelmer Vernooij
 Support listing tags.  | 
103  | 
self.simple_commit_a()  | 
104  | 
reva = tests.run_git('rev-parse', 'HEAD').strip()  | 
|
105  | 
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.  | 
106  | 
thebranch = Branch.open('.')  | 
107  | 
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},  | 
|
108  | 
thebranch.tags.get_tag_dict())  | 
|
109  | 
||
110  | 
def test_tag(self):  | 
|
111  | 
self.simple_commit_a()  | 
|
112  | 
reva = tests.run_git('rev-parse', 'HEAD').strip()  | 
|
113  | 
tests.run_git('tag', '-m', 'add tag', 'foo')  | 
|
114  | 
thebranch = Branch.open('.')  | 
|
115  | 
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},  | 
|
116  | 
thebranch.tags.get_tag_dict())  | 
|
117  | 
||
| 
0.200.58
by Jelmer Vernooij
 Fix remaining tests.  | 
118  | 
|
| 
0.200.66
by Jelmer Vernooij
 Implement branch.get_parent().  | 
119  | 
|
120  | 
class TestWithGitBranch(tests.TestCaseWithTransport):  | 
|
121  | 
||
122  | 
def setUp(self):  | 
|
123  | 
tests.TestCaseWithTransport.setUp(self)  | 
|
| 
0.200.411
by Jelmer Vernooij
 Stop pretending dulwich has the same api as python-git.  | 
124  | 
dulwich.repo.Repo.create(self.test_dir)  | 
| 
0.200.769
by Jelmer Vernooij
 Cope with open_branch() actually checking whether there is a branch present.  | 
125  | 
d = BzrDir.open(self.test_dir)  | 
126  | 
self.git_branch = d.create_branch()  | 
|
| 
0.200.66
by Jelmer Vernooij
 Implement branch.get_parent().  | 
127  | 
|
128  | 
def test_get_parent(self):  | 
|
129  | 
self.assertIs(None, self.git_branch.get_parent())  | 
|
| 
0.200.67
by Jelmer Vernooij
 Implement Branch.get_stacked_on_url.  | 
130  | 
|
131  | 
def test_get_stacked_on_url(self):  | 
|
| 
0.200.633
by Jelmer Vernooij
 Fix Branch.get_stacked_on_url() test.  | 
132  | 
self.assertRaises(errors.UnstackableBranchFormat,  | 
133  | 
self.git_branch.get_stacked_on_url)  | 
|
| 
0.200.70
by Jelmer Vernooij
 Implement GitBranchFormat.get_format_description.  | 
134  | 
|
| 
0.200.72
by Jelmer Vernooij
 Implement Branch.get_physical_lock_status.  | 
135  | 
def test_get_physical_lock_status(self):  | 
136  | 
self.assertFalse(self.git_branch.get_physical_lock_status())  | 
|
137  | 
||
| 
0.200.70
by Jelmer Vernooij
 Implement GitBranchFormat.get_format_description.  | 
138  | 
|
139  | 
class TestGitBranchFormat(tests.TestCase):  | 
|
140  | 
||
141  | 
def setUp(self):  | 
|
142  | 
super(TestGitBranchFormat, self).setUp()  | 
|
| 
0.200.94
by Jelmer Vernooij
 Eliminate (duplicate) git_ prefix.  | 
143  | 
self.format = branch.GitBranchFormat()  | 
| 
0.200.70
by Jelmer Vernooij
 Implement GitBranchFormat.get_format_description.  | 
144  | 
|
145  | 
def test_get_format_description(self):  | 
|
146  | 
self.assertEquals("Git Branch", self.format.get_format_description())  | 
|
| 
0.200.270
by Jelmer Vernooij
 add tests for branch sprouting.  | 
147  | 
|
148  | 
||
149  | 
||
| 
0.200.271
by Jelmer Vernooij
 Stop importing tags as branches as part of git-import.  | 
150  | 
class BranchTests(tests.TestCaseInTempDir):  | 
| 
0.200.270
by Jelmer Vernooij
 add tests for branch sprouting.  | 
151  | 
|
152  | 
def make_onerev_branch(self):  | 
|
153  | 
os.mkdir("d")  | 
|
154  | 
os.chdir("d")  | 
|
| 
0.200.447
by Jelmer Vernooij
 Rely less on command-line git.  | 
155  | 
GitRepo.init('.')  | 
| 
0.200.270
by Jelmer Vernooij
 add tests for branch sprouting.  | 
156  | 
bb = tests.GitBranchBuilder()  | 
157  | 
bb.set_file("foobar", "foo\nbar\n", False)  | 
|
158  | 
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")  | 
|
159  | 
gitsha = bb.finish()[mark]  | 
|
160  | 
os.chdir("..")  | 
|
161  | 
return "d", gitsha  | 
|
162  | 
||
| 
0.247.1
by Michael Hudson
 test  | 
163  | 
def make_tworev_branch(self):  | 
164  | 
os.mkdir("d")  | 
|
165  | 
os.chdir("d")  | 
|
166  | 
GitRepo.init('.')  | 
|
167  | 
bb = tests.GitBranchBuilder()  | 
|
168  | 
bb.set_file("foobar", "foo\nbar\n", False)  | 
|
169  | 
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")  | 
|
170  | 
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")  | 
|
171  | 
marks = bb.finish()  | 
|
172  | 
os.chdir("..")  | 
|
173  | 
return "d", (marks[mark1], marks[mark2])  | 
|
174  | 
||
| 
0.200.270
by Jelmer Vernooij
 add tests for branch sprouting.  | 
175  | 
def clone_git_branch(self, from_url, to_url):  | 
176  | 
from_dir = BzrDir.open(from_url)  | 
|
177  | 
to_dir = from_dir.sprout(to_url)  | 
|
178  | 
return to_dir.open_branch()  | 
|
179  | 
||
180  | 
def test_single_rev(self):  | 
|
181  | 
path, gitsha = self.make_onerev_branch()  | 
|
182  | 
oldrepo = Repository.open(path)  | 
|
183  | 
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)  | 
|
184  | 
newbranch = self.clone_git_branch(path, "f")  | 
|
185  | 
self.assertEquals([revid], newbranch.repository.all_revision_ids())  | 
|
| 
0.200.271
by Jelmer Vernooij
 Stop importing tags as branches as part of git-import.  | 
186  | 
|
187  | 
def test_sprouted_tags(self):  | 
|
188  | 
path, gitsha = self.make_onerev_branch()  | 
|
189  | 
os.chdir(path)  | 
|
190  | 
tests.run_git("tag", "lala")  | 
|
191  | 
os.chdir(self.test_dir)  | 
|
192  | 
oldrepo = Repository.open(path)  | 
|
193  | 
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)  | 
|
194  | 
newbranch = self.clone_git_branch(path, "f")  | 
|
195  | 
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())  | 
|
196  | 
self.assertEquals([revid], newbranch.repository.all_revision_ids())  | 
|
| 
0.243.1
by Jelmer Vernooij
 Use foreign branch testing infrastructure.  | 
197  | 
|
| 
0.247.1
by Michael Hudson
 test  | 
198  | 
def test_interbranch_pull(self):  | 
199  | 
path, (gitsha1, gitsha2) = self.make_tworev_branch()  | 
|
200  | 
oldrepo = Repository.open(path)  | 
|
201  | 
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)  | 
|
202  | 
newbranch = self.make_branch('g')  | 
|
203  | 
inter_branch = InterBranch.get(Branch.open(path), newbranch)  | 
|
204  | 
inter_branch.pull()  | 
|
205  | 
self.assertEquals(revid2, newbranch.last_revision())  | 
|
206  | 
||
| 
0.247.5
by Michael Hudson
 test and fix for noop pull case  | 
207  | 
def test_interbranch_pull_noop(self):  | 
208  | 
path, (gitsha1, gitsha2) = self.make_tworev_branch()  | 
|
209  | 
oldrepo = Repository.open(path)  | 
|
210  | 
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)  | 
|
211  | 
newbranch = self.make_branch('g')  | 
|
212  | 
inter_branch = InterBranch.get(Branch.open(path), newbranch)  | 
|
213  | 
inter_branch.pull()  | 
|
214  | 
        # This is basically "assertNotRaises"
 | 
|
215  | 
inter_branch.pull()  | 
|
216  | 
self.assertEquals(revid2, newbranch.last_revision())  | 
|
217  | 
||
| 
0.247.3
by Michael Hudson
 oh, so it wasn't (particularly) wrong, but it was a bit obscure  | 
218  | 
def test_interbranch_pull_stop_revision(self):  | 
219  | 
path, (gitsha1, gitsha2) = self.make_tworev_branch()  | 
|
220  | 
oldrepo = Repository.open(path)  | 
|
221  | 
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)  | 
|
222  | 
newbranch = self.make_branch('g')  | 
|
223  | 
inter_branch = InterBranch.get(Branch.open(path), newbranch)  | 
|
224  | 
inter_branch.pull(stop_revision=revid1)  | 
|
225  | 
self.assertEquals(revid1, newbranch.last_revision())  | 
|
226  | 
||
| 
0.247.1
by Michael Hudson
 test  | 
227  | 
def test_interbranch_limited_pull(self):  | 
228  | 
path, (gitsha1, gitsha2) = self.make_tworev_branch()  | 
|
229  | 
oldrepo = Repository.open(path)  | 
|
230  | 
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)  | 
|
231  | 
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)  | 
|
232  | 
newbranch = self.make_branch('g')  | 
|
233  | 
inter_branch = InterBranch.get(Branch.open(path), newbranch)  | 
|
234  | 
inter_branch.pull(limit=1)  | 
|
235  | 
self.assertEquals(revid1, newbranch.last_revision())  | 
|
236  | 
inter_branch.pull(limit=1)  | 
|
237  | 
self.assertEquals(revid2, newbranch.last_revision())  | 
|
238  | 
||
| 
0.243.1
by Jelmer Vernooij
 Use foreign branch testing infrastructure.  | 
239  | 
|
240  | 
class ForeignTestsBranchFactory(object):  | 
|
241  | 
||
242  | 
def make_empty_branch(self, transport):  | 
|
| 
0.200.769
by Jelmer Vernooij
 Cope with open_branch() actually checking whether there is a branch present.  | 
243  | 
d = LocalGitBzrDirFormat().initialize_on_transport(transport)  | 
244  | 
return d.create_branch()  | 
|
| 
0.243.1
by Jelmer Vernooij
 Use foreign branch testing infrastructure.  | 
245  | 
|
246  | 
make_branch = make_empty_branch  | 
|
| 
0.200.770
by Jelmer Vernooij
 Proper branch names.  | 
247  | 
|
248  | 
||
249  | 
class BranchNameRefConversionTests(tests.TestCase):  | 
|
250  | 
||
251  | 
def test_head(self):  | 
|
252  | 
self.assertEquals("HEAD", branch.ref_to_branch_name("HEAD"))  | 
|
253  | 
self.assertEquals("HEAD", branch.branch_name_to_ref("HEAD"))  | 
|
254  | 
||
255  | 
def test_tag(self):  | 
|
256  | 
self.assertRaises(ValueError, branch.ref_to_branch_name, "refs/tags/FOO")  | 
|
257  | 
||
258  | 
def test_branch(self):  | 
|
259  | 
self.assertEquals("frost", branch.ref_to_branch_name("refs/heads/frost"))  | 
|
260  | 
self.assertEquals("refs/heads/frost", branch.branch_name_to_ref("frost"))  |