bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
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 |
"""Test our ability to build up test repositories"""
|
|
18 |
||
19 |
from cStringIO import StringIO |
|
20 |
||
0.200.992
by Jelmer Vernooij
Avoid invoking git directly. |
21 |
from dulwich.repo import Repo as GitRepo |
22 |
||
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
23 |
from bzrlib.plugins.git import tests |
24 |
||
25 |
||
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
26 |
class TestGitBranchBuilder(tests.TestCase): |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
27 |
|
28 |
def test__create_blob(self): |
|
29 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
30 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
31 |
self.assertEqual(1, builder._create_blob('foo\nbar\n')) |
32 |
self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n', |
|
33 |
stream.getvalue()) |
|
34 |
||
35 |
def test_set_file(self): |
|
36 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
37 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
38 |
builder.set_file('foobar', 'foo\nbar\n', False) |
39 |
self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n', |
|
40 |
stream.getvalue()) |
|
41 |
self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info) |
|
42 |
||
43 |
def test_set_file_unicode(self): |
|
44 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
45 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
46 |
builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False) |
47 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n', |
|
48 |
stream.getvalue()) |
|
49 |
self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info) |
|
50 |
||
0.200.36
by David Allouche
GitBranchBuilder now handles file names with newlines correctly. |
51 |
def test_set_file_newline(self): |
52 |
stream = StringIO() |
|
53 |
builder = tests.GitBranchBuilder(stream) |
|
54 |
builder.set_file(u'foo\nbar', 'contents\nbar\n', False) |
|
55 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n', |
|
56 |
stream.getvalue()) |
|
57 |
self.assertEqual(['M 100644 :1 "foo\\nbar"\n'], builder.commit_info) |
|
58 |
||
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
59 |
def test_set_file_executable(self): |
60 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
61 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
62 |
builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True) |
63 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n', |
|
64 |
stream.getvalue()) |
|
65 |
self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info) |
|
66 |
||
67 |
def test_set_link(self): |
|
68 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
69 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
70 |
builder.set_link(u'f\xb5/bar', 'link/contents') |
71 |
self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n', |
|
72 |
stream.getvalue()) |
|
73 |
self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info) |
|
74 |
||
0.200.36
by David Allouche
GitBranchBuilder now handles file names with newlines correctly. |
75 |
def test_set_link_newline(self): |
76 |
stream = StringIO() |
|
77 |
builder = tests.GitBranchBuilder(stream) |
|
78 |
builder.set_link(u'foo\nbar', 'link/contents') |
|
79 |
self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n', |
|
80 |
stream.getvalue()) |
|
81 |
self.assertEqual(['M 120000 :1 "foo\\nbar"\n'], builder.commit_info) |
|
82 |
||
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
83 |
def test_delete_entry(self): |
84 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
85 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
86 |
builder.delete_entry(u'path/to/f\xb5') |
87 |
self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info) |
|
88 |
||
0.200.36
by David Allouche
GitBranchBuilder now handles file names with newlines correctly. |
89 |
def test_delete_entry_newline(self): |
90 |
stream = StringIO() |
|
91 |
builder = tests.GitBranchBuilder(stream) |
|
92 |
builder.delete_entry(u'path/to/foo\nbar') |
|
93 |
self.assertEqual(['D "path/to/foo\\nbar"\n'], builder.commit_info) |
|
94 |
||
95 |
def test_encode_path(self): |
|
96 |
encode = tests.GitBranchBuilder._encode_path |
|
97 |
# Unicode is encoded to utf-8
|
|
98 |
self.assertEqual(encode(u'f\xb5'), 'f\xc2\xb5') |
|
99 |
# The name must be quoted if it starts by a double quote or contains a
|
|
100 |
# newline.
|
|
101 |
self.assertEqual(encode(u'"foo'), '"\\"foo"') |
|
102 |
self.assertEqual(encode(u'fo\no'), '"fo\\no"') |
|
103 |
# When the name is quoted, all backslash and quote chars must be
|
|
104 |
# escaped.
|
|
105 |
self.assertEqual(encode(u'fo\\o\nbar'), '"fo\\\\o\\nbar"') |
|
106 |
self.assertEqual(encode(u'fo"o"\nbar'), '"fo\\"o\\"\\nbar"') |
|
107 |
# Other control chars, such as \r, need not be escaped.
|
|
108 |
self.assertEqual(encode(u'foo\r\nbar'), '"foo\r\\nbar"') |
|
109 |
||
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
110 |
def test_add_and_commit(self): |
111 |
stream = StringIO() |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
112 |
builder = tests.GitBranchBuilder(stream) |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
113 |
|
114 |
builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False) |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
115 |
self.assertEqual(2, builder.commit('Joe Foo <joe@foo.com>', |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
116 |
u'committing f\xb5/bar', |
117 |
timestamp=1194586400, |
|
118 |
timezone='+0100')) |
|
119 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
120 |
'commit refs/heads/master\n' |
0.200.22
by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. |
121 |
'mark :2\n' |
122 |
'committer Joe Foo <joe@foo.com> 1194586400 +0100\n' |
|
123 |
'data 18\n' |
|
124 |
'committing f\xc2\xb5/bar' |
|
125 |
'\n' |
|
126 |
'M 100644 :1 f\xc2\xb5/bar\n' |
|
127 |
'\n', |
|
128 |
stream.getvalue()) |
|
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
129 |
|
130 |
def test_commit_base(self): |
|
131 |
stream = StringIO() |
|
132 |
builder = tests.GitBranchBuilder(stream) |
|
133 |
||
134 |
builder.set_file(u'foo', 'contents\nfoo\n', False) |
|
135 |
r1 = builder.commit('Joe Foo <joe@foo.com>', u'first', |
|
136 |
timestamp=1194586400) |
|
137 |
r2 = builder.commit('Joe Foo <joe@foo.com>', u'second', |
|
138 |
timestamp=1194586405) |
|
139 |
r3 = builder.commit('Joe Foo <joe@foo.com>', u'third', |
|
140 |
timestamp=1194586410, |
|
141 |
base=r1) |
|
142 |
||
143 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
144 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
145 |
'mark :2\n' |
146 |
'committer Joe Foo <joe@foo.com> 1194586400 +0000\n' |
|
147 |
'data 5\n' |
|
148 |
'first'
|
|
149 |
'\n' |
|
150 |
'M 100644 :1 foo\n' |
|
151 |
'\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
152 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
153 |
'mark :3\n' |
154 |
'committer Joe Foo <joe@foo.com> 1194586405 +0000\n' |
|
155 |
'data 6\n' |
|
156 |
'second'
|
|
157 |
'\n' |
|
158 |
'\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
159 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
160 |
'mark :4\n' |
161 |
'committer Joe Foo <joe@foo.com> 1194586410 +0000\n' |
|
162 |
'data 5\n' |
|
163 |
'third'
|
|
164 |
'\n' |
|
165 |
'from :2\n' |
|
166 |
'\n', stream.getvalue()) |
|
167 |
||
168 |
def test_commit_merge(self): |
|
169 |
stream = StringIO() |
|
170 |
builder = tests.GitBranchBuilder(stream) |
|
171 |
||
172 |
builder.set_file(u'foo', 'contents\nfoo\n', False) |
|
173 |
r1 = builder.commit('Joe Foo <joe@foo.com>', u'first', |
|
174 |
timestamp=1194586400) |
|
175 |
r2 = builder.commit('Joe Foo <joe@foo.com>', u'second', |
|
176 |
timestamp=1194586405) |
|
177 |
r3 = builder.commit('Joe Foo <joe@foo.com>', u'third', |
|
178 |
timestamp=1194586410, |
|
179 |
base=r1) |
|
180 |
r4 = builder.commit('Joe Foo <joe@foo.com>', u'Merge', |
|
181 |
timestamp=1194586415, |
|
182 |
merge=[r2]) |
|
183 |
||
184 |
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
185 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
186 |
'mark :2\n' |
187 |
'committer Joe Foo <joe@foo.com> 1194586400 +0000\n' |
|
188 |
'data 5\n' |
|
189 |
'first'
|
|
190 |
'\n' |
|
191 |
'M 100644 :1 foo\n' |
|
192 |
'\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
193 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
194 |
'mark :3\n' |
195 |
'committer Joe Foo <joe@foo.com> 1194586405 +0000\n' |
|
196 |
'data 6\n' |
|
197 |
'second'
|
|
198 |
'\n' |
|
199 |
'\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
200 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
201 |
'mark :4\n' |
202 |
'committer Joe Foo <joe@foo.com> 1194586410 +0000\n' |
|
203 |
'data 5\n' |
|
204 |
'third'
|
|
205 |
'\n' |
|
206 |
'from :2\n' |
|
207 |
'\n' |
|
0.200.33
by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master. |
208 |
'commit refs/heads/master\n' |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
209 |
'mark :5\n' |
210 |
'committer Joe Foo <joe@foo.com> 1194586415 +0000\n' |
|
211 |
'data 5\n' |
|
212 |
'Merge'
|
|
213 |
'\n' |
|
214 |
'merge :3\n' |
|
215 |
'\n', stream.getvalue()) |
|
216 |
||
217 |
def test_auto_timestamp(self): |
|
218 |
stream = StringIO() |
|
219 |
builder = tests.GitBranchBuilder(stream) |
|
220 |
builder.commit('Joe Foo <joe@foo.com>', u'message') |
|
221 |
self.assertContainsRe(stream.getvalue(), |
|
222 |
r'committer Joe Foo <joe@foo\.com> \d+ \+0000') |
|
223 |
||
0.200.34
by David Allouche
GitBranchBuilder.reset() |
224 |
def test_reset(self): |
225 |
stream = StringIO() |
|
226 |
builder = tests.GitBranchBuilder(stream) |
|
227 |
builder.reset() |
|
228 |
self.assertEqualDiff('reset refs/heads/master\n\n', stream.getvalue()) |
|
229 |
||
230 |
def test_reset_named_ref(self): |
|
231 |
stream = StringIO() |
|
232 |
builder = tests.GitBranchBuilder(stream) |
|
233 |
builder.reset('refs/heads/branch') |
|
234 |
self.assertEqualDiff('reset refs/heads/branch\n\n', stream.getvalue()) |
|
235 |
||
236 |
def test_reset_revision(self): |
|
237 |
stream = StringIO() |
|
238 |
builder = tests.GitBranchBuilder(stream) |
|
239 |
builder.reset(mark=123) |
|
240 |
self.assertEqualDiff( |
|
241 |
'reset refs/heads/master\n' |
|
242 |
'from :123\n' |
|
243 |
'\n', stream.getvalue()) |
|
244 |
||
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
245 |
|
246 |
class TestGitBranchBuilderReal(tests.TestCaseInTempDir): |
|
247 |
||
248 |
def test_create_real_branch(self): |
|
0.200.992
by Jelmer Vernooij
Avoid invoking git directly. |
249 |
GitRepo.init(".") |
0.200.23
by John Arbash Meinel
Clean up the builder, start using it for big speed gains. |
250 |
|
251 |
builder = tests.GitBranchBuilder() |
|
252 |
builder.set_file(u'foo', 'contents\nfoo\n', False) |
|
253 |
r1 = builder.commit('Joe Foo <joe@foo.com>', u'first', |
|
254 |
timestamp=1194586400) |
|
255 |
mapping = builder.finish() |
|
256 |
self.assertEqual({1:'44411e8e9202177dd19b6599d7a7991059fa3cb4', |
|
257 |
2: 'b0b62e674f67306fddcf72fa888c3b56df100d64', |
|
258 |
}, mapping) |