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 |
||
19 |
import subprocess |
|
20 |
||
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
21 |
from bzrlib import ( |
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
22 |
inventory, |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
23 |
repository, |
24 |
revision, |
|
25 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
26 |
|
27 |
from bzrlib.plugins.git import tests |
|
|
0.200.27
by David Allouche
Flat is better than nested, remove the gitlib hierarchy. |
28 |
from bzrlib.plugins.git import ( |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
29 |
git_repository, |
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
30 |
ids, |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
31 |
model, |
32 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
33 |
|
34 |
||
35 |
class TestGitRepository(tests.TestCaseInTempDir): |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
36 |
"""Feature tests for GitRepository.""" |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
37 |
|
38 |
_test_needs_features = [tests.GitCommandFeature] |
|
39 |
||
40 |
def test_open_existing(self): |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
41 |
tests.run_git('init') |
42 |
||
43 |
repo = repository.Repository.open('.') |
|
44 |
self.assertIsInstance(repo, git_repository.GitRepository) |
|
45 |
||
46 |
def test_has_git_model(self): |
|
47 |
tests.run_git('init') |
|
48 |
||
49 |
repo = repository.Repository.open('.') |
|
50 |
self.assertIsInstance(repo._git, model.GitModel) |
|
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
51 |
|
52 |
def test_revision_graph(self): |
|
53 |
tests.run_git('init') |
|
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
54 |
builder = tests.GitBranchBuilder() |
|
0.200.31
by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value. |
55 |
builder.set_file('a', 'text for a\n', False) |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
56 |
commit1_handle = builder.commit('Joe Foo <joe@foo.com>', u'message') |
|
0.200.31
by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value. |
57 |
builder.set_file('a', 'new a\n', False) |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
58 |
commit2_handle = builder.commit('Joe Foo <joe@foo.com>', u'new a') |
|
0.200.31
by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value. |
59 |
builder.set_file('b', 'text for b\n', False) |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
60 |
commit3_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'b', |
61 |
base=commit1_handle) |
|
62 |
commit4_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'merge', |
|
63 |
base=commit3_handle, |
|
64 |
merge=[commit2_handle],) |
|
65 |
||
66 |
mapping = builder.finish() |
|
67 |
commit1_id = mapping[commit1_handle] |
|
68 |
commit2_id = mapping[commit2_handle] |
|
69 |
commit3_id = mapping[commit3_handle] |
|
70 |
commit4_id = mapping[commit4_handle] |
|
71 |
||
72 |
revisions = tests.run_git('rev-list', '--topo-order', |
|
73 |
commit4_id) |
|
74 |
revisions = revisions.splitlines() |
|
75 |
self.assertEqual([commit4_id, commit2_id, commit3_id, commit1_id], |
|
76 |
revisions) |
|
77 |
bzr_revisions = [ids.convert_revision_id_git_to_bzr(r) for r in revisions] |
|
78 |
graph = {bzr_revisions[0]:[bzr_revisions[2], bzr_revisions[1]], |
|
79 |
bzr_revisions[1]:[bzr_revisions[3]], |
|
80 |
bzr_revisions[2]:[bzr_revisions[3]], |
|
81 |
bzr_revisions[3]:[], |
|
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
82 |
}
|
83 |
||
84 |
repo = repository.Repository.open('.') |
|
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
85 |
self.assertEqual(graph, repo.get_revision_graph(bzr_revisions[0])) |
86 |
self.assertEqual({bzr_revisions[3]:[]}, |
|
87 |
repo.get_revision_graph(bzr_revisions[3])) |
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
88 |
|
89 |
def test_get_revision(self): |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
90 |
# GitRepository.get_revision gives a Revision object.
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
91 |
|
92 |
# Create a git repository with a revision.
|
|
93 |
tests.run_git('init') |
|
94 |
builder = tests.GitBranchBuilder() |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
95 |
builder.set_file('a', 'text for a\n', False) |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
96 |
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message') |
97 |
mapping = builder.finish() |
|
98 |
commit_id = mapping[commit_handle] |
|
99 |
||
100 |
# Get the corresponding Revision object.
|
|
101 |
revid = ids.convert_revision_id_git_to_bzr(commit_id) |
|
102 |
repo = repository.Repository.open('.') |
|
103 |
rev = repo.get_revision(revid) |
|
104 |
self.assertIsInstance(rev, revision.Revision) |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
105 |
|
|
0.200.38
by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster. |
106 |
def test_get_inventory(self): |
107 |
# GitRepository.get_inventory gives a GitInventory object with
|
|
108 |
# plausible entries for typical cases.
|
|
109 |
||
110 |
# Create a git repository with some interesting files in a revision.
|
|
111 |
tests.run_git('init') |
|
112 |
builder = tests.GitBranchBuilder() |
|
113 |
builder.set_file('data', 'text\n', False) |
|
114 |
builder.set_file('executable', 'content', True) |
|
115 |
builder.set_link('link', 'broken') |
|
116 |
builder.set_file('subdir/subfile', 'subdir text\n', False) |
|
117 |
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message') |
|
118 |
mapping = builder.finish() |
|
119 |
commit_id = mapping[commit_handle] |
|
120 |
||
121 |
# Get the corresponding Inventory object.
|
|
122 |
revid = ids.convert_revision_id_git_to_bzr(commit_id) |
|
123 |
repo = repository.Repository.open('.') |
|
124 |
inv = repo.get_inventory(revid) |
|
125 |
self.assertIsInstance(inv, inventory.Inventory) |
|
126 |
entries = list(inv.iter_entries()) |
|
127 |
printed_inv = '\n'.join( |
|
128 |
repr((path, entry.executable, entry)) |
|
129 |
for path, entry in inv.iter_entries()) |
|
130 |
self.assertEqualDiff( |
|
131 |
printed_inv, |
|
132 |
"('', False, InventoryDirectory('TREE_ROOT', u'', parent_id=None,"
|
|
133 |
" revision=None))\n" |
|
134 |
"(u'data', False, InventoryFile('data', u'data',"
|
|
135 |
" parent_id='TREE_ROOT',"
|
|
136 |
" sha1='8e27be7d6154a1f68ea9160ef0e18691d20560dc', len=None))\n" |
|
137 |
"(u'executable', True, InventoryFile('executable', u'executable',"
|
|
138 |
" parent_id='TREE_ROOT',"
|
|
139 |
" sha1='6b584e8ece562ebffc15d38808cd6b98fc3d97ea', len=None))\n" |
|
140 |
"(u'link', False, InventoryLink('link', u'link',"
|
|
141 |
" parent_id='TREE_ROOT', revision=None))\n" |
|
142 |
"(u'subdir', False, InventoryDirectory('subdir', u'subdir',"
|
|
143 |
" parent_id='TREE_ROOT', revision=None))\n" |
|
144 |
"(u'subdir/subfile', False, InventoryFile('subdir/subfile',"
|
|
145 |
" u'subfile', parent_id='subdir',"
|
|
146 |
" sha1='0ddb53cbe2dd209f550dd8d7f1287a5ed9b1ee8b', len=None))") |
|
147 |
||
|
0.200.40
by David Allouche
GitRepository.supports_rich_root() => False |
148 |
def test_supports_rich_root(self): |
149 |
# GitRepository.supports_rich_root is False, at least for now.
|
|
150 |
tests.run_git('init') |
|
151 |
repo = repository.Repository.open('.') |
|
152 |
self.assertEqual(repo.supports_rich_root(), False) |
|
153 |
||
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
154 |
|
155 |
class TestGitRepositoryParseRev(tests.TestCase): |
|
156 |
"""Unit tests for GitRepository._parse_rev.""" |
|
157 |
||
158 |
def test_base_commit(self): |
|
159 |
# GitRepository._parse_rev works for a simple base commit.
|
|
160 |
rev = git_repository.GitRepository._parse_rev([ |
|
161 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
162 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
163 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
164 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
165 |
"\n", |
|
166 |
" message\n", |
|
167 |
"\x00"]) |
|
168 |
self.assertEqual( |
|
169 |
rev.revision_id, 'git1r-873a8ae0d682b0e63e9795bc53056d32ed3de93f') |
|
170 |
self.assertEqual(rev.parent_ids, []) |
|
171 |
self.assertEqual(rev.committer, 'Joe Foo <joe@foo.com>') |
|
172 |
self.assertEqual(rev.timestamp, 1198784532.0) |
|
|
0.200.35
by David Allouche
GitRepository._parse_rev sets Revision.timezone to a float instead of a string. |
173 |
self.assertEqual(rev.timezone, 3600.0) |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
174 |
self.assertEqual(rev.message, 'message\n') |
175 |
self.assertEqual( |
|
176 |
rev.properties, |
|
177 |
{'git-tree-id': 'aaff74984cccd156a469afa7d9ab10e4777beb24', |
|
178 |
'author': 'Jane Bar <jane@bar.com>', |
|
179 |
'git-author-timestamp': '1198784533', |
|
180 |
'git-author-timezone': '+0200'}) |
|
181 |
||
182 |
def test_merge_commit(self): |
|
183 |
# Multi-parent commits (merges) are parsed correctly.
|
|
184 |
rev = git_repository.GitRepository._parse_rev([ |
|
185 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
186 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
187 |
"parent 263ed20f0d4898be994404ca418bafe8e89abb8a\n", |
|
188 |
"parent 546563eb8f3e94a557f3bb779b6e5a2bd9658752\n", |
|
189 |
"parent 3116d42db7b5c5e69e58f651721e179791479c23\n", |
|
190 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
191 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
192 |
"\n", |
|
193 |
" message\n", |
|
194 |
"\x00"]) |
|
195 |
# Git records merges in the same way as bzr. The first parent is the
|
|
196 |
# commit base, the following parents are the ordered merged revisions.
|
|
197 |
self.assertEqual( |
|
198 |
rev.parent_ids, |
|
199 |
['git1r-263ed20f0d4898be994404ca418bafe8e89abb8a', |
|
200 |
'git1r-546563eb8f3e94a557f3bb779b6e5a2bd9658752', |
|
201 |
'git1r-3116d42db7b5c5e69e58f651721e179791479c23']) |
|
202 |
||
203 |
def test_redundant_spaces(self): |
|
204 |
# Redundant spaces in author and committer are preserved.
|
|
205 |
rev = git_repository.GitRepository._parse_rev([ |
|
206 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
207 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
208 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
209 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
210 |
"\n", |
|
211 |
" message\n", |
|
212 |
"\x00"]) |
|
213 |
self.assertEqual(rev.committer, ' Joe Foo <joe@foo.com> ') |
|
214 |
self.assertEqual( |
|
215 |
rev.properties['author'], ' Jane Bar <jane@bar.com> ') |
|
216 |
||
217 |
def test_no_committer(self): |
|
218 |
# If committer is not set, then author is used.
|
|
219 |
#
|
|
220 |
# Folks in #git say that git fsck would likely accept commits that do
|
|
221 |
# not set committer, but that author is a mandatory value.
|
|
222 |
rev = git_repository.GitRepository._parse_rev([ |
|
223 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
224 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
225 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
226 |
"\n", |
|
227 |
" message\n", |
|
228 |
"\x00"]) |
|
229 |
self.assertEqual(rev.committer, 'Jane Bar <jane@bar.com>') |
|
230 |
self.assertEqual(rev.timestamp, 1198784533.0) |
|
|
0.200.35
by David Allouche
GitRepository._parse_rev sets Revision.timezone to a float instead of a string. |
231 |
self.assertEqual(rev.timezone, 7200.0) |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
232 |
self.assertEqual(rev.properties['author'], 'Jane Bar <jane@bar.com>') |
233 |
self.assertEqual(rev.properties['git-author-timestamp'], '1198784533') |
|
234 |
self.assertEqual(rev.properties['git-author-timezone'], '+0200') |
|
|
0.200.35
by David Allouche
GitRepository._parse_rev sets Revision.timezone to a float instead of a string. |
235 |
|
236 |
def test_parse_tz(self): |
|
237 |
# Simple tests for the _parse_tz helper.
|
|
238 |
parse_tz = git_repository.GitRepository._parse_tz |
|
239 |
self.assertEqual(parse_tz('+0000'), 0.0) |
|
240 |
self.assertEqual(parse_tz('+0001'), 60.0) |
|
241 |
self.assertEqual(parse_tz('-0001'), -60.0) |
|
242 |
self.assertEqual(parse_tz('+0100'), 3600.0) |
|
243 |
self.assertEqual(parse_tz('-0100'), -3600.0) |
|
244 |
self.assertEqual(parse_tz('+9959'), 359940.0) |
|
245 |
self.assertEqual(parse_tz('-9959'), -359940.0) |
|
246 |