1 #include "clar_libgit2.h"
2 #include "git2/rebase.h"
4 static git_repository
*repo
;
5 static git_signature
*signature
;
7 /* Fixture setup and teardown */
8 void test_rebase_sign__initialize(void)
10 repo
= cl_git_sandbox_init("rebase");
11 cl_git_pass(git_signature_new(&signature
, "Rebaser",
12 "rebaser@rebaser.rb", 1405694510, 0));
15 void test_rebase_sign__cleanup(void)
17 git_signature_free(signature
);
18 cl_git_sandbox_cleanup();
21 static const char *expected_commit_content
= "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
22 parent f87d14a4a236582a0278a916340a793714256864\n\
23 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
24 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
26 Modification 3 to gravy\n";
28 int signing_cb_passthrough(
30 git_buf
*signature_field
,
31 const char *commit_content
,
34 cl_assert_equal_b(false, git_buf_is_allocated(signature
));
35 cl_assert_equal_b(false, git_buf_is_allocated(signature_field
));
36 cl_assert_equal_s(expected_commit_content
, commit_content
);
37 cl_assert_equal_p(NULL
, payload
);
38 return GIT_PASSTHROUGH
;
41 /* git checkout gravy ; git rebase --merge veal */
42 void test_rebase_sign__passthrough_signing_cb(void)
45 git_reference
*branch_ref
, *upstream_ref
;
46 git_annotated_commit
*branch_head
, *upstream_head
;
47 git_rebase_operation
*rebase_operation
;
48 git_oid commit_id
, expected_id
;
49 git_rebase_options rebase_opts
= GIT_REBASE_OPTIONS_INIT
;
51 const char *expected_commit_raw_header
= "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
52 parent f87d14a4a236582a0278a916340a793714256864\n\
53 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
54 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
56 rebase_opts
.signing_cb
= signing_cb_passthrough
;
58 cl_git_pass(git_reference_lookup(&branch_ref
, repo
, "refs/heads/gravy"));
59 cl_git_pass(git_reference_lookup(&upstream_ref
, repo
, "refs/heads/veal"));
61 cl_git_pass(git_annotated_commit_from_ref(&branch_head
, repo
, branch_ref
));
62 cl_git_pass(git_annotated_commit_from_ref(&upstream_head
, repo
, upstream_ref
));
64 cl_git_pass(git_rebase_init(&rebase
, repo
, branch_head
, upstream_head
, NULL
, &rebase_opts
));
66 cl_git_pass(git_rebase_next(&rebase_operation
, rebase
));
67 cl_git_pass(git_rebase_commit(&commit_id
, rebase
, NULL
, signature
, NULL
, NULL
));
69 git_oid_fromstr(&expected_id
, "129183968a65abd6c52da35bff43325001bfc630");
70 cl_assert_equal_oid(&expected_id
, &commit_id
);
72 cl_git_pass(git_commit_lookup(&commit
, repo
, &commit_id
));
73 cl_assert_equal_s(expected_commit_raw_header
, git_commit_raw_header(commit
));
75 cl_git_fail_with(GIT_ITEROVER
, git_rebase_next(&rebase_operation
, rebase
));
77 git_reference_free(branch_ref
);
78 git_reference_free(upstream_ref
);
79 git_annotated_commit_free(branch_head
);
80 git_annotated_commit_free(upstream_head
);
81 git_commit_free(commit
);
82 git_rebase_free(rebase
);
87 git_buf
*signature_field
,
88 const char *commit_content
,
91 const char *gpg_signature
= "-----BEGIN PGP SIGNATURE-----\n\
93 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
94 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
95 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
96 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
97 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
98 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
99 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
100 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
101 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
102 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
103 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
104 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
106 -----END PGP SIGNATURE-----";
108 cl_assert_equal_b(false, git_buf_is_allocated(signature
));
109 cl_assert_equal_b(false, git_buf_is_allocated(signature_field
));
110 cl_assert_equal_s(expected_commit_content
, commit_content
);
111 cl_assert_equal_p(NULL
, payload
);
113 cl_git_pass(git_buf_set(signature
, gpg_signature
, strlen(gpg_signature
) + 1));
117 /* git checkout gravy ; git rebase --merge veal */
118 void test_rebase_sign__gpg_with_no_field(void)
121 git_reference
*branch_ref
, *upstream_ref
;
122 git_annotated_commit
*branch_head
, *upstream_head
;
123 git_rebase_operation
*rebase_operation
;
124 git_oid commit_id
, expected_id
;
125 git_rebase_options rebase_opts
= GIT_REBASE_OPTIONS_INIT
;
127 const char *expected_commit_raw_header
= "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
128 parent f87d14a4a236582a0278a916340a793714256864\n\
129 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
130 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
131 gpgsig -----BEGIN PGP SIGNATURE-----\n\
133 iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
134 ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
135 ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
136 7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
137 km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
138 nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
139 jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
140 dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
141 fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
142 cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
143 xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
144 cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
146 -----END PGP SIGNATURE-----\n";
148 rebase_opts
.signing_cb
= signing_cb_gpg
;
150 cl_git_pass(git_reference_lookup(&branch_ref
, repo
, "refs/heads/gravy"));
151 cl_git_pass(git_reference_lookup(&upstream_ref
, repo
, "refs/heads/veal"));
153 cl_git_pass(git_annotated_commit_from_ref(&branch_head
, repo
, branch_ref
));
154 cl_git_pass(git_annotated_commit_from_ref(&upstream_head
, repo
, upstream_ref
));
156 cl_git_pass(git_rebase_init(&rebase
, repo
, branch_head
, upstream_head
, NULL
, &rebase_opts
));
158 cl_git_pass(git_rebase_next(&rebase_operation
, rebase
));
159 cl_git_pass(git_rebase_commit(&commit_id
, rebase
, NULL
, signature
, NULL
, NULL
));
161 git_oid_fromstr(&expected_id
, "bf78348e45c8286f52b760f1db15cb6da030f2ef");
162 cl_assert_equal_oid(&expected_id
, &commit_id
);
164 cl_git_pass(git_commit_lookup(&commit
, repo
, &commit_id
));
165 cl_assert_equal_s(expected_commit_raw_header
, git_commit_raw_header(commit
));
167 cl_git_fail_with(GIT_ITEROVER
, git_rebase_next(&rebase_operation
, rebase
));
169 git_reference_free(branch_ref
);
170 git_reference_free(upstream_ref
);
171 git_annotated_commit_free(branch_head
);
172 git_annotated_commit_free(upstream_head
);
173 git_commit_free(commit
);
174 git_rebase_free(rebase
);
178 int signing_cb_magic_field(
180 git_buf
*signature_field
,
181 const char *commit_content
,
184 const char *signature_content
= "magic word: pretty please";
185 const char *signature_field_content
= "magicsig";
187 cl_assert_equal_b(false, git_buf_is_allocated(signature
));
188 cl_assert_equal_b(false, git_buf_is_allocated(signature_field
));
189 cl_assert_equal_s(expected_commit_content
, commit_content
);
190 cl_assert_equal_p(NULL
, payload
);
192 cl_git_pass(git_buf_set(signature
, signature_content
,
193 strlen(signature_content
) + 1));
194 cl_git_pass(git_buf_set(signature_field
, signature_field_content
,
195 strlen(signature_field_content
) + 1));
200 /* git checkout gravy ; git rebase --merge veal */
201 void test_rebase_sign__custom_signature_field(void)
204 git_reference
*branch_ref
, *upstream_ref
;
205 git_annotated_commit
*branch_head
, *upstream_head
;
206 git_rebase_operation
*rebase_operation
;
207 git_oid commit_id
, expected_id
;
208 git_rebase_options rebase_opts
= GIT_REBASE_OPTIONS_INIT
;
210 const char *expected_commit_raw_header
= "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
211 parent f87d14a4a236582a0278a916340a793714256864\n\
212 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
213 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
214 magicsig magic word: pretty please\n";
216 rebase_opts
.signing_cb
= signing_cb_magic_field
;
218 cl_git_pass(git_reference_lookup(&branch_ref
, repo
, "refs/heads/gravy"));
219 cl_git_pass(git_reference_lookup(&upstream_ref
, repo
, "refs/heads/veal"));
221 cl_git_pass(git_annotated_commit_from_ref(&branch_head
, repo
, branch_ref
));
222 cl_git_pass(git_annotated_commit_from_ref(&upstream_head
, repo
, upstream_ref
));
224 cl_git_pass(git_rebase_init(&rebase
, repo
, branch_head
, upstream_head
, NULL
, &rebase_opts
));
226 cl_git_pass(git_rebase_next(&rebase_operation
, rebase
));
227 cl_git_pass(git_rebase_commit(&commit_id
, rebase
, NULL
, signature
, NULL
, NULL
));
229 git_oid_fromstr(&expected_id
, "f46a4a8d26ae411b02aa61b7d69576627f4a1e1c");
230 cl_assert_equal_oid(&expected_id
, &commit_id
);
232 cl_git_pass(git_commit_lookup(&commit
, repo
, &commit_id
));
233 cl_assert_equal_s(expected_commit_raw_header
, git_commit_raw_header(commit
));
235 cl_git_fail_with(GIT_ITEROVER
, git_rebase_next(&rebase_operation
, rebase
));
237 git_reference_free(branch_ref
);
238 git_reference_free(upstream_ref
);
239 git_annotated_commit_free(branch_head
);
240 git_annotated_commit_free(upstream_head
);
241 git_commit_free(commit
);
242 git_rebase_free(rebase
);