1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for interfacing with a Git Repository"""
from bzrlib import (
errors,
inventory,
revision,
)
from bzrlib.repository import Repository
from bzrlib.plugins.git import (
dir,
git,
repository,
tests,
)
from bzrlib.plugins.git.mapping import default_mapping
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
"""Feature tests for GitRepository."""
_test_needs_features = [tests.GitCommandFeature]
def test_open_existing(self):
tests.run_git('init')
repo = Repository.open('.')
self.assertIsInstance(repo, repository.GitRepository)
def test_has_git_repo(self):
tests.run_git('init')
repo = Repository.open('.')
self.assertIsInstance(repo._git, git.repo.Repo)
def test_get_revision(self):
# GitRepository.get_revision gives a Revision object.
# Create a git repository with a revision.
tests.run_git('init')
builder = tests.GitBranchBuilder()
builder.set_file('a', 'text for a\n', False)
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
mapping = builder.finish()
commit_id = mapping[commit_handle]
# Get the corresponding Revision object.
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
repo = Repository.open('.')
rev = repo.get_revision(revid)
self.assertIsInstance(rev, revision.Revision)
def test_get_revision_unknown(self):
tests.run_git('init')
repo = Repository.open('.')
self.assertRaises(errors.NoSuchRevision, repo.get_revision, "bla")
def simple_commit(self):
# Create a git repository with some interesting files in a revision.
tests.run_git('init')
builder = tests.GitBranchBuilder()
builder.set_file('data', 'text\n', False)
builder.set_file('executable', 'content', True)
builder.set_link('link', 'broken')
builder.set_file('subdir/subfile', 'subdir text\n', False)
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message',
timestamp=1205433193)
mapping = builder.finish()
return mapping[commit_handle]
def test_revision_tree(self):
commit_id = self.simple_commit()
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
repo = Repository.open('.')
tree = repo.revision_tree(revid)
self.assertEquals(tree.get_revision_id(), revid)
self.assertEquals("text\n", tree.get_file_text(tree.path2id("data")))
def test_get_inventory(self):
# GitRepository.get_inventory gives a GitInventory object with
# plausible entries for typical cases.
commit_id = self.simple_commit()
# Get the corresponding Inventory object.
revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
repo = Repository.open('.')
inv = repo.get_inventory(revid)
self.assertIsInstance(inv, inventory.Inventory)
printed_inv = '\n'.join(
repr((path, entry.executable, entry))
for path, entry in inv.iter_entries())
self.assertEqualDiff(
printed_inv,
"('', False, InventoryDirectory('TREE_ROOT', u'', parent_id=None,"
" revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
"(u'data', False, InventoryFile('data', u'data',"
" parent_id='TREE_ROOT',"
" sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5))\n"
"(u'executable', True, InventoryFile('executable', u'executable',"
" parent_id='TREE_ROOT',"
" sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7))\n"
"(u'link', False, InventoryLink('link', u'link',"
" parent_id='TREE_ROOT', revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
"(u'subdir', False, InventoryDirectory('subdir', u'subdir',"
" parent_id='TREE_ROOT', revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
"(u'subdir/subfile', False, InventoryFile('subdir/subfile',"
" u'subfile', parent_id='subdir',"
" sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12))")
class TestGitRepository(tests.TestCaseWithTransport):
def setUp(self):
tests.TestCaseWithTransport.setUp(self)
git.repo.Repo.create(self.test_dir)
self.git_repo = Repository.open(self.test_dir)
def test_supports_rich_root(self):
# GitRepository.supports_rich_root is False, at least for now.
repo = self.git_repo
self.assertEqual(repo.supports_rich_root(), False)
def test_get_signature_text(self):
self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
def test_has_signature_for_revision_id(self):
self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
def test_all_revision_ids_none(self):
self.assertEquals(set(), self.git_repo.all_revision_ids())
def test_get_ancestry_null(self):
self.assertEquals([None], self.git_repo.get_ancestry(revision.NULL_REVISION))
def assertIsNullInventory(self, inv):
self.assertEqual(inv.root, None)
self.assertEqual(inv.revision_id, revision.NULL_REVISION)
self.assertEqual(list(inv.iter_entries()), [])
def test_get_inventory_none(self):
# GitRepository.get_inventory(None) returns the null inventory.
repo = self.git_repo
inv = repo.get_inventory(revision.NULL_REVISION)
self.assertIsNullInventory(inv)
def test_revision_tree_none(self):
# GitRepository.revision_tree(None) returns the null tree.
repo = self.git_repo
tree = repo.revision_tree(revision.NULL_REVISION)
self.assertEqual(tree.get_revision_id(), revision.NULL_REVISION)
self.assertIsNullInventory(tree.inventory)
def test_get_parent_map_null(self):
self.assertEquals({revision.NULL_REVISION: ()},
self.git_repo.get_parent_map([revision.NULL_REVISION]))
class GitRepositoryFormat(tests.TestCase):
def setUp(self):
super(GitRepositoryFormat, self).setUp()
self.format = repository.GitFormat()
def test_get_format_description(self):
self.assertEquals("Git Repository", self.format.get_format_description())
|