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 ( |
22 |
repository, |
|
23 |
revision, |
|
24 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
25 |
|
26 |
from bzrlib.plugins.git import tests |
|
|
0.200.27
by David Allouche
Flat is better than nested, remove the gitlib hierarchy. |
27 |
from bzrlib.plugins.git import ( |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
28 |
git_repository, |
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
29 |
ids, |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
30 |
model, |
31 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
32 |
|
33 |
||
34 |
class TestGitRepository(tests.TestCaseInTempDir): |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
35 |
"""Feature tests for GitRepository.""" |
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
36 |
|
37 |
_test_needs_features = [tests.GitCommandFeature] |
|
38 |
||
39 |
def test_open_existing(self): |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
40 |
tests.run_git('init') |
41 |
||
42 |
repo = repository.Repository.open('.') |
|
43 |
self.assertIsInstance(repo, git_repository.GitRepository) |
|
44 |
||
45 |
def test_has_git_model(self): |
|
46 |
tests.run_git('init') |
|
47 |
||
48 |
repo = repository.Repository.open('.') |
|
49 |
self.assertIsInstance(repo._git, model.GitModel) |
|
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
50 |
|
51 |
def test_revision_graph(self): |
|
52 |
tests.run_git('init') |
|
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
53 |
builder = tests.GitBranchBuilder() |
|
0.200.31
by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value. |
54 |
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. |
55 |
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. |
56 |
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. |
57 |
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. |
58 |
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. |
59 |
commit3_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'b', |
60 |
base=commit1_handle) |
|
61 |
commit4_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'merge', |
|
62 |
base=commit3_handle, |
|
63 |
merge=[commit2_handle],) |
|
64 |
||
65 |
mapping = builder.finish() |
|
66 |
commit1_id = mapping[commit1_handle] |
|
67 |
commit2_id = mapping[commit2_handle] |
|
68 |
commit3_id = mapping[commit3_handle] |
|
69 |
commit4_id = mapping[commit4_handle] |
|
70 |
||
71 |
revisions = tests.run_git('rev-list', '--topo-order', |
|
72 |
commit4_id) |
|
73 |
revisions = revisions.splitlines() |
|
74 |
self.assertEqual([commit4_id, commit2_id, commit3_id, commit1_id], |
|
75 |
revisions) |
|
76 |
bzr_revisions = [ids.convert_revision_id_git_to_bzr(r) for r in revisions] |
|
77 |
graph = {bzr_revisions[0]:[bzr_revisions[2], bzr_revisions[1]], |
|
78 |
bzr_revisions[1]:[bzr_revisions[3]], |
|
79 |
bzr_revisions[2]:[bzr_revisions[3]], |
|
80 |
bzr_revisions[3]:[], |
|
|
0.200.21
by John Arbash Meinel
Fix Repository.get_revision_graph() |
81 |
}
|
82 |
||
83 |
repo = repository.Repository.open('.') |
|
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
84 |
self.assertEqual(graph, repo.get_revision_graph(bzr_revisions[0])) |
85 |
self.assertEqual({bzr_revisions[3]:[]}, |
|
86 |
repo.get_revision_graph(bzr_revisions[3])) |
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
87 |
|
88 |
def test_get_revision(self): |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
89 |
# GitRepository.get_revision gives a Revision object.
|
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
90 |
|
91 |
# Create a git repository with a revision.
|
|
92 |
tests.run_git('init') |
|
93 |
builder = tests.GitBranchBuilder() |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
94 |
builder.set_file('a', 'text for a\n', False) |
|
0.200.29
by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes. |
95 |
commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message') |
96 |
mapping = builder.finish() |
|
97 |
commit_id = mapping[commit_handle] |
|
98 |
||
99 |
# Get the corresponding Revision object.
|
|
100 |
revid = ids.convert_revision_id_git_to_bzr(commit_id) |
|
101 |
repo = repository.Repository.open('.') |
|
102 |
rev = repo.get_revision(revid) |
|
103 |
self.assertIsInstance(rev, revision.Revision) |
|
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
104 |
|
105 |
||
106 |
class TestGitRepositoryParseRev(tests.TestCase): |
|
107 |
"""Unit tests for GitRepository._parse_rev.""" |
|
108 |
||
109 |
def test_base_commit(self): |
|
110 |
# GitRepository._parse_rev works for a simple base commit.
|
|
111 |
rev = git_repository.GitRepository._parse_rev([ |
|
112 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
113 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
114 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
115 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
116 |
"\n", |
|
117 |
" message\n", |
|
118 |
"\x00"]) |
|
119 |
self.assertEqual( |
|
120 |
rev.revision_id, 'git1r-873a8ae0d682b0e63e9795bc53056d32ed3de93f') |
|
121 |
self.assertEqual(rev.parent_ids, []) |
|
122 |
self.assertEqual(rev.committer, 'Joe Foo <joe@foo.com>') |
|
123 |
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. |
124 |
self.assertEqual(rev.timezone, 3600.0) |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
125 |
self.assertEqual(rev.message, 'message\n') |
126 |
self.assertEqual( |
|
127 |
rev.properties, |
|
128 |
{'git-tree-id': 'aaff74984cccd156a469afa7d9ab10e4777beb24', |
|
129 |
'author': 'Jane Bar <jane@bar.com>', |
|
130 |
'git-author-timestamp': '1198784533', |
|
131 |
'git-author-timezone': '+0200'}) |
|
132 |
||
133 |
def test_merge_commit(self): |
|
134 |
# Multi-parent commits (merges) are parsed correctly.
|
|
135 |
rev = git_repository.GitRepository._parse_rev([ |
|
136 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
137 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
138 |
"parent 263ed20f0d4898be994404ca418bafe8e89abb8a\n", |
|
139 |
"parent 546563eb8f3e94a557f3bb779b6e5a2bd9658752\n", |
|
140 |
"parent 3116d42db7b5c5e69e58f651721e179791479c23\n", |
|
141 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
142 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
143 |
"\n", |
|
144 |
" message\n", |
|
145 |
"\x00"]) |
|
146 |
# Git records merges in the same way as bzr. The first parent is the
|
|
147 |
# commit base, the following parents are the ordered merged revisions.
|
|
148 |
self.assertEqual( |
|
149 |
rev.parent_ids, |
|
150 |
['git1r-263ed20f0d4898be994404ca418bafe8e89abb8a', |
|
151 |
'git1r-546563eb8f3e94a557f3bb779b6e5a2bd9658752', |
|
152 |
'git1r-3116d42db7b5c5e69e58f651721e179791479c23']) |
|
153 |
||
154 |
def test_redundant_spaces(self): |
|
155 |
# Redundant spaces in author and committer are preserved.
|
|
156 |
rev = git_repository.GitRepository._parse_rev([ |
|
157 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
158 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
159 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
160 |
"committer Joe Foo <joe@foo.com> 1198784532 +0100\n", |
|
161 |
"\n", |
|
162 |
" message\n", |
|
163 |
"\x00"]) |
|
164 |
self.assertEqual(rev.committer, ' Joe Foo <joe@foo.com> ') |
|
165 |
self.assertEqual( |
|
166 |
rev.properties['author'], ' Jane Bar <jane@bar.com> ') |
|
167 |
||
168 |
def test_no_committer(self): |
|
169 |
# If committer is not set, then author is used.
|
|
170 |
#
|
|
171 |
# Folks in #git say that git fsck would likely accept commits that do
|
|
172 |
# not set committer, but that author is a mandatory value.
|
|
173 |
rev = git_repository.GitRepository._parse_rev([ |
|
174 |
"873a8ae0d682b0e63e9795bc53056d32ed3de93f\n", |
|
175 |
"tree aaff74984cccd156a469afa7d9ab10e4777beb24\n", |
|
176 |
"author Jane Bar <jane@bar.com> 1198784533 +0200\n", |
|
177 |
"\n", |
|
178 |
" message\n", |
|
179 |
"\x00"]) |
|
180 |
self.assertEqual(rev.committer, 'Jane Bar <jane@bar.com>') |
|
181 |
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. |
182 |
self.assertEqual(rev.timezone, 7200.0) |
|
0.200.32
by David Allouche
Rewrite GitRepository._parse_rev, with unit tests. |
183 |
self.assertEqual(rev.properties['author'], 'Jane Bar <jane@bar.com>') |
184 |
self.assertEqual(rev.properties['git-author-timestamp'], '1198784533') |
|
185 |
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. |
186 |
|
187 |
def test_parse_tz(self): |
|
188 |
# Simple tests for the _parse_tz helper.
|
|
189 |
parse_tz = git_repository.GitRepository._parse_tz |
|
190 |
self.assertEqual(parse_tz('+0000'), 0.0) |
|
191 |
self.assertEqual(parse_tz('+0001'), 60.0) |
|
192 |
self.assertEqual(parse_tz('-0001'), -60.0) |
|
193 |
self.assertEqual(parse_tz('+0100'), 3600.0) |
|
194 |
self.assertEqual(parse_tz('-0100'), -3600.0) |
|
195 |
self.assertEqual(parse_tz('+9959'), 359940.0) |
|
196 |
self.assertEqual(parse_tz('-9959'), -359940.0) |
|
197 |