50
50
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
51
51
"""Feature tests for GitRepository."""
54
builder = tests.GitBranchBuilder()
55
builder.set_file('a', 'text for a\n', False)
56
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
57
mapping = builder.finish()
58
return mapping[commit_handle]
53
_test_needs_features = [tests.GitCommandFeature]
60
55
def test_open_existing(self):
61
56
GitRepo.init(self.test_dir)
67
62
GitRepo.init(self.test_dir)
69
64
repo = Repository.open('.')
70
self.assertIsInstance(repo._git, dulwich.repo.BaseRepo)
72
def test_has_revision(self):
73
GitRepo.init(self.test_dir)
74
commit_id = self._do_commit()
75
repo = Repository.open('.')
76
self.assertFalse(repo.has_revision('foobar'))
77
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
78
self.assertTrue(repo.has_revision(revid))
80
def test_has_revisions(self):
81
GitRepo.init(self.test_dir)
82
commit_id = self._do_commit()
83
repo = Repository.open('.')
84
self.assertEquals(set(), repo.has_revisions(['foobar']))
85
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
86
self.assertEquals(set([revid]), repo.has_revisions(['foobar', revid]))
65
self.assertIsInstance(repo._git, dulwich.repo.Repo)
88
67
def test_get_revision(self):
89
68
# GitRepository.get_revision gives a Revision object.
91
70
# Create a git repository with a revision.
92
71
GitRepo.init(self.test_dir)
93
commit_id = self._do_commit()
72
builder = tests.GitBranchBuilder()
73
builder.set_file('a', 'text for a\n', False)
74
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
75
mapping = builder.finish()
76
commit_id = mapping[commit_handle]
95
78
# Get the corresponding Revision object.
96
79
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
117
100
mapping = builder.finish()
118
101
return mapping[commit_handle]
121
commit_id = self.simple_commit()
122
repo = Repository.open('.')
125
103
def test_revision_tree(self):
126
104
commit_id = self.simple_commit()
127
105
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
150
128
" revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n"
151
129
"(u'data', False, GitInventoryFile('data', u'data',"
152
130
" parent_id='TREE_ROOT',"
153
" sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n"
131
" sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5, revision=git-v1:69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n"
154
132
"(u'executable', True, GitInventoryFile('executable', u'executable',"
155
133
" parent_id='TREE_ROOT',"
156
" sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n"
134
" sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7, revision=git-v1:69c39cfa65962f3cf16b9b3eb08a15954e9d8590))\n"
157
135
"(u'link', False, GitInventoryLink('link', u'link',"
158
136
" parent_id='TREE_ROOT', revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n"
159
137
"(u'subdir', False, GitInventoryDirectory('subdir', u'subdir',"
160
138
" parent_id='TREE_ROOT', revision='"+default_mapping.revision_id_foreign_to_bzr("69c39cfa65962f3cf16b9b3eb08a15954e9d8590")+"'))\n"
161
139
"(u'subdir/subfile', False, GitInventoryFile('subdir/subfile',"
162
140
" u'subfile', parent_id='subdir',"
163
" sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12, revision="+default_mapping.revid_prefix+":69c39cfa65962f3cf16b9b3eb08a15954e9d8590))")
141
" sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12, revision=git-v1:69c39cfa65962f3cf16b9b3eb08a15954e9d8590))")
166
144
class TestGitRepository(tests.TestCaseWithTransport):
168
def _do_commit(self):
169
builder = tests.GitBranchBuilder()
170
builder.set_file('a', 'text for a\n', False)
171
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
172
mapping = builder.finish()
173
return mapping[commit_handle]
176
147
tests.TestCaseWithTransport.setUp(self)
177
148
dulwich.repo.Repo.create(self.test_dir)
188
159
self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
190
161
def test_all_revision_ids_none(self):
191
self.assertEquals(set([]), self.git_repo.all_revision_ids())
193
def test_all_revision_ids(self):
194
commit_id = self._do_commit()
196
set([default_mapping.revision_id_foreign_to_bzr(commit_id)]),
197
self.git_repo.all_revision_ids())
162
self.assertEquals(set([revision.NULL_REVISION]), self.git_repo.all_revision_ids())
199
164
def test_get_ancestry_null(self):
200
165
self.assertEquals([None, revision.NULL_REVISION], self.git_repo.get_ancestry(revision.NULL_REVISION))
249
214
def object_iter(self):
250
215
store = BazaarObjectStore(self.bzr_tree.branch.repository, default_mapping)
251
store_iterator = MissingObjectsIterator(store, self.bzr_tree.branch.repository)
252
return store, store_iterator
216
return MissingObjectsIterator(store, self.bzr_tree.branch.repository)
254
218
def import_rev(self, revid, parent_lookup=None):
255
store, store_iter = self.object_iter()
256
store._cache.idmap.start_write_group()
258
return store_iter.import_revision(revid, roundtrip=False)
260
store._cache.idmap.abort_write_group()
263
store._cache.idmap.commit_write_group()
219
return self.object_iter().import_revision(revid)
265
221
def test_pointless(self):
266
222
revid = self.bzr_tree.commit("pointless", timestamp=1205433193,