]>
Commit | Line | Data |
---|---|---|
613d5eb9 PK |
1 | #include "clar_libgit2.h" |
2 | #include "buffer.h" | |
3 | #include "posix.h" | |
4 | #include "vector.h" | |
5 | #include "../submodule/submodule_helpers.h" | |
6 | #include "push_util.h" | |
1d645aab JM |
7 | #include "refspec.h" |
8 | #include "remote.h" | |
613d5eb9 | 9 | |
613d5eb9 PK |
10 | static git_repository *_repo; |
11 | ||
84efffc3 ET |
12 | static char *_remote_url; |
13 | ||
5be622fb CMN |
14 | static char *_remote_ssh_key; |
15 | static char *_remote_ssh_pubkey; | |
16 | static char *_remote_ssh_passphrase; | |
17 | ||
613d5eb9 PK |
18 | static char *_remote_user; |
19 | static char *_remote_pass; | |
20 | ||
84efffc3 ET |
21 | static char *_remote_default; |
22 | ||
e3c131c5 CMN |
23 | static int cred_acquire_cb(git_cred **, const char *, const char *, unsigned int, void *); |
24 | ||
613d5eb9 PK |
25 | static git_remote *_remote; |
26 | static record_callbacks_data _record_cbs_data = {{ 0 }}; | |
27 | static git_remote_callbacks _record_cbs = RECORD_CALLBACKS_INIT(&_record_cbs_data); | |
28 | ||
29 | static git_oid _oid_b6; | |
30 | static git_oid _oid_b5; | |
31 | static git_oid _oid_b4; | |
32 | static git_oid _oid_b3; | |
33 | static git_oid _oid_b2; | |
34 | static git_oid _oid_b1; | |
35 | ||
abeefbbe MS |
36 | static git_oid _tag_commit; |
37 | static git_oid _tag_tree; | |
38 | static git_oid _tag_blob; | |
39 | static git_oid _tag_lightweight; | |
1c13b0bf | 40 | static git_oid _tag_tag; |
abeefbbe | 41 | |
7602cb7c | 42 | static int cred_acquire_cb( |
2648dc1a ET |
43 | git_cred **cred, |
44 | const char *url, | |
45 | const char *user_from_url, | |
46 | unsigned int allowed_types, | |
47 | void *payload) | |
613d5eb9 PK |
48 | { |
49 | GIT_UNUSED(url); | |
7602cb7c | 50 | GIT_UNUSED(user_from_url); |
2648dc1a | 51 | GIT_UNUSED(payload); |
613d5eb9 | 52 | |
84efffc3 ET |
53 | if (GIT_CREDTYPE_DEFAULT & allowed_types) { |
54 | if (!_remote_default) { | |
55 | printf("GITTEST_REMOTE_DEFAULT must be set to use NTLM/Negotiate credentials\n"); | |
56 | return -1; | |
57 | } | |
58 | ||
59 | return git_cred_default_new(cred); | |
60 | } | |
61 | ||
70a8c78f | 62 | if (GIT_CREDTYPE_SSH_KEY & allowed_types) { |
2648dc1a ET |
63 | if (!_remote_user || !_remote_ssh_pubkey || !_remote_ssh_key || !_remote_ssh_passphrase) { |
64 | printf("GITTEST_REMOTE_USER, GITTEST_REMOTE_SSH_PUBKEY, GITTEST_REMOTE_SSH_KEY and GITTEST_REMOTE_SSH_PASSPHRASE must be set\n"); | |
65 | return -1; | |
66 | } | |
84efffc3 | 67 | |
70a8c78f | 68 | return git_cred_ssh_key_new(cred, _remote_user, _remote_ssh_pubkey, _remote_ssh_key, _remote_ssh_passphrase); |
2648dc1a | 69 | } |
5be622fb | 70 | |
2648dc1a ET |
71 | if (GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) { |
72 | if (!_remote_user || !_remote_pass) { | |
73 | printf("GITTEST_REMOTE_USER and GITTEST_REMOTE_PASS must be set\n"); | |
74 | return -1; | |
75 | } | |
613d5eb9 | 76 | |
2648dc1a ET |
77 | return git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass); |
78 | } | |
79 | ||
80 | return -1; | |
613d5eb9 PK |
81 | } |
82 | ||
9d41984c ET |
83 | /* the results of a push status. when used for expected values, msg may be NULL |
84 | * to indicate that it should not be matched. */ | |
613d5eb9 PK |
85 | typedef struct { |
86 | const char *ref; | |
9d41984c | 87 | int success; |
613d5eb9 PK |
88 | const char *msg; |
89 | } push_status; | |
90 | ||
91 | /** | |
92 | * git_push_status_foreach callback that records status entries. | |
93 | * @param data (git_vector *) of push_status instances | |
94 | */ | |
95 | static int record_push_status_cb(const char *ref, const char *msg, void *data) | |
96 | { | |
97 | git_vector *statuses = (git_vector *)data; | |
98 | push_status *s; | |
99 | ||
100 | cl_assert(s = git__malloc(sizeof(*s))); | |
101 | s->ref = ref; | |
9d41984c | 102 | s->success = (msg == NULL); |
613d5eb9 PK |
103 | s->msg = msg; |
104 | ||
105 | git_vector_insert(statuses, s); | |
106 | ||
107 | return 0; | |
108 | } | |
109 | ||
110 | static void do_verify_push_status(git_push *push, const push_status expected[], const size_t expected_len) | |
111 | { | |
112 | git_vector actual = GIT_VECTOR_INIT; | |
113 | push_status *iter; | |
114 | bool failed = false; | |
115 | size_t i; | |
116 | ||
117 | git_push_status_foreach(push, record_push_status_cb, &actual); | |
118 | ||
119 | if (expected_len != actual.length) | |
120 | failed = true; | |
121 | else | |
122 | git_vector_foreach(&actual, i, iter) | |
123 | if (strcmp(expected[i].ref, iter->ref) || | |
9d41984c ET |
124 | (expected[i].success != iter->success) || |
125 | (expected[i].msg && (!iter->msg || strcmp(expected[i].msg, iter->msg)))) { | |
613d5eb9 PK |
126 | failed = true; |
127 | break; | |
128 | } | |
129 | ||
130 | if (failed) { | |
131 | git_buf msg = GIT_BUF_INIT; | |
132 | ||
133 | git_buf_puts(&msg, "Expected and actual push statuses differ:\nEXPECTED:\n"); | |
134 | ||
135 | for(i = 0; i < expected_len; i++) { | |
136 | git_buf_printf(&msg, "%s: %s\n", | |
137 | expected[i].ref, | |
9d41984c | 138 | expected[i].success ? "success" : "failed"); |
613d5eb9 PK |
139 | } |
140 | ||
141 | git_buf_puts(&msg, "\nACTUAL:\n"); | |
142 | ||
9d41984c ET |
143 | git_vector_foreach(&actual, i, iter) { |
144 | if (iter->success) | |
145 | git_buf_printf(&msg, "%s: success\n", iter->ref); | |
146 | else | |
147 | git_buf_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg); | |
148 | } | |
613d5eb9 PK |
149 | |
150 | cl_fail(git_buf_cstr(&msg)); | |
151 | ||
152 | git_buf_free(&msg); | |
153 | } | |
154 | ||
155 | git_vector_foreach(&actual, i, iter) | |
156 | git__free(iter); | |
157 | ||
158 | git_vector_free(&actual); | |
159 | } | |
160 | ||
161 | /** | |
162 | * Verifies that after git_push_finish(), refs on a remote have the expected | |
163 | * names, oids, and order. | |
156cfec0 | 164 | * |
613d5eb9 PK |
165 | * @param remote remote to verify |
166 | * @param expected_refs expected remote refs after push | |
167 | * @param expected_refs_len length of expected_refs | |
168 | */ | |
169 | static void verify_refs(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len) | |
170 | { | |
359dce72 CMN |
171 | const git_remote_head **actual_refs; |
172 | size_t actual_refs_len; | |
613d5eb9 | 173 | |
359dce72 CMN |
174 | git_remote_ls(&actual_refs, &actual_refs_len, remote); |
175 | verify_remote_refs(actual_refs, actual_refs_len, expected_refs, expected_refs_len); | |
613d5eb9 PK |
176 | } |
177 | ||
1d645aab JM |
178 | /** |
179 | * Verifies that after git_push_update_tips(), remote tracking branches have the expected | |
180 | * names and oids. | |
181 | * | |
182 | * @param remote remote to verify | |
183 | * @param expected_refs expected remote refs after push | |
184 | * @param expected_refs_len length of expected_refs | |
185 | */ | |
186 | static void verify_tracking_branches(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len) | |
187 | { | |
4330ab26 | 188 | git_refspec *fetch_spec; |
1d645aab JM |
189 | size_t i, j; |
190 | git_buf msg = GIT_BUF_INIT; | |
191 | git_buf ref_name = GIT_BUF_INIT; | |
1d645aab | 192 | git_vector actual_refs = GIT_VECTOR_INIT; |
8ec889a4 | 193 | git_branch_iterator *iter; |
1d645aab JM |
194 | char *actual_ref; |
195 | git_oid oid; | |
8ec889a4 | 196 | int failed = 0, error; |
a667ca82 | 197 | git_branch_t branch_type; |
8ec889a4 | 198 | git_reference *ref; |
1d645aab JM |
199 | |
200 | /* Get current remote branches */ | |
8ec889a4 CMN |
201 | cl_git_pass(git_branch_iterator_new(&iter, remote->repo, GIT_BRANCH_REMOTE)); |
202 | ||
203 | while ((error = git_branch_next(&ref, &branch_type, iter)) == 0) { | |
204 | cl_assert_equal_i(branch_type, GIT_BRANCH_REMOTE); | |
205 | ||
206 | cl_git_pass(git_vector_insert(&actual_refs, git__strdup(git_reference_name(ref)))); | |
207 | } | |
208 | ||
209 | cl_assert_equal_i(error, GIT_ITEROVER); | |
11bd7a03 | 210 | git_branch_iterator_free(iter); |
1d645aab JM |
211 | |
212 | /* Loop through expected refs, make sure they exist */ | |
213 | for (i = 0; i < expected_refs_len; i++) { | |
214 | ||
215 | /* Convert remote reference name into tracking branch name. | |
216 | * If the spec is not under refs/heads/, then skip. | |
217 | */ | |
4330ab26 CMN |
218 | fetch_spec = git_remote__matching_refspec(remote, expected_refs[i].name); |
219 | if (!fetch_spec) | |
1d645aab JM |
220 | continue; |
221 | ||
bf522e08 | 222 | cl_git_pass(git_refspec_transform(&ref_name, fetch_spec, expected_refs[i].name)); |
1d645aab JM |
223 | |
224 | /* Find matching remote branch */ | |
225 | git_vector_foreach(&actual_refs, j, actual_ref) { | |
8ec889a4 | 226 | if (!strcmp(git_buf_cstr(&ref_name), actual_ref)) |
1d645aab JM |
227 | break; |
228 | } | |
229 | ||
230 | if (j == actual_refs.length) { | |
231 | git_buf_printf(&msg, "Did not find expected tracking branch '%s'.", git_buf_cstr(&ref_name)); | |
232 | failed = 1; | |
233 | goto failed; | |
234 | } | |
235 | ||
236 | /* Make sure tracking branch is at expected commit ID */ | |
8ec889a4 | 237 | cl_git_pass(git_reference_name_to_id(&oid, remote->repo, actual_ref)); |
1d645aab JM |
238 | |
239 | if (git_oid_cmp(expected_refs[i].oid, &oid) != 0) { | |
240 | git_buf_puts(&msg, "Tracking branch commit does not match expected ID."); | |
241 | failed = 1; | |
242 | goto failed; | |
243 | } | |
244 | ||
2ff4469a | 245 | git__free(actual_ref); |
1d645aab JM |
246 | cl_git_pass(git_vector_remove(&actual_refs, j)); |
247 | } | |
248 | ||
249 | /* Make sure there are no extra branches */ | |
250 | if (actual_refs.length > 0) { | |
251 | git_buf_puts(&msg, "Unexpected remote tracking branches exist."); | |
252 | failed = 1; | |
253 | goto failed; | |
254 | } | |
255 | ||
256 | failed: | |
f70cfd34 | 257 | if (failed) |
1d645aab JM |
258 | cl_fail(git_buf_cstr(&msg)); |
259 | ||
260 | git_vector_foreach(&actual_refs, i, actual_ref) | |
261 | git__free(actual_ref); | |
262 | ||
263 | git_vector_free(&actual_refs); | |
264 | git_buf_free(&msg); | |
2ff4469a | 265 | git_buf_free(&ref_name); |
f70cfd34 JG |
266 | } |
267 | ||
268 | static void verify_update_tips_callback(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len) | |
269 | { | |
270 | git_refspec *fetch_spec; | |
271 | git_buf msg = GIT_BUF_INIT; | |
272 | git_buf ref_name = GIT_BUF_INIT; | |
273 | updated_tip *tip = NULL; | |
274 | size_t i, j; | |
275 | int failed = 0; | |
276 | ||
277 | for (i = 0; i < expected_refs_len; ++i) { | |
278 | /* Convert remote reference name into tracking branch name. | |
279 | * If the spec is not under refs/heads/, then skip. | |
280 | */ | |
281 | fetch_spec = git_remote__matching_refspec(remote, expected_refs[i].name); | |
282 | if (!fetch_spec) | |
283 | continue; | |
284 | ||
285 | cl_git_pass(git_refspec_transform(&ref_name, fetch_spec, expected_refs[i].name)); | |
286 | ||
287 | /* Find matching update_tip entry */ | |
288 | git_vector_foreach(&_record_cbs_data.updated_tips, j, tip) { | |
289 | if (!strcmp(git_buf_cstr(&ref_name), tip->name)) | |
290 | break; | |
291 | } | |
292 | ||
293 | if (j == _record_cbs_data.updated_tips.length) { | |
294 | git_buf_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", git_buf_cstr(&ref_name)); | |
295 | failed = 1; | |
296 | goto failed; | |
297 | } | |
298 | ||
299 | if (git_oid_cmp(expected_refs[i].oid, tip->new_oid) != 0) { | |
300 | git_buf_printf(&msg, "Updated tip ID does not match expected ID"); | |
301 | failed = 1; | |
302 | goto failed; | |
303 | } | |
304 | } | |
305 | ||
306 | failed: | |
307 | if (failed) | |
308 | cl_fail(git_buf_cstr(&msg)); | |
309 | ||
310 | git_buf_free(&ref_name); | |
311 | git_buf_free(&msg); | |
1d645aab JM |
312 | } |
313 | ||
6443eaf2 | 314 | void test_online_push__initialize(void) |
613d5eb9 PK |
315 | { |
316 | git_vector delete_specs = GIT_VECTOR_INIT; | |
ae297212 CMN |
317 | const git_remote_head **heads; |
318 | size_t i, heads_len; | |
613d5eb9 PK |
319 | char *curr_del_spec; |
320 | ||
321 | _repo = cl_git_sandbox_init("push_src"); | |
322 | ||
323 | cl_fixture_sandbox("testrepo.git"); | |
324 | cl_rename("push_src/submodule/.gitted", "push_src/submodule/.git"); | |
325 | ||
326 | rewrite_gitmodules(git_repository_workdir(_repo)); | |
327 | ||
328 | /* git log --format=oneline --decorate --graph | |
329 | * *-. 951bbbb90e2259a4c8950db78946784fb53fcbce (HEAD, b6) merge b3, b4, and b5 to b6 | |
330 | * |\ \ | |
331 | * | | * fa38b91f199934685819bea316186d8b008c52a2 (b5) added submodule named 'submodule' pointing to '../testrepo.git' | |
332 | * | * | 27b7ce66243eb1403862d05f958c002312df173d (b4) edited fold\b.txt | |
333 | * | |/ | |
334 | * * | d9b63a88223d8367516f50bd131a5f7349b7f3e4 (b3) edited a.txt | |
335 | * |/ | |
336 | * * a78705c3b2725f931d3ee05348d83cc26700f247 (b2, b1) added fold and fold/b.txt | |
337 | * * 5c0bb3d1b9449d1cc69d7519fd05166f01840915 added a.txt | |
338 | */ | |
339 | git_oid_fromstr(&_oid_b6, "951bbbb90e2259a4c8950db78946784fb53fcbce"); | |
340 | git_oid_fromstr(&_oid_b5, "fa38b91f199934685819bea316186d8b008c52a2"); | |
341 | git_oid_fromstr(&_oid_b4, "27b7ce66243eb1403862d05f958c002312df173d"); | |
342 | git_oid_fromstr(&_oid_b3, "d9b63a88223d8367516f50bd131a5f7349b7f3e4"); | |
343 | git_oid_fromstr(&_oid_b2, "a78705c3b2725f931d3ee05348d83cc26700f247"); | |
344 | git_oid_fromstr(&_oid_b1, "a78705c3b2725f931d3ee05348d83cc26700f247"); | |
345 | ||
abeefbbe MS |
346 | git_oid_fromstr(&_tag_commit, "805c54522e614f29f70d2413a0470247d8b424ac"); |
347 | git_oid_fromstr(&_tag_tree, "ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e"); | |
348 | git_oid_fromstr(&_tag_blob, "b483ae7ba66decee9aee971f501221dea84b1498"); | |
349 | git_oid_fromstr(&_tag_lightweight, "951bbbb90e2259a4c8950db78946784fb53fcbce"); | |
1c13b0bf | 350 | git_oid_fromstr(&_tag_tag, "eea4f2705eeec2db3813f2430829afce99cd00b5"); |
abeefbbe | 351 | |
613d5eb9 PK |
352 | /* Remote URL environment variable must be set. User and password are optional. */ |
353 | _remote_url = cl_getenv("GITTEST_REMOTE_URL"); | |
354 | _remote_user = cl_getenv("GITTEST_REMOTE_USER"); | |
355 | _remote_pass = cl_getenv("GITTEST_REMOTE_PASS"); | |
5be622fb CMN |
356 | _remote_ssh_key = cl_getenv("GITTEST_REMOTE_SSH_KEY"); |
357 | _remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); | |
358 | _remote_ssh_passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE"); | |
84efffc3 | 359 | _remote_default = cl_getenv("GITTEST_REMOTE_DEFAULT"); |
613d5eb9 PK |
360 | _remote = NULL; |
361 | ||
0f65733b VM |
362 | /* Skip the test if we're missing the remote URL */ |
363 | if (!_remote_url) | |
364 | cl_skip(); | |
613d5eb9 | 365 | |
0f65733b | 366 | cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url)); |
613d5eb9 | 367 | |
0f65733b VM |
368 | record_callbacks_data_clear(&_record_cbs_data); |
369 | git_remote_set_callbacks(_remote, &_record_cbs); | |
613d5eb9 | 370 | |
0f65733b | 371 | cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH)); |
613d5eb9 | 372 | |
0f65733b VM |
373 | /* Clean up previously pushed branches. Fails if receive.denyDeletes is |
374 | * set on the remote. Also, on Git 1.7.0 and newer, you must run | |
375 | * 'git config receive.denyDeleteCurrent ignore' in the remote repo in | |
376 | * order to delete the remote branch pointed to by HEAD (usually master). | |
377 | * See: https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.0.txt | |
378 | */ | |
379 | cl_git_pass(git_remote_ls(&heads, &heads_len, _remote)); | |
380 | cl_git_pass(create_deletion_refspecs(&delete_specs, heads, heads_len)); | |
381 | if (delete_specs.length) { | |
382 | git_push *push; | |
613d5eb9 | 383 | |
0f65733b | 384 | cl_git_pass(git_push_new(&push, _remote)); |
613d5eb9 | 385 | |
0f65733b VM |
386 | git_vector_foreach(&delete_specs, i, curr_del_spec) { |
387 | git_push_add_refspec(push, curr_del_spec); | |
388 | git__free(curr_del_spec); | |
613d5eb9 PK |
389 | } |
390 | ||
0f65733b VM |
391 | cl_git_pass(git_push_finish(push)); |
392 | git_push_free(push); | |
393 | } | |
394 | ||
395 | git_remote_disconnect(_remote); | |
396 | git_vector_free(&delete_specs); | |
613d5eb9 | 397 | |
0f65733b VM |
398 | /* Now that we've deleted everything, fetch from the remote */ |
399 | cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH)); | |
400 | cl_git_pass(git_remote_download(_remote)); | |
401 | cl_git_pass(git_remote_update_tips(_remote, NULL, NULL)); | |
402 | git_remote_disconnect(_remote); | |
613d5eb9 PK |
403 | } |
404 | ||
6443eaf2 | 405 | void test_online_push__cleanup(void) |
613d5eb9 PK |
406 | { |
407 | if (_remote) | |
408 | git_remote_free(_remote); | |
c4e3e797 BS |
409 | _remote = NULL; |
410 | ||
411 | /* Freed by cl_git_sandbox_cleanup */ | |
412 | _repo = NULL; | |
613d5eb9 PK |
413 | |
414 | record_callbacks_data_clear(&_record_cbs_data); | |
415 | ||
416 | cl_fixture_cleanup("testrepo.git"); | |
417 | cl_git_sandbox_cleanup(); | |
418 | } | |
419 | ||
11bd7a03 RB |
420 | static int push_pack_progress_cb( |
421 | int stage, unsigned int current, unsigned int total, void* payload) | |
b176eded | 422 | { |
11bd7a03 | 423 | int *calls = (int *)payload; |
7baa7631 | 424 | GIT_UNUSED(stage); GIT_UNUSED(current); GIT_UNUSED(total); |
11bd7a03 RB |
425 | if (*calls < 0) |
426 | return *calls; | |
427 | (*calls)++; | |
5b188225 | 428 | return 0; |
b176eded JM |
429 | } |
430 | ||
11bd7a03 RB |
431 | static int push_transfer_progress_cb( |
432 | unsigned int current, unsigned int total, size_t bytes, void* payload) | |
b176eded | 433 | { |
11bd7a03 | 434 | int *calls = (int *)payload; |
af302aca | 435 | GIT_UNUSED(current); GIT_UNUSED(total); GIT_UNUSED(bytes); |
11bd7a03 RB |
436 | if (*calls < 0) |
437 | return *calls; | |
438 | (*calls)++; | |
5b188225 | 439 | return 0; |
b176eded JM |
440 | } |
441 | ||
613d5eb9 PK |
442 | /** |
443 | * Calls push and relists refs on remote to verify success. | |
156cfec0 | 444 | * |
613d5eb9 PK |
445 | * @param refspecs refspecs to push |
446 | * @param refspecs_len length of refspecs | |
447 | * @param expected_refs expected remote refs after push | |
448 | * @param expected_refs_len length of expected_refs | |
449 | * @param expected_ret expected return value from git_push_finish() | |
b176eded | 450 | * @param check_progress_cb Check that the push progress callbacks are called |
613d5eb9 | 451 | */ |
11bd7a03 RB |
452 | static void do_push( |
453 | const char *refspecs[], size_t refspecs_len, | |
613d5eb9 | 454 | push_status expected_statuses[], size_t expected_statuses_len, |
11bd7a03 | 455 | expected_ref expected_refs[], size_t expected_refs_len, |
f70cfd34 | 456 | int expected_ret, int check_progress_cb, int check_update_tips_cb) |
613d5eb9 PK |
457 | { |
458 | git_push *push; | |
b8b897bb | 459 | git_push_options opts = GIT_PUSH_OPTIONS_INIT; |
613d5eb9 | 460 | size_t i; |
11bd7a03 | 461 | int pack_progress_calls = 0, transfer_progress_calls = 0; |
491cecfe | 462 | git_signature *pusher; |
613d5eb9 PK |
463 | |
464 | if (_remote) { | |
b8b897bb PK |
465 | /* Auto-detect the number of threads to use */ |
466 | opts.pb_parallelism = 0; | |
467 | ||
491cecfe | 468 | cl_git_pass(git_signature_now(&pusher, "Foo Bar", "foo@example.com")); |
613d5eb9 PK |
469 | cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH)); |
470 | ||
471 | cl_git_pass(git_push_new(&push, _remote)); | |
b8b897bb | 472 | cl_git_pass(git_push_set_options(push, &opts)); |
613d5eb9 | 473 | |
11bd7a03 RB |
474 | if (check_progress_cb) { |
475 | /* if EUSER, then abort in transfer */ | |
476 | if (expected_ret == GIT_EUSER) | |
477 | transfer_progress_calls = GIT_EUSER; | |
478 | ||
479 | cl_git_pass( | |
480 | git_push_set_callbacks( | |
481 | push, push_pack_progress_cb, &pack_progress_calls, | |
482 | push_transfer_progress_cb, &transfer_progress_calls)); | |
483 | } | |
b176eded | 484 | |
613d5eb9 PK |
485 | for (i = 0; i < refspecs_len; i++) |
486 | cl_git_pass(git_push_add_refspec(push, refspecs[i])); | |
487 | ||
488 | if (expected_ret < 0) { | |
11bd7a03 | 489 | cl_git_fail_with(git_push_finish(push), expected_ret); |
613d5eb9 | 490 | cl_assert_equal_i(0, git_push_unpack_ok(push)); |
11bd7a03 RB |
491 | } else { |
492 | cl_git_pass(git_push_finish(push)); | |
613d5eb9 PK |
493 | cl_assert_equal_i(1, git_push_unpack_ok(push)); |
494 | } | |
495 | ||
11bd7a03 RB |
496 | if (check_progress_cb && !expected_ret) { |
497 | cl_assert(pack_progress_calls > 0); | |
498 | cl_assert(transfer_progress_calls > 0); | |
b176eded JM |
499 | } |
500 | ||
613d5eb9 PK |
501 | do_verify_push_status(push, expected_statuses, expected_statuses_len); |
502 | ||
613d5eb9 PK |
503 | verify_refs(_remote, expected_refs, expected_refs_len); |
504 | ||
491cecfe | 505 | cl_git_pass(git_push_update_tips(push, pusher, "test push")); |
1d645aab JM |
506 | verify_tracking_branches(_remote, expected_refs, expected_refs_len); |
507 | ||
f70cfd34 JG |
508 | if (check_update_tips_cb) |
509 | verify_update_tips_callback(_remote, expected_refs, expected_refs_len); | |
510 | ||
1d645aab | 511 | git_push_free(push); |
613d5eb9 PK |
512 | |
513 | git_remote_disconnect(_remote); | |
491cecfe | 514 | git_signature_free(pusher); |
613d5eb9 | 515 | } |
491cecfe | 516 | |
613d5eb9 PK |
517 | } |
518 | ||
519 | /* Call push_finish() without ever calling git_push_add_refspec() */ | |
6443eaf2 | 520 | void test_online_push__noop(void) |
613d5eb9 | 521 | { |
f70cfd34 | 522 | do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0, 1); |
613d5eb9 PK |
523 | } |
524 | ||
6443eaf2 | 525 | void test_online_push__b1(void) |
613d5eb9 PK |
526 | { |
527 | const char *specs[] = { "refs/heads/b1:refs/heads/b1" }; | |
9d41984c | 528 | push_status exp_stats[] = { { "refs/heads/b1", 1 } }; |
613d5eb9 PK |
529 | expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } }; |
530 | do_push(specs, ARRAY_SIZE(specs), | |
531 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 532 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
613d5eb9 PK |
533 | } |
534 | ||
6443eaf2 | 535 | void test_online_push__b2(void) |
613d5eb9 PK |
536 | { |
537 | const char *specs[] = { "refs/heads/b2:refs/heads/b2" }; | |
9d41984c | 538 | push_status exp_stats[] = { { "refs/heads/b2", 1 } }; |
613d5eb9 PK |
539 | expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } }; |
540 | do_push(specs, ARRAY_SIZE(specs), | |
541 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 542 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
613d5eb9 PK |
543 | } |
544 | ||
6443eaf2 | 545 | void test_online_push__b3(void) |
613d5eb9 PK |
546 | { |
547 | const char *specs[] = { "refs/heads/b3:refs/heads/b3" }; | |
9d41984c | 548 | push_status exp_stats[] = { { "refs/heads/b3", 1 } }; |
613d5eb9 PK |
549 | expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } }; |
550 | do_push(specs, ARRAY_SIZE(specs), | |
551 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 552 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
613d5eb9 PK |
553 | } |
554 | ||
6443eaf2 | 555 | void test_online_push__b4(void) |
613d5eb9 PK |
556 | { |
557 | const char *specs[] = { "refs/heads/b4:refs/heads/b4" }; | |
9d41984c | 558 | push_status exp_stats[] = { { "refs/heads/b4", 1 } }; |
613d5eb9 PK |
559 | expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } }; |
560 | do_push(specs, ARRAY_SIZE(specs), | |
561 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 562 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
613d5eb9 PK |
563 | } |
564 | ||
6443eaf2 | 565 | void test_online_push__b5(void) |
613d5eb9 PK |
566 | { |
567 | const char *specs[] = { "refs/heads/b5:refs/heads/b5" }; | |
9d41984c | 568 | push_status exp_stats[] = { { "refs/heads/b5", 1 } }; |
613d5eb9 PK |
569 | expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } }; |
570 | do_push(specs, ARRAY_SIZE(specs), | |
571 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 572 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
613d5eb9 PK |
573 | } |
574 | ||
11bd7a03 RB |
575 | void test_online_push__b5_cancel(void) |
576 | { | |
577 | const char *specs[] = { "refs/heads/b5:refs/heads/b5" }; | |
f70cfd34 | 578 | do_push(specs, ARRAY_SIZE(specs), NULL, 0, NULL, 0, GIT_EUSER, 1, 1); |
11bd7a03 RB |
579 | } |
580 | ||
6443eaf2 | 581 | void test_online_push__multi(void) |
613d5eb9 | 582 | { |
491cecfe BS |
583 | git_reflog *log; |
584 | const git_reflog_entry *entry; | |
585 | ||
613d5eb9 PK |
586 | const char *specs[] = { |
587 | "refs/heads/b1:refs/heads/b1", | |
588 | "refs/heads/b2:refs/heads/b2", | |
589 | "refs/heads/b3:refs/heads/b3", | |
590 | "refs/heads/b4:refs/heads/b4", | |
591 | "refs/heads/b5:refs/heads/b5" | |
592 | }; | |
593 | push_status exp_stats[] = { | |
9d41984c ET |
594 | { "refs/heads/b1", 1 }, |
595 | { "refs/heads/b2", 1 }, | |
596 | { "refs/heads/b3", 1 }, | |
597 | { "refs/heads/b4", 1 }, | |
598 | { "refs/heads/b5", 1 } | |
613d5eb9 PK |
599 | }; |
600 | expected_ref exp_refs[] = { | |
601 | { "refs/heads/b1", &_oid_b1 }, | |
602 | { "refs/heads/b2", &_oid_b2 }, | |
603 | { "refs/heads/b3", &_oid_b3 }, | |
604 | { "refs/heads/b4", &_oid_b4 }, | |
605 | { "refs/heads/b5", &_oid_b5 } | |
606 | }; | |
607 | do_push(specs, ARRAY_SIZE(specs), | |
608 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 609 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
491cecfe BS |
610 | |
611 | cl_git_pass(git_reflog_read(&log, _repo, "refs/remotes/test/b1")); | |
612 | entry = git_reflog_entry_byindex(log, 0); | |
3094102f BS |
613 | if (entry) { |
614 | cl_assert_equal_s("test push", git_reflog_entry_message(entry)); | |
615 | cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email); | |
616 | } | |
491cecfe BS |
617 | |
618 | git_reflog_free(log); | |
613d5eb9 PK |
619 | } |
620 | ||
6443eaf2 | 621 | void test_online_push__implicit_tgt(void) |
613d5eb9 PK |
622 | { |
623 | const char *specs1[] = { "refs/heads/b1:" }; | |
9d41984c | 624 | push_status exp_stats1[] = { { "refs/heads/b1", 1 } }; |
613d5eb9 PK |
625 | expected_ref exp_refs1[] = { { "refs/heads/b1", &_oid_b1 } }; |
626 | ||
627 | const char *specs2[] = { "refs/heads/b2:" }; | |
9d41984c | 628 | push_status exp_stats2[] = { { "refs/heads/b2", 1 } }; |
613d5eb9 PK |
629 | expected_ref exp_refs2[] = { |
630 | { "refs/heads/b1", &_oid_b1 }, | |
631 | { "refs/heads/b2", &_oid_b2 } | |
632 | }; | |
633 | ||
634 | do_push(specs1, ARRAY_SIZE(specs1), | |
635 | exp_stats1, ARRAY_SIZE(exp_stats1), | |
f70cfd34 | 636 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1); |
613d5eb9 PK |
637 | do_push(specs2, ARRAY_SIZE(specs2), |
638 | exp_stats2, ARRAY_SIZE(exp_stats2), | |
f70cfd34 | 639 | exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0, 0); |
613d5eb9 PK |
640 | } |
641 | ||
6443eaf2 | 642 | void test_online_push__fast_fwd(void) |
613d5eb9 PK |
643 | { |
644 | /* Fast forward b1 in tgt from _oid_b1 to _oid_b6. */ | |
645 | ||
646 | const char *specs_init[] = { "refs/heads/b1:refs/heads/b1" }; | |
9d41984c | 647 | push_status exp_stats_init[] = { { "refs/heads/b1", 1 } }; |
613d5eb9 PK |
648 | expected_ref exp_refs_init[] = { { "refs/heads/b1", &_oid_b1 } }; |
649 | ||
650 | const char *specs_ff[] = { "refs/heads/b6:refs/heads/b1" }; | |
9d41984c | 651 | push_status exp_stats_ff[] = { { "refs/heads/b1", 1 } }; |
613d5eb9 PK |
652 | expected_ref exp_refs_ff[] = { { "refs/heads/b1", &_oid_b6 } }; |
653 | ||
654 | /* Do a force push to reset b1 in target back to _oid_b1 */ | |
655 | const char *specs_reset[] = { "+refs/heads/b1:refs/heads/b1" }; | |
656 | /* Force should have no effect on a fast forward push */ | |
657 | const char *specs_ff_force[] = { "+refs/heads/b6:refs/heads/b1" }; | |
658 | ||
659 | do_push(specs_init, ARRAY_SIZE(specs_init), | |
660 | exp_stats_init, ARRAY_SIZE(exp_stats_init), | |
f70cfd34 | 661 | exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1, 1); |
613d5eb9 PK |
662 | |
663 | do_push(specs_ff, ARRAY_SIZE(specs_ff), | |
664 | exp_stats_ff, ARRAY_SIZE(exp_stats_ff), | |
f70cfd34 | 665 | exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0); |
613d5eb9 PK |
666 | |
667 | do_push(specs_reset, ARRAY_SIZE(specs_reset), | |
668 | exp_stats_init, ARRAY_SIZE(exp_stats_init), | |
f70cfd34 | 669 | exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0, 0); |
613d5eb9 PK |
670 | |
671 | do_push(specs_ff_force, ARRAY_SIZE(specs_ff_force), | |
672 | exp_stats_ff, ARRAY_SIZE(exp_stats_ff), | |
f70cfd34 | 673 | exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0); |
613d5eb9 PK |
674 | } |
675 | ||
abeefbbe MS |
676 | void test_online_push__tag_commit(void) |
677 | { | |
678 | const char *specs[] = { "refs/tags/tag-commit:refs/tags/tag-commit" }; | |
9d41984c | 679 | push_status exp_stats[] = { { "refs/tags/tag-commit", 1 } }; |
abeefbbe MS |
680 | expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } }; |
681 | do_push(specs, ARRAY_SIZE(specs), | |
682 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 683 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
abeefbbe MS |
684 | } |
685 | ||
686 | void test_online_push__tag_tree(void) | |
687 | { | |
688 | const char *specs[] = { "refs/tags/tag-tree:refs/tags/tag-tree" }; | |
9d41984c | 689 | push_status exp_stats[] = { { "refs/tags/tag-tree", 1 } }; |
abeefbbe MS |
690 | expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } }; |
691 | do_push(specs, ARRAY_SIZE(specs), | |
692 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 693 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
abeefbbe MS |
694 | } |
695 | ||
696 | void test_online_push__tag_blob(void) | |
697 | { | |
698 | const char *specs[] = { "refs/tags/tag-blob:refs/tags/tag-blob" }; | |
9d41984c | 699 | push_status exp_stats[] = { { "refs/tags/tag-blob", 1 } }; |
abeefbbe MS |
700 | expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } }; |
701 | do_push(specs, ARRAY_SIZE(specs), | |
702 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 703 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
abeefbbe MS |
704 | } |
705 | ||
706 | void test_online_push__tag_lightweight(void) | |
707 | { | |
708 | const char *specs[] = { "refs/tags/tag-lightweight:refs/tags/tag-lightweight" }; | |
9d41984c | 709 | push_status exp_stats[] = { { "refs/tags/tag-lightweight", 1 } }; |
abeefbbe MS |
710 | expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } }; |
711 | do_push(specs, ARRAY_SIZE(specs), | |
712 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 713 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
abeefbbe MS |
714 | } |
715 | ||
1c13b0bf ET |
716 | void test_online_push__tag_to_tag(void) |
717 | { | |
718 | const char *specs[] = { "refs/tags/tag-tag:refs/tags/tag-tag" }; | |
9d41984c | 719 | push_status exp_stats[] = { { "refs/tags/tag-tag", 1 } }; |
1c13b0bf ET |
720 | expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } }; |
721 | do_push(specs, ARRAY_SIZE(specs), | |
722 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 723 | exp_refs, ARRAY_SIZE(exp_refs), 0, 0, 0); |
1c13b0bf ET |
724 | } |
725 | ||
6443eaf2 | 726 | void test_online_push__force(void) |
613d5eb9 PK |
727 | { |
728 | const char *specs1[] = {"refs/heads/b3:refs/heads/tgt"}; | |
9d41984c | 729 | push_status exp_stats1[] = { { "refs/heads/tgt", 1 } }; |
613d5eb9 PK |
730 | expected_ref exp_refs1[] = { { "refs/heads/tgt", &_oid_b3 } }; |
731 | ||
732 | const char *specs2[] = {"refs/heads/b4:refs/heads/tgt"}; | |
733 | ||
734 | const char *specs2_force[] = {"+refs/heads/b4:refs/heads/tgt"}; | |
9d41984c | 735 | push_status exp_stats2_force[] = { { "refs/heads/tgt", 1 } }; |
613d5eb9 PK |
736 | expected_ref exp_refs2_force[] = { { "refs/heads/tgt", &_oid_b4 } }; |
737 | ||
738 | do_push(specs1, ARRAY_SIZE(specs1), | |
739 | exp_stats1, ARRAY_SIZE(exp_stats1), | |
f70cfd34 | 740 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1); |
613d5eb9 PK |
741 | |
742 | do_push(specs2, ARRAY_SIZE(specs2), | |
743 | NULL, 0, | |
f70cfd34 | 744 | exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0, 0); |
613d5eb9 PK |
745 | |
746 | /* Non-fast-forward update with force should pass. */ | |
f70cfd34 | 747 | record_callbacks_data_clear(&_record_cbs_data); |
613d5eb9 PK |
748 | do_push(specs2_force, ARRAY_SIZE(specs2_force), |
749 | exp_stats2_force, ARRAY_SIZE(exp_stats2_force), | |
f70cfd34 | 750 | exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1, 1); |
613d5eb9 PK |
751 | } |
752 | ||
6443eaf2 | 753 | void test_online_push__delete(void) |
613d5eb9 PK |
754 | { |
755 | const char *specs1[] = { | |
756 | "refs/heads/b1:refs/heads/tgt1", | |
757 | "refs/heads/b1:refs/heads/tgt2" | |
758 | }; | |
759 | push_status exp_stats1[] = { | |
9d41984c ET |
760 | { "refs/heads/tgt1", 1 }, |
761 | { "refs/heads/tgt2", 1 } | |
613d5eb9 PK |
762 | }; |
763 | expected_ref exp_refs1[] = { | |
764 | { "refs/heads/tgt1", &_oid_b1 }, | |
765 | { "refs/heads/tgt2", &_oid_b1 } | |
766 | }; | |
767 | ||
768 | const char *specs_del_fake[] = { ":refs/heads/fake" }; | |
769 | /* Force has no effect for delete. */ | |
770 | const char *specs_del_fake_force[] = { "+:refs/heads/fake" }; | |
9d41984c | 771 | push_status exp_stats_fake[] = { { "refs/heads/fake", 1 } }; |
613d5eb9 PK |
772 | |
773 | const char *specs_delete[] = { ":refs/heads/tgt1" }; | |
9d41984c | 774 | push_status exp_stats_delete[] = { { "refs/heads/tgt1", 1 } }; |
613d5eb9 PK |
775 | expected_ref exp_refs_delete[] = { { "refs/heads/tgt2", &_oid_b1 } }; |
776 | /* Force has no effect for delete. */ | |
777 | const char *specs_delete_force[] = { "+:refs/heads/tgt1" }; | |
778 | ||
779 | do_push(specs1, ARRAY_SIZE(specs1), | |
780 | exp_stats1, ARRAY_SIZE(exp_stats1), | |
f70cfd34 | 781 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1); |
613d5eb9 | 782 | |
d73d52df CW |
783 | /* When deleting a non-existent branch, the git client sends zero for both |
784 | * the old and new commit id. This should succeed on the server with the | |
785 | * same status report as if the branch were actually deleted. The server | |
786 | * returns a warning on the side-band iff the side-band is supported. | |
787 | * Since libgit2 doesn't support the side-band yet, there are no warnings. | |
613d5eb9 PK |
788 | */ |
789 | do_push(specs_del_fake, ARRAY_SIZE(specs_del_fake), | |
d73d52df | 790 | exp_stats_fake, 1, |
f70cfd34 | 791 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0); |
613d5eb9 | 792 | do_push(specs_del_fake_force, ARRAY_SIZE(specs_del_fake_force), |
d73d52df | 793 | exp_stats_fake, 1, |
f70cfd34 | 794 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0); |
613d5eb9 PK |
795 | |
796 | /* Delete one of the pushed branches. */ | |
797 | do_push(specs_delete, ARRAY_SIZE(specs_delete), | |
798 | exp_stats_delete, ARRAY_SIZE(exp_stats_delete), | |
f70cfd34 | 799 | exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0); |
613d5eb9 PK |
800 | |
801 | /* Re-push branches and retry delete with force. */ | |
802 | do_push(specs1, ARRAY_SIZE(specs1), | |
803 | exp_stats1, ARRAY_SIZE(exp_stats1), | |
f70cfd34 | 804 | exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0); |
613d5eb9 PK |
805 | do_push(specs_delete_force, ARRAY_SIZE(specs_delete_force), |
806 | exp_stats_delete, ARRAY_SIZE(exp_stats_delete), | |
f70cfd34 | 807 | exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0); |
613d5eb9 PK |
808 | } |
809 | ||
6443eaf2 | 810 | void test_online_push__bad_refspecs(void) |
613d5eb9 PK |
811 | { |
812 | /* All classes of refspecs that should be rejected by | |
813 | * git_push_add_refspec() should go in this test. | |
814 | */ | |
815 | git_push *push; | |
816 | ||
817 | if (_remote) { | |
11bd7a03 | 818 | /* cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH)); */ |
613d5eb9 PK |
819 | cl_git_pass(git_push_new(&push, _remote)); |
820 | ||
821 | /* Unexpanded branch names not supported */ | |
822 | cl_git_fail(git_push_add_refspec(push, "b6:b6")); | |
823 | ||
824 | git_push_free(push); | |
825 | } | |
826 | } | |
827 | ||
6443eaf2 | 828 | void test_online_push__expressions(void) |
613d5eb9 PK |
829 | { |
830 | /* TODO: Expressions in refspecs doesn't actually work yet */ | |
831 | const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" }; | |
832 | ||
9d41984c ET |
833 | /* expect not NULL to indicate failure (core git replies "funny refname", |
834 | * other servers may be less pithy. */ | |
613d5eb9 | 835 | const char *specs_right_expr[] = { "refs/heads/b2:refs/heads/b2~1" }; |
9d41984c | 836 | push_status exp_stats_right_expr[] = { { "refs/heads/b2~1", 0 } }; |
613d5eb9 PK |
837 | |
838 | /* TODO: Find a more precise way of checking errors than a exit code of -1. */ | |
839 | do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr), | |
840 | NULL, 0, | |
f70cfd34 | 841 | NULL, 0, -1, 0, 0); |
613d5eb9 PK |
842 | |
843 | do_push(specs_right_expr, ARRAY_SIZE(specs_right_expr), | |
844 | exp_stats_right_expr, ARRAY_SIZE(exp_stats_right_expr), | |
f70cfd34 | 845 | NULL, 0, 0, 1, 1); |
613d5eb9 | 846 | } |
087f64d3 | 847 | |
abeefbbe | 848 | void test_online_push__notes(void) |
087f64d3 JM |
849 | { |
850 | git_oid note_oid, *target_oid, expected_oid; | |
851 | git_signature *signature; | |
852 | const char *specs[] = { "refs/notes/commits:refs/notes/commits" }; | |
9d41984c | 853 | push_status exp_stats[] = { { "refs/notes/commits", 1 } }; |
087f64d3 JM |
854 | expected_ref exp_refs[] = { { "refs/notes/commits", &expected_oid } }; |
855 | git_oid_fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb"); | |
856 | ||
857 | target_oid = &_oid_b6; | |
858 | ||
859 | /* Create note to push */ | |
860 | cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ | |
abeefbbe | 861 | cl_git_pass(git_note_create(¬e_oid, _repo, signature, signature, NULL, target_oid, "hello world\n", 0)); |
087f64d3 JM |
862 | |
863 | do_push(specs, ARRAY_SIZE(specs), | |
864 | exp_stats, ARRAY_SIZE(exp_stats), | |
f70cfd34 | 865 | exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); |
087f64d3 JM |
866 | |
867 | git_signature_free(signature); | |
868 | } |