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 |
||
17 |
"""Tests for interfacing with a Git Repository"""
|
|
18 |
||
|
0.200.445
by Jelmer Vernooij
Import dulwich as dulwich, not as git. |
19 |
import dulwich |
|
0.200.447
by Jelmer Vernooij
Rely less on command-line git. |
20 |
from dulwich.repo import ( |
21 |
Repo as GitRepo, |
|
22 |
)
|
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
23 |
import os |
24 |
||
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
25 |
from bzrlib import ( |
|
0.200.61
by Jelmer Vernooij
Fix tests. |
26 |
errors, |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
27 |
inventory, |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
28 |
revision, |
29 |
)
|
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
30 |
from bzrlib.repository import ( |
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
31 |
InterRepository, |
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
32 |
Repository, |
33 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
34 |
|
|
0.200.27
by David Allouche
Flat is better than nested, remove the gitlib hierarchy. |
35 |
from bzrlib.plugins.git import ( |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
36 |
dir, |
37 |
repository, |
|
|
0.200.97
by Jelmer Vernooij
use mapping object. |
38 |
tests, |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
39 |
)
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
40 |
from bzrlib.plugins.git.mapping import ( |
41 |
default_mapping, |
|
42 |
)
|
|
|
0.235.2
by Jelmer Vernooij
Fix tests. |
43 |
from bzrlib.plugins.git.object_store import ( |
44 |
BazaarObjectStore, |
|
45 |
)
|
|
|
0.200.368
by Jelmer Vernooij
Cope with more granular timezones. |
46 |
from bzrlib.plugins.git.push import ( |
47 |
MissingObjectsIterator, |
|
48 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
49 |
|
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
50 |
class TestGitRepositoryFeatures(tests.TestCaseInTempDir): |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
51 |
"""Feature tests for GitRepository.""" |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
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(self.test_dir) |
|
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 |
repo = Repository.open('.') |
59 |
self.assertIsInstance(repo, repository.GitRepository) |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
60 |
|
|
0.200.56
by Jelmer Vernooij
Switch to using GitPython rather than our own in-house stuff. |
61 |
def test_has_git_repo(self): |
|
0.200.447
by Jelmer Vernooij
Rely less on command-line git. |
62 |
GitRepo.init(self.test_dir) |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
63 |
|
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
64 |
repo = Repository.open('.') |
|
0.200.445
by Jelmer Vernooij
Import dulwich as dulwich, not as git. |
65 |
self.assertIsInstance(repo._git, dulwich.repo.Repo) |
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
66 |
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
67 |
def test_get_revision(self): |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
68 |
# GitRepository.get_revision gives a Revision object.
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
69 |
|
70 |
# Create a git repository with a revision.
|
|
|
0.200.447
by Jelmer Vernooij
Rely less on command-line git. |
71 |
GitRepo.init(self.test_dir) |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
72 |
builder = tests.GitBranchBuilder() |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
73 |
builder.set_file('a', 'text for a\n', False) |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
74 |
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message') |
75 |
mapping = builder.finish() |
|
76 |
commit_id = mapping[commit_handle] |
|
77 |
||
78 |
# Get the corresponding Revision object.
|
|
|
0.200.104
by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids. |
79 |
revid = default_mapping.revision_id_foreign_to_bzr(commit_id) |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
80 |
repo = Repository.open('.') |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
81 |
rev = repo.get_revision(revid) |
82 |
self.assertIsInstance(rev, revision.Revision) |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
83 |
|
|
0.200.106
by Jelmer Vernooij
Test that getting an unknown revision fails. |
84 |
def test_get_revision_unknown(self): |
|
0.200.447
by Jelmer Vernooij
Rely less on command-line git. |
85 |
GitRepo.init(self.test_dir) |
|
0.200.106
by Jelmer Vernooij
Test that getting an unknown revision fails. |
86 |
|
87 |
repo = Repository.open('.') |
|
88 |
self.assertRaises(errors.NoSuchRevision, repo.get_revision, "bla") |
|
89 |
||
|
0.200.79
by Jelmer Vernooij
Implement RevisionTree.get_revision_id(). |
90 |
def simple_commit(self): |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
91 |
# Create a git repository with some interesting files in a revision.
|
|
0.200.447
by Jelmer Vernooij
Rely less on command-line git. |
92 |
GitRepo.init(self.test_dir) |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
93 |
builder = tests.GitBranchBuilder() |
94 |
builder.set_file('data', 'text\n', False) |
|
95 |
builder.set_file('executable', 'content', True) |
|
96 |
builder.set_link('link', 'broken') |
|
97 |
builder.set_file('subdir/subfile', 'subdir text\n', False) |
|
|
0.204.4
by James Westby
Make the inventory test match what the code produces. |
98 |
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message', |
99 |
timestamp=1205433193) |
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
100 |
mapping = builder.finish() |
|
0.200.79
by Jelmer Vernooij
Implement RevisionTree.get_revision_id(). |
101 |
return mapping[commit_handle] |
102 |
||
103 |
def test_revision_tree(self): |
|
104 |
commit_id = self.simple_commit() |
|
|
0.200.104
by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids. |
105 |
revid = default_mapping.revision_id_foreign_to_bzr(commit_id) |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
106 |
repo = Repository.open('.') |
|
0.200.79
by Jelmer Vernooij
Implement RevisionTree.get_revision_id(). |
107 |
tree = repo.revision_tree(revid) |
108 |
self.assertEquals(tree.get_revision_id(), revid) |
|
|
0.200.88
by Jelmer Vernooij
Fix RevisionTree.get_file_text(). |
109 |
self.assertEquals("text\n", tree.get_file_text(tree.path2id("data"))) |
|
0.200.79
by Jelmer Vernooij
Implement RevisionTree.get_revision_id(). |
110 |
|
111 |
def test_get_inventory(self): |
|
112 |
# GitRepository.get_inventory gives a GitInventory object with
|
|
113 |
# plausible entries for typical cases.
|
|
114 |
||
115 |
commit_id = self.simple_commit() |
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
116 |
|
117 |
# Get the corresponding Inventory object.
|
|
|
0.200.104
by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids. |
118 |
revid = default_mapping.revision_id_foreign_to_bzr(commit_id) |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
119 |
repo = Repository.open('.') |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
120 |
inv = repo.get_inventory(revid) |
121 |
self.assertIsInstance(inv, inventory.Inventory) |
|
122 |
printed_inv = '\n'.join( |
|
123 |
repr((path, entry.executable, entry)) |
|
124 |
for path, entry in inv.iter_entries()) |
|
125 |
self.assertEqualDiff( |
|
126 |
printed_inv, |
|
|
0.200.394
by Jelmer Vernooij
Fix expected test output. |
127 |
"('', False, GitInventoryDirectory('TREE_ROOT', u'', parent_id=None,"
|
|
0.200.190
by Jelmer Vernooij
Bless current mapping as v1. |
128 |
" revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n" |
|
0.200.394
by Jelmer Vernooij
Fix expected test output. |
129 |
"(u'data', False, GitInventoryFile('data', u'data',"
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
130 |
" parent_id='TREE_ROOT',"
|
|
0.200.655
by Jelmer Vernooij
Fix test to be mapping-independent. |
131 |
" sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n" |
|
0.200.394
by Jelmer Vernooij
Fix expected test output. |
132 |
"(u'executable', True, GitInventoryFile('executable', u'executable',"
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
133 |
" parent_id='TREE_ROOT',"
|
|
0.200.655
by Jelmer Vernooij
Fix test to be mapping-independent. |
134 |
" sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n" |
|
0.200.394
by Jelmer Vernooij
Fix expected test output. |
135 |
"(u'link', False, GitInventoryLink('link', u'link',"
|
136 |
" parent_id='TREE_ROOT', revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n" |
|
137 |
"(u'subdir', False, GitInventoryDirectory('subdir', u'subdir',"
|
|
138 |
" parent_id='TREE_ROOT', revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n" |
|
139 |
"(u'subdir/subfile', False, GitInventoryFile('subdir/subfile',"
|
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
140 |
" u'subfile', parent_id='subdir',"
|
|
0.200.655
by Jelmer Vernooij
Fix test to be mapping-independent. |
141 |
" sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))") |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
142 |
|
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
143 |
|
|
0.204.2
by James Westby
Switch to TestCaseWithTransport so that the cache dir can be |
144 |
class TestGitRepository(tests.TestCaseWithTransport): |
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
145 |
|
146 |
def setUp(self): |
|
|
0.204.2
by James Westby
Switch to TestCaseWithTransport so that the cache dir can be |
147 |
tests.TestCaseWithTransport.setUp(self) |
|
0.200.445
by Jelmer Vernooij
Import dulwich as dulwich, not as git. |
148 |
dulwich.repo.Repo.create(self.test_dir) |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
149 |
self.git_repo = Repository.open(self.test_dir) |
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
150 |
|
|
0.200.40
by David Allouche
GitRepository.supports_rich_root() => False |
151 |
def test_supports_rich_root(self): |
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
152 |
repo = self.git_repo |
|
0.200.131
by Jelmer Vernooij
Fix all tests but two, use rich roots by default. |
153 |
self.assertEqual(repo.supports_rich_root(), True) |
|
0.200.40
by David Allouche
GitRepository.supports_rich_root() => False |
154 |
|
|
0.200.60
by Jelmer Vernooij
Support signature functions. |
155 |
def test_get_signature_text(self): |
|
0.200.61
by Jelmer Vernooij
Fix tests. |
156 |
self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION) |
|
0.200.60
by Jelmer Vernooij
Support signature functions. |
157 |
|
158 |
def test_has_signature_for_revision_id(self): |
|
159 |
self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION)) |
|
160 |
||
|
0.200.75
by Jelmer Vernooij
Implement Repository.all_revision_ids(). |
161 |
def test_all_revision_ids_none(self): |
|
0.200.712
by Jelmer Vernooij
all_revision_ids() on an empty repo returns an empty set. |
162 |
self.assertEquals(set([]), self.git_repo.all_revision_ids()) |
|
0.200.75
by Jelmer Vernooij
Implement Repository.all_revision_ids(). |
163 |
|
|
0.200.65
by Jelmer Vernooij
Implement get_ancestry properly. |
164 |
def test_get_ancestry_null(self): |
|
0.200.237
by Jelmer Vernooij
Fix get_ancestry() contents. |
165 |
self.assertEquals([None, revision.NULL_REVISION], self.git_repo.get_ancestry(revision.NULL_REVISION)) |
|
0.200.65
by Jelmer Vernooij
Implement get_ancestry properly. |
166 |
|
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
167 |
def assertIsNullInventory(self, inv): |
168 |
self.assertEqual(inv.root, None) |
|
169 |
self.assertEqual(inv.revision_id, revision.NULL_REVISION) |
|
170 |
self.assertEqual(list(inv.iter_entries()), []) |
|
171 |
||
172 |
def test_get_inventory_none(self): |
|
173 |
# GitRepository.get_inventory(None) returns the null inventory.
|
|
174 |
repo = self.git_repo |
|
|
0.200.57
by Jelmer Vernooij
Fix more tests. |
175 |
inv = repo.get_inventory(revision.NULL_REVISION) |
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
176 |
self.assertIsNullInventory(inv) |
177 |
||
178 |
def test_revision_tree_none(self): |
|
179 |
# GitRepository.revision_tree(None) returns the null tree.
|
|
180 |
repo = self.git_repo |
|
|
0.200.57
by Jelmer Vernooij
Fix more tests. |
181 |
tree = repo.revision_tree(revision.NULL_REVISION) |
|
0.202.2
by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data. |
182 |
self.assertEqual(tree.get_revision_id(), revision.NULL_REVISION) |
183 |
self.assertIsNullInventory(tree.inventory) |
|
184 |
||
|
0.200.77
by Jelmer Vernooij
Handle NULL_REVISION in get_parent_map. |
185 |
def test_get_parent_map_null(self): |
186 |
self.assertEquals({revision.NULL_REVISION: ()}, |
|
187 |
self.git_repo.get_parent_map([revision.NULL_REVISION])) |
|
188 |
||
|
0.200.71
by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description. |
189 |
|
190 |
class GitRepositoryFormat(tests.TestCase): |
|
191 |
||
192 |
def setUp(self): |
|
193 |
super(GitRepositoryFormat, self).setUp() |
|
|
0.200.290
by Jelmer Vernooij
Fix tests. |
194 |
self.format = repository.GitRepositoryFormat() |
|
0.200.71
by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description. |
195 |
|
196 |
def test_get_format_description(self): |
|
197 |
self.assertEquals("Git Repository", self.format.get_format_description()) |
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
198 |
|
199 |
||
200 |
class RevisionGistImportTests(tests.TestCaseWithTransport): |
|
201 |
||
202 |
def setUp(self): |
|
203 |
tests.TestCaseWithTransport.setUp(self) |
|
204 |
self.git_path = os.path.join(self.test_dir, "git") |
|
205 |
os.mkdir(self.git_path) |
|
|
0.200.445
by Jelmer Vernooij
Import dulwich as dulwich, not as git. |
206 |
dulwich.repo.Repo.create(self.git_path) |
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
207 |
self.git_repo = Repository.open(self.git_path) |
208 |
self.bzr_tree = self.make_branch_and_tree("bzr") |
|
209 |
||
|
0.200.357
by Jelmer Vernooij
Move push code to push.py. |
210 |
def get_inter(self): |
211 |
return InterRepository.get(self.bzr_tree.branch.repository, |
|
212 |
self.git_repo) |
|
213 |
||
|
0.200.368
by Jelmer Vernooij
Cope with more granular timezones. |
214 |
def object_iter(self): |
|
0.235.2
by Jelmer Vernooij
Fix tests. |
215 |
store = BazaarObjectStore(self.bzr_tree.branch.repository, default_mapping) |
|
0.200.749
by Jelmer Vernooij
Avoid storing entries for trees in the cache, use blobs instead |
216 |
store_iterator = MissingObjectsIterator(store, self.bzr_tree.branch.repository) |
217 |
return store, store_iterator |
|
|
0.200.368
by Jelmer Vernooij
Cope with more granular timezones. |
218 |
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
219 |
def import_rev(self, revid, parent_lookup=None): |
|
0.200.749
by Jelmer Vernooij
Avoid storing entries for trees in the cache, use blobs instead |
220 |
store, store_iter = self.object_iter() |
221 |
store._idmap.start_write_group() |
|
222 |
try: |
|
223 |
return store_iter.import_revision(revid) |
|
224 |
except: |
|
225 |
store._idmap.abort_write_group() |
|
226 |
raise
|
|
227 |
else: |
|
228 |
store._idmap.commit_write_group() |
|
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
229 |
|
230 |
def test_pointless(self): |
|
|
0.200.257
by Jelmer Vernooij
Add more details for commit, to avoid checksum from changing. |
231 |
revid = self.bzr_tree.commit("pointless", timestamp=1205433193, |
|
0.200.362
by Jelmer Vernooij
Fix tests. |
232 |
timezone=0, |
|
0.200.257
by Jelmer Vernooij
Add more details for commit, to avoid checksum from changing. |
233 |
committer="Jelmer Vernooij <jelmer@samba.org>") |
|
0.200.443
by Jelmer Vernooij
Fix tests. |
234 |
self.assertEquals("2caa8094a5b794961cd9bf582e3e2bb090db0b14", |
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
235 |
self.import_rev(revid)) |
|
0.200.443
by Jelmer Vernooij
Fix tests. |
236 |
self.assertEquals("2caa8094a5b794961cd9bf582e3e2bb090db0b14", |
|
0.200.256
by Jelmer Vernooij
Add tests for import_revision_gist. |
237 |
self.import_rev(revid)) |
|
0.200.658
by Jelmer Vernooij
Provide right infrastructure for foreign repository tests from bzrlib. |
238 |
|
239 |
||
240 |
class ForeignTestsRepositoryFactory(object): |
|
241 |
||
242 |
def make_repository(self, transport): |
|
243 |
return dir.LocalGitBzrDirFormat().initialize_on_transport(transport).open_repository() |