]> git.proxmox.com Git - libgit2.git/blob - tests/rebase/sign.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / rebase / sign.c
1 #include "clar_libgit2.h"
2 #include "git2/rebase.h"
3
4 static git_repository *repo;
5 static git_signature *signature;
6
7 /* Fixture setup and teardown */
8 void test_rebase_sign__initialize(void)
9 {
10 repo = cl_git_sandbox_init("rebase");
11 cl_git_pass(git_signature_new(&signature, "Rebaser",
12 "rebaser@rebaser.rb", 1405694510, 0));
13 }
14
15 void test_rebase_sign__cleanup(void)
16 {
17 git_signature_free(signature);
18 cl_git_sandbox_cleanup();
19 }
20
21 static int create_cb_passthrough(
22 git_oid *out,
23 const git_signature *author,
24 const git_signature *committer,
25 const char *message_encoding,
26 const char *message,
27 const git_tree *tree,
28 size_t parent_count,
29 const git_commit *parents[],
30 void *payload)
31 {
32 GIT_UNUSED(out);
33 GIT_UNUSED(author);
34 GIT_UNUSED(committer);
35 GIT_UNUSED(message_encoding);
36 GIT_UNUSED(message);
37 GIT_UNUSED(tree);
38 GIT_UNUSED(parent_count);
39 GIT_UNUSED(parents);
40 GIT_UNUSED(payload);
41
42 return GIT_PASSTHROUGH;
43 }
44
45 /* git checkout gravy ; git rebase --merge veal */
46 void test_rebase_sign__passthrough_create_cb(void)
47 {
48 git_rebase *rebase;
49 git_reference *branch_ref, *upstream_ref;
50 git_annotated_commit *branch_head, *upstream_head;
51 git_rebase_operation *rebase_operation;
52 git_oid commit_id, expected_id;
53 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
54 git_commit *commit;
55 const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
56 parent f87d14a4a236582a0278a916340a793714256864\n\
57 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
58 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
59
60 rebase_opts.commit_create_cb = create_cb_passthrough;
61
62 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
63 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
64
65 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
66 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
67
68 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
69
70 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
71 cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
72
73 git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630");
74 cl_assert_equal_oid(&expected_id, &commit_id);
75
76 cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
77 cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
78
79 cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
80
81 git_reference_free(branch_ref);
82 git_reference_free(upstream_ref);
83 git_annotated_commit_free(branch_head);
84 git_annotated_commit_free(upstream_head);
85 git_commit_free(commit);
86 git_rebase_free(rebase);
87 }
88
89 static int create_cb_signed_gpg(
90 git_oid *out,
91 const git_signature *author,
92 const git_signature *committer,
93 const char *message_encoding,
94 const char *message,
95 const git_tree *tree,
96 size_t parent_count,
97 const git_commit *parents[],
98 void *payload)
99 {
100 git_buf commit_content = GIT_BUF_INIT;
101 const char *gpg_signature = "-----BEGIN PGP SIGNATURE-----\n\
102 \n\
103 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
104 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
105 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
106 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
107 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
108 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
109 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
110 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
111 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
112 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
113 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
114 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
115 =KbsY\n\
116 -----END PGP SIGNATURE-----";
117
118 git_repository *repo = (git_repository *)payload;
119 int error;
120
121 if ((error = git_commit_create_buffer(&commit_content,
122 repo, author, committer, message_encoding, message,
123 tree, parent_count, parents)) < 0)
124 goto done;
125
126 error = git_commit_create_with_signature(out, repo,
127 commit_content.ptr,
128 gpg_signature,
129 NULL);
130
131 done:
132 git_buf_dispose(&commit_content);
133 return error;
134 }
135
136 /* git checkout gravy ; git rebase --merge veal */
137 void test_rebase_sign__create_gpg_signed(void)
138 {
139 git_rebase *rebase;
140 git_reference *branch_ref, *upstream_ref;
141 git_annotated_commit *branch_head, *upstream_head;
142 git_rebase_operation *rebase_operation;
143 git_oid commit_id, expected_id;
144 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
145 git_commit *commit;
146 const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
147 parent f87d14a4a236582a0278a916340a793714256864\n\
148 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
149 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
150 gpgsig -----BEGIN PGP SIGNATURE-----\n\
151 \n\
152 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
153 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
154 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
155 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
156 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
157 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
158 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
159 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
160 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
161 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
162 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
163 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
164 =KbsY\n\
165 -----END PGP SIGNATURE-----\n";
166
167 rebase_opts.commit_create_cb = create_cb_signed_gpg;
168 rebase_opts.payload = repo;
169
170 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
171 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
172
173 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
174 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
175
176 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
177
178 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
179 cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
180
181 git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef");
182 cl_assert_equal_oid(&expected_id, &commit_id);
183
184 cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
185 cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
186
187 cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
188
189 git_reference_free(branch_ref);
190 git_reference_free(upstream_ref);
191 git_annotated_commit_free(branch_head);
192 git_annotated_commit_free(upstream_head);
193 git_commit_free(commit);
194 git_rebase_free(rebase);
195 }
196
197 static int create_cb_error(
198 git_oid *out,
199 const git_signature *author,
200 const git_signature *committer,
201 const char *message_encoding,
202 const char *message,
203 const git_tree *tree,
204 size_t parent_count,
205 const git_commit *parents[],
206 void *payload)
207 {
208 GIT_UNUSED(out);
209 GIT_UNUSED(author);
210 GIT_UNUSED(committer);
211 GIT_UNUSED(message_encoding);
212 GIT_UNUSED(message);
213 GIT_UNUSED(tree);
214 GIT_UNUSED(parent_count);
215 GIT_UNUSED(parents);
216 GIT_UNUSED(payload);
217
218 return GIT_EUSER;
219 }
220
221 /* git checkout gravy ; git rebase --merge veal */
222 void test_rebase_sign__create_propagates_error(void)
223 {
224 git_rebase *rebase;
225 git_reference *branch_ref, *upstream_ref;
226 git_annotated_commit *branch_head, *upstream_head;
227 git_oid commit_id;
228 git_rebase_operation *rebase_operation;
229 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
230
231 rebase_opts.commit_create_cb = create_cb_error;
232
233 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
234 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
235
236 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
237 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
238
239 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
240
241 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
242 cl_git_fail_with(GIT_EUSER, git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
243
244 git_reference_free(branch_ref);
245 git_reference_free(upstream_ref);
246 git_annotated_commit_free(branch_head);
247 git_annotated_commit_free(upstream_head);
248 git_rebase_free(rebase);
249 }
250
251 #ifndef GIT_DEPRECATE_HARD
252 static const char *expected_commit_content = "\
253 tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
254 parent f87d14a4a236582a0278a916340a793714256864\n\
255 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
256 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
257 \n\
258 Modification 3 to gravy\n";
259
260 int signing_cb_passthrough(
261 git_buf *signature,
262 git_buf *signature_field,
263 const char *commit_content,
264 void *payload)
265 {
266 cl_assert_equal_i(0, signature->size);
267 cl_assert_equal_i(0, signature_field->size);
268 cl_assert_equal_s(expected_commit_content, commit_content);
269 cl_assert_equal_p(NULL, payload);
270 return GIT_PASSTHROUGH;
271 }
272 #endif /* !GIT_DEPRECATE_HARD */
273
274 /* git checkout gravy ; git rebase --merge veal */
275 void test_rebase_sign__passthrough_signing_cb(void)
276 {
277 #ifndef GIT_DEPRECATE_HARD
278 git_rebase *rebase;
279 git_reference *branch_ref, *upstream_ref;
280 git_annotated_commit *branch_head, *upstream_head;
281 git_rebase_operation *rebase_operation;
282 git_oid commit_id, expected_id;
283 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
284 git_commit *commit;
285 const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
286 parent f87d14a4a236582a0278a916340a793714256864\n\
287 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
288 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
289
290 rebase_opts.signing_cb = signing_cb_passthrough;
291
292 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
293 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
294
295 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
296 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
297
298 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
299
300 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
301 cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
302
303 git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630");
304 cl_assert_equal_oid(&expected_id, &commit_id);
305
306 cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
307 cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
308
309 cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
310
311 git_reference_free(branch_ref);
312 git_reference_free(upstream_ref);
313 git_annotated_commit_free(branch_head);
314 git_annotated_commit_free(upstream_head);
315 git_commit_free(commit);
316 git_rebase_free(rebase);
317 #endif /* !GIT_DEPRECATE_HARD */
318 }
319
320 #ifndef GIT_DEPRECATE_HARD
321 int signing_cb_gpg(
322 git_buf *signature,
323 git_buf *signature_field,
324 const char *commit_content,
325 void *payload)
326 {
327 const char *gpg_signature = "\
328 -----BEGIN PGP SIGNATURE-----\n\
329 \n\
330 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
331 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
332 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
333 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
334 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
335 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
336 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
337 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
338 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
339 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
340 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
341 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
342 =KbsY\n\
343 -----END PGP SIGNATURE-----";
344
345 cl_assert_equal_i(0, signature->size);
346 cl_assert_equal_i(0, signature_field->size);
347 cl_assert_equal_s(expected_commit_content, commit_content);
348 cl_assert_equal_p(NULL, payload);
349
350 cl_git_pass(git_buf_set(signature, gpg_signature, strlen(gpg_signature) + 1));
351 return GIT_OK;
352 }
353 #endif /* !GIT_DEPRECATE_HARD */
354
355 /* git checkout gravy ; git rebase --merge veal */
356 void test_rebase_sign__gpg_with_no_field(void)
357 {
358 #ifndef GIT_DEPRECATE_HARD
359 git_rebase *rebase;
360 git_reference *branch_ref, *upstream_ref;
361 git_annotated_commit *branch_head, *upstream_head;
362 git_rebase_operation *rebase_operation;
363 git_oid commit_id, expected_id;
364 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
365 git_commit *commit;
366 const char *expected_commit_raw_header = "\
367 tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
368 parent f87d14a4a236582a0278a916340a793714256864\n\
369 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
370 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
371 gpgsig -----BEGIN PGP SIGNATURE-----\n\
372 \n\
373 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
374 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
375 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
376 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
377 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
378 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
379 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
380 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
381 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
382 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
383 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
384 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
385 =KbsY\n\
386 -----END PGP SIGNATURE-----\n";
387
388 rebase_opts.signing_cb = signing_cb_gpg;
389
390 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
391 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
392
393 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
394 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
395
396 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
397
398 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
399 cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
400
401 git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef");
402 cl_assert_equal_oid(&expected_id, &commit_id);
403
404 cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
405 cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
406
407 cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
408
409 git_reference_free(branch_ref);
410 git_reference_free(upstream_ref);
411 git_annotated_commit_free(branch_head);
412 git_annotated_commit_free(upstream_head);
413 git_commit_free(commit);
414 git_rebase_free(rebase);
415 #endif /* !GIT_DEPRECATE_HARD */
416 }
417
418
419 #ifndef GIT_DEPRECATE_HARD
420 int signing_cb_magic_field(
421 git_buf *signature,
422 git_buf *signature_field,
423 const char *commit_content,
424 void *payload)
425 {
426 const char *signature_content = "magic word: pretty please";
427 const char *signature_field_content = "magicsig";
428
429 cl_assert_equal_p(NULL, signature->ptr);
430 cl_assert_equal_i(0, signature->size);
431 cl_assert_equal_p(NULL, signature_field->ptr);
432 cl_assert_equal_i(0, signature_field->size);
433 cl_assert_equal_s(expected_commit_content, commit_content);
434 cl_assert_equal_p(NULL, payload);
435
436 cl_git_pass(git_buf_set(signature, signature_content,
437 strlen(signature_content) + 1));
438 cl_git_pass(git_buf_set(signature_field, signature_field_content,
439 strlen(signature_field_content) + 1));
440
441 return GIT_OK;
442 }
443 #endif /* !GIT_DEPRECATE_HARD */
444
445 /* git checkout gravy ; git rebase --merge veal */
446 void test_rebase_sign__custom_signature_field(void)
447 {
448 #ifndef GIT_DEPRECATE_HARD
449 git_rebase *rebase;
450 git_reference *branch_ref, *upstream_ref;
451 git_annotated_commit *branch_head, *upstream_head;
452 git_rebase_operation *rebase_operation;
453 git_oid commit_id, expected_id;
454 git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
455 git_commit *commit;
456 const char *expected_commit_raw_header = "\
457 tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
458 parent f87d14a4a236582a0278a916340a793714256864\n\
459 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
460 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
461 magicsig magic word: pretty please\n";
462
463 rebase_opts.signing_cb = signing_cb_magic_field;
464
465 cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
466 cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
467
468 cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
469 cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
470
471 cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
472
473 cl_git_pass(git_rebase_next(&rebase_operation, rebase));
474 cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
475
476 git_oid_fromstr(&expected_id, "f46a4a8d26ae411b02aa61b7d69576627f4a1e1c");
477 cl_assert_equal_oid(&expected_id, &commit_id);
478
479 cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
480 cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
481
482 cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
483
484 git_reference_free(branch_ref);
485 git_reference_free(upstream_ref);
486 git_annotated_commit_free(branch_head);
487 git_annotated_commit_free(upstream_head);
488 git_commit_free(commit);
489 git_rebase_free(rebase);
490 #endif /* !GIT_DEPRECATE_HARD */
491 }