1 #include "clar_libgit2.h"
2 #include <git2/types.h>
7 static git_repository
*g_repo
;
8 void test_commit_parse__initialize(void)
10 g_repo
= cl_git_sandbox_init("testrepo");
12 void test_commit_parse__cleanup(void)
14 cl_git_sandbox_cleanup();
24 static parse_test_case passing_header_cases
[] = {
25 { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
26 { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
27 { "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " },
28 { "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" },
29 { "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " },
30 { "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " },
31 { "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " },
32 { "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " },
36 static parse_test_case failing_header_cases
[] = {
37 { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " },
38 { "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
39 { "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " },
40 { "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " },
41 { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
42 { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
43 { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " },
49 void test_commit_parse__header(void)
53 parse_test_case
*testcase
;
54 for (testcase
= passing_header_cases
; testcase
->line
!= NULL
; testcase
++)
56 const char *line
= testcase
->line
;
57 const char *line_end
= line
+ strlen(line
);
59 cl_git_pass(git_oid__parse(&oid
, &line
, line_end
, testcase
->header
));
60 cl_assert(line
== line_end
);
63 for (testcase
= failing_header_cases
; testcase
->line
!= NULL
; testcase
++)
65 const char *line
= testcase
->line
;
66 const char *line_end
= line
+ strlen(line
);
68 cl_git_fail(git_oid__parse(&oid
, &line
, line_end
, testcase
->header
));
81 } passing_signature_test_case
;
83 passing_signature_test_case passing_signature_cases
[] = {
84 {"author Vicent Marti <tanoku@gmail.com> 12345 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 12345, 0},
85 {"author Vicent Marti <> 12345 \n", "author ", "Vicent Marti", "", 12345, 0},
86 {"author Vicent Marti <tanoku@gmail.com> 231301 +1020\n", "author ", "Vicent Marti", "tanoku@gmail.com", 231301, 620},
87 {"author Vicent Marti with an outrageously long name which will probably overflow the buffer <tanoku@gmail.com> 12345 \n", "author ", "Vicent Marti with an outrageously long name which will probably overflow the buffer", "tanoku@gmail.com", 12345, 0},
88 {"author Vicent Marti <tanokuwithaveryveryverylongemailwhichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n", "author ", "Vicent Marti", "tanokuwithaveryveryverylongemailwhichwillprobablyvoverflowtheemailbuffer@gmail.com", 12345, 0},
89 {"committer Vicent Marti <tanoku@gmail.com> 123456 +0000 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0},
90 {"committer Vicent Marti <tanoku@gmail.com> 123456 +0100 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 60},
91 {"committer Vicent Marti <tanoku@gmail.com> 123456 -0100 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, -60},
92 // Parse a signature without an author field
93 {"committer <tanoku@gmail.com> 123456 -0100 \n", "committer ", "", "tanoku@gmail.com", 123456, -60},
94 // Parse a signature without an author field
95 {"committer <tanoku@gmail.com> 123456 -0100 \n", "committer ", "", "tanoku@gmail.com", 123456, -60},
96 // Parse a signature with an empty author field
97 {"committer <tanoku@gmail.com> 123456 -0100 \n", "committer ", "", "tanoku@gmail.com", 123456, -60},
98 // Parse a signature with an empty email field
99 {"committer Vicent Marti <> 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
100 // Parse a signature with an empty email field
101 {"committer Vicent Marti < > 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
102 // Parse a signature with empty name and email
103 {"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
104 // Parse a signature with empty name and email
105 {"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
106 // Parse a signature with empty name and email
107 {"committer < > 123456 -0100 \n", "committer ", "", "", 123456, -60},
108 // Parse an obviously invalid signature
109 {"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
110 // Parse an obviously invalid signature
111 {"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
112 // Parse an obviously invalid signature
113 {"committer <>\n", "committer ", "", "", 0, 0},
114 {"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0},
115 {"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0},
116 {"author Vicent Marti <tanoku@gmail.com>\n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
117 /* a variety of dates */
118 {"author Vicent Marti <tanoku@gmail.com> 0 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0},
119 {"author Vicent Marti <tanoku@gmail.com> 1234567890 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 1234567890, 0},
120 {"author Vicent Marti <tanoku@gmail.com> 2147483647 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0x7fffffff, 0},
121 {"author Vicent Marti <tanoku@gmail.com> 4294967295 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0xffffffff, 0},
122 {"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296, 0},
123 {"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592, 0},
125 {NULL
,NULL
,NULL
,NULL
,0,0}
131 } failing_signature_test_case
;
133 failing_signature_test_case failing_signature_cases
[] = {
134 {"committer Vicent Marti tanoku@gmail.com> 123456 -0100 \n", "committer "},
135 {"author Vicent Marti <tanoku@gmail.com> 12345 \n", "author "},
136 {"author Vicent Marti <tanoku@gmail.com> 12345 \n", "committer "},
137 {"author Vicent Marti 12345 \n", "author "},
138 {"author Vicent Marti <broken@email 12345 \n", "author "},
139 {"committer Vicent Marti ><\n", "committer "},
140 {"author ", "author "},
144 void test_commit_parse__signature(void)
146 passing_signature_test_case
*passcase
;
147 failing_signature_test_case
*failcase
;
149 for (passcase
= passing_signature_cases
; passcase
->string
!= NULL
; passcase
++)
151 const char *str
= passcase
->string
;
152 size_t len
= strlen(passcase
->string
);
153 struct git_signature person
= {0};
155 cl_git_pass(git_signature__parse(&person
, &str
, str
+ len
, passcase
->header
, '\n'));
156 cl_assert_equal_s(passcase
->name
, person
.name
);
157 cl_assert_equal_s(passcase
->email
, person
.email
);
158 cl_assert_equal_i((int)passcase
->time
, (int)person
.when
.time
);
159 cl_assert_equal_i(passcase
->offset
, person
.when
.offset
);
160 git__free(person
.name
); git__free(person
.email
);
163 for (failcase
= failing_signature_cases
; failcase
->string
!= NULL
; failcase
++)
165 const char *str
= failcase
->string
;
166 size_t len
= strlen(failcase
->string
);
167 git_signature person
= {0};
168 cl_git_fail(git_signature__parse(&person
, &str
, str
+ len
, failcase
->header
, '\n'));
169 git__free(person
.name
); git__free(person
.email
);
175 static char *failing_commit_cases
[] = {
179 "asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n",
181 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\
182 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\
183 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
184 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
186 a test commit with broken endlines\r\n",
188 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\
189 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\
190 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
191 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
193 another test commit with broken endlines",
195 "\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
196 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
197 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
198 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
200 a test commit with a starting endline\n",
201 // corrupted commit 1
202 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
203 parent 05452d6349abcd67aa396df",
204 // corrupted commit 2
205 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
207 // corrupted commit 3
208 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
210 // corrupted commit 4
211 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
216 static char *passing_commit_cases
[] = {
217 // simple commit with no message
218 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
219 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
220 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
222 // simple commit, no parent
223 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
224 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
225 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
227 a simple commit which works\n",
228 // simple commit, no parent, no newline in message
229 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
230 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
231 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
233 a simple commit which works",
234 // simple commit, 1 parent
235 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
236 parent e90810b8df3e80c413d903f631643c716887138d\n\
237 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
238 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
240 a simple commit which works\n",
241 /* simple commit with GPG signature */
242 "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
243 parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
244 author Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
245 committer Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
246 gpgsig -----BEGIN PGP SIGNATURE-----\n\
247 Version: GnuPG v1.4.12 (Darwin)\n\
249 iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
250 o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
251 JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
252 AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
253 SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
254 who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
255 6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
256 cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
257 c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
258 ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
259 7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
260 cpxtDQQMGYFpXK/71stq\n\
262 -----END PGP SIGNATURE-----\n\
264 a simple commit which works\n",
265 /* some tools create two author entries */
266 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
267 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
268 author Helpful Coworker <helpful@coworker> 1273848544 +0200\n\
269 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
271 a simple commit which works",
274 static int parse_commit(git_commit
**out
, const char *buffer
)
277 git_odb_object fake_odb_object
;
280 commit
= (git_commit
*)git__malloc(sizeof(git_commit
));
281 memset(commit
, 0x0, sizeof(git_commit
));
282 commit
->object
.repo
= g_repo
;
284 memset(&fake_odb_object
, 0x0, sizeof(git_odb_object
));
285 fake_odb_object
.buffer
= (char *)buffer
;
286 fake_odb_object
.cached
.size
= strlen(fake_odb_object
.buffer
);
288 error
= git_commit__parse(commit
, &fake_odb_object
);
294 void test_commit_parse__entire_commit(void)
296 const int failing_commit_count
= ARRAY_SIZE(failing_commit_cases
);
297 const int passing_commit_count
= ARRAY_SIZE(passing_commit_cases
);
301 for (i
= 0; i
< failing_commit_count
; ++i
) {
302 cl_git_fail(parse_commit(&commit
, failing_commit_cases
[i
]));
303 git_commit__free(commit
);
306 for (i
= 0; i
< passing_commit_count
; ++i
) {
307 cl_git_pass(parse_commit(&commit
, passing_commit_cases
[i
]));
310 cl_assert_equal_s("", git_commit_message(commit
));
312 cl_assert(git__prefixcmp(
313 git_commit_message(commit
), "a simple commit which works") == 0);
315 git_commit__free(commit
);
320 // query the details on a parsed commit
321 void test_commit_parse__details0(void) {
322 static const char *commit_ids
[] = {
323 "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
324 "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
325 "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
326 "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
327 "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
328 "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
329 "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */
331 const size_t commit_count
= sizeof(commit_ids
) / sizeof(const char *);
334 for (i
= 0; i
< commit_count
; ++i
) {
338 const git_signature
*author
, *committer
;
340 git_time_t commit_time
;
341 unsigned int parents
, p
;
342 git_commit
*parent
= NULL
, *old_parent
= NULL
;
344 git_oid_fromstr(&id
, commit_ids
[i
]);
346 cl_git_pass(git_commit_lookup(&commit
, g_repo
, &id
));
348 message
= git_commit_message(commit
);
349 author
= git_commit_author(commit
);
350 committer
= git_commit_committer(commit
);
351 commit_time
= git_commit_time(commit
);
352 parents
= git_commit_parentcount(commit
);
354 cl_assert_equal_s("Scott Chacon", author
->name
);
355 cl_assert_equal_s("schacon@gmail.com", author
->email
);
356 cl_assert_equal_s("Scott Chacon", committer
->name
);
357 cl_assert_equal_s("schacon@gmail.com", committer
->email
);
358 cl_assert(message
!= NULL
);
359 cl_assert(commit_time
> 0);
360 cl_assert(parents
<= 2);
361 for (p
= 0;p
< parents
;p
++) {
362 if (old_parent
!= NULL
)
363 git_commit_free(old_parent
);
366 cl_git_pass(git_commit_parent(&parent
, commit
, p
));
367 cl_assert(parent
!= NULL
);
368 cl_assert(git_commit_author(parent
) != NULL
); // is it really a commit?
370 git_commit_free(old_parent
);
371 git_commit_free(parent
);
373 cl_git_fail(git_commit_parent(&parent
, commit
, parents
));
374 git_commit_free(commit
);
378 void test_commit_parse__leading_lf(void)
382 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
383 parent e90810b8df3e80c413d903f631643c716887138d\n\
384 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
385 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
389 This commit has a few LF at the start of the commit message";
390 const char *message
=
391 "This commit has a few LF at the start of the commit message";
392 const char *raw_message
=
395 This commit has a few LF at the start of the commit message";
396 cl_git_pass(parse_commit(&commit
, buffer
));
397 cl_assert_equal_s(message
, git_commit_message(commit
));
398 cl_assert_equal_s(raw_message
, git_commit_message_raw(commit
));
399 git_commit__free(commit
);
402 void test_commit_parse__only_lf(void)
406 "tree 1810dff58d8a660512d4832e740f692884338ccd\n\
407 parent e90810b8df3e80c413d903f631643c716887138d\n\
408 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
409 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
413 const char *message
= "";
414 const char *raw_message
= "\n\n";
416 cl_git_pass(parse_commit(&commit
, buffer
));
417 cl_assert_equal_s(message
, git_commit_message(commit
));
418 cl_assert_equal_s(raw_message
, git_commit_message_raw(commit
));
419 git_commit__free(commit
);
422 void test_commit_parse__arbitrary_field(void)
425 git_buf buf
= GIT_BUF_INIT
;
426 const char *gpgsig
= "-----BEGIN PGP SIGNATURE-----\n\
427 Version: GnuPG v1.4.12 (Darwin)\n\
429 iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
430 o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
431 JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
432 AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
433 SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
434 who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
435 6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
436 cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
437 c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
438 ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
439 7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
440 cpxtDQQMGYFpXK/71stq\n\
442 -----END PGP SIGNATURE-----";
444 cl_git_pass(parse_commit(&commit
, passing_commit_cases
[4]));
446 cl_git_pass(git_commit_header_field(&buf
, commit
, "tree"));
447 cl_assert_equal_s("6b79e22d69bf46e289df0345a14ca059dfc9bdf6", buf
.ptr
);
450 cl_git_pass(git_commit_header_field(&buf
, commit
, "parent"));
451 cl_assert_equal_s("34734e478d6cf50c27c9d69026d93974d052c454", buf
.ptr
);
454 cl_git_pass(git_commit_header_field(&buf
, commit
, "gpgsig"));
455 cl_assert_equal_s(gpgsig
, buf
.ptr
);
458 cl_git_fail_with(GIT_ENOTFOUND
, git_commit_header_field(&buf
, commit
, "awesomeness"));
459 cl_git_fail_with(GIT_ENOTFOUND
, git_commit_header_field(&buf
, commit
, "par"));
461 git_commit__free(commit
);
462 cl_git_pass(parse_commit(&commit
, passing_commit_cases
[0]));
464 cl_git_pass(git_commit_header_field(&buf
, commit
, "committer"));
465 cl_assert_equal_s("Vicent Marti <tanoku@gmail.com> 1273848544 +0200", buf
.ptr
);
468 git_commit__free(commit
);
471 void test_commit_parse__extract_signature(void)
475 git_buf signature
= GIT_BUF_INIT
, signed_data
= GIT_BUF_INIT
;
476 const char *gpgsig
= "-----BEGIN PGP SIGNATURE-----\n\
477 Version: GnuPG v1.4.12 (Darwin)\n\
479 iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
480 o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
481 JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
482 AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
483 SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
484 who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
485 6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
486 cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
487 c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
488 ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
489 7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
490 cpxtDQQMGYFpXK/71stq\n\
492 -----END PGP SIGNATURE-----";
494 const char *data
= "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
495 parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
496 author Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
497 committer Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\
499 a simple commit which works\n";
502 cl_git_pass(git_repository_odb__weakptr(&odb
, g_repo
));
503 cl_git_pass(git_odb_write(&commit_id
, odb
, passing_commit_cases
[4], strlen(passing_commit_cases
[4]), GIT_OBJ_COMMIT
));
505 cl_git_pass(git_commit_extract_signature(&signature
, &signed_data
, g_repo
, &commit_id
, NULL
));
506 cl_assert_equal_s(gpgsig
, signature
.ptr
);
507 cl_assert_equal_s(data
, signed_data
.ptr
);
509 git_buf_clear(&signature
);
510 git_buf_clear(&signed_data
);
512 cl_git_pass(git_commit_extract_signature(&signature
, &signed_data
, g_repo
, &commit_id
, "gpgsig"));
513 cl_assert_equal_s(gpgsig
, signature
.ptr
);
514 cl_assert_equal_s(data
, signed_data
.ptr
);
516 /* Try to parse a tree */
517 cl_git_pass(git_oid_fromstr(&commit_id
, "45dd856fdd4d89b884c340ba0e047752d9b085d6"));
518 cl_git_fail_with(GIT_ENOTFOUND
, git_commit_extract_signature(&signature
, &signed_data
, g_repo
, &commit_id
, NULL
));
519 cl_assert_equal_i(GITERR_INVALID
, giterr_last()->klass
);
521 /* Try to parse an unsigned commit */
522 cl_git_pass(git_odb_write(&commit_id
, odb
, passing_commit_cases
[1], strlen(passing_commit_cases
[1]), GIT_OBJ_COMMIT
));
523 cl_git_fail_with(GIT_ENOTFOUND
, git_commit_extract_signature(&signature
, &signed_data
, g_repo
, &commit_id
, NULL
));
524 cl_assert_equal_i(GITERR_OBJECT
, giterr_last()->klass
);
526 git_buf_free(&signature
);
527 git_buf_free(&signed_data
);