Verify update_tips callbacks in push test cases
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
diff --git a/tests/online/push.c b/tests/online/push.c
index 716e2e9..6da27bb 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -254,8 +254,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
}
failed:
-
- if(failed)
+ if (failed)
cl_fail(git_buf_cstr(&msg));
git_vector_foreach(&actual_refs, i, actual_ref)
@@ -264,7 +263,52 @@ failed:
git_vector_free(&actual_refs);
git_buf_free(&msg);
git_buf_free(&ref_name);
- return;
+}
+
+static void verify_update_tips_callback(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
+{
+ git_refspec *fetch_spec;
+ git_buf msg = GIT_BUF_INIT;
+ git_buf ref_name = GIT_BUF_INIT;
+ updated_tip *tip = NULL;
+ size_t i, j;
+ int failed = 0;
+
+ for (i = 0; i < expected_refs_len; ++i) {
+ /* Convert remote reference name into tracking branch name.
+ * If the spec is not under refs/heads/, then skip.
+ */
+ fetch_spec = git_remote__matching_refspec(remote, expected_refs[i].name);
+ if (!fetch_spec)
+ continue;
+
+ cl_git_pass(git_refspec_transform(&ref_name, fetch_spec, expected_refs[i].name));
+
+ /* Find matching update_tip entry */
+ git_vector_foreach(&_record_cbs_data.updated_tips, j, tip) {
+ if (!strcmp(git_buf_cstr(&ref_name), tip->name))
+ break;
+ }
+
+ if (j == _record_cbs_data.updated_tips.length) {
+ git_buf_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", git_buf_cstr(&ref_name));
+ failed = 1;
+ goto failed;
+ }
+
+ if (git_oid_cmp(expected_refs[i].oid, tip->new_oid) != 0) {
+ git_buf_printf(&msg, "Updated tip ID does not match expected ID");
+ failed = 1;
+ goto failed;
+ }
+ }
+
+failed:
+ if (failed)
+ cl_fail(git_buf_cstr(&msg));
+
+ git_buf_free(&ref_name);
+ git_buf_free(&msg);
}
void test_online_push__initialize(void)
@@ -409,7 +453,7 @@ static void do_push(
const char *refspecs[], size_t refspecs_len,
push_status expected_statuses[], size_t expected_statuses_len,
expected_ref expected_refs[], size_t expected_refs_len,
- int expected_ret, int check_progress_cb)
+ int expected_ret, int check_progress_cb, int check_update_tips_cb)
{
git_push *push;
git_push_options opts = GIT_PUSH_OPTIONS_INIT;
@@ -461,6 +505,9 @@ static void do_push(
cl_git_pass(git_push_update_tips(push, pusher, "test push"));
verify_tracking_branches(_remote, expected_refs, expected_refs_len);
+ if (check_update_tips_cb)
+ verify_update_tips_callback(_remote, expected_refs, expected_refs_len);
+
git_push_free(push);
git_remote_disconnect(_remote);
@@ -472,7 +519,7 @@ static void do_push(
/* Call push_finish() without ever calling git_push_add_refspec() */
void test_online_push__noop(void)
{
- do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0);
+ do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0, 1);
}
void test_online_push__b1(void)
@@ -482,7 +529,7 @@ void test_online_push__b1(void)
expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__b2(void)
@@ -492,7 +539,7 @@ void test_online_push__b2(void)
expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__b3(void)
@@ -502,7 +549,7 @@ void test_online_push__b3(void)
expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__b4(void)
@@ -512,7 +559,7 @@ void test_online_push__b4(void)
expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__b5(void)
@@ -522,13 +569,13 @@ void test_online_push__b5(void)
expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__b5_cancel(void)
{
const char *specs[] = { "refs/heads/b5:refs/heads/b5" };
- do_push(specs, ARRAY_SIZE(specs), NULL, 0, NULL, 0, GIT_EUSER, 1);
+ do_push(specs, ARRAY_SIZE(specs), NULL, 0, NULL, 0, GIT_EUSER, 1, 1);
}
void test_online_push__multi(void)
@@ -559,7 +606,7 @@ void test_online_push__multi(void)
};
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
cl_git_pass(git_reflog_read(&log, _repo, "refs/remotes/test/b1"));
entry = git_reflog_entry_byindex(log, 0);
@@ -586,10 +633,10 @@ void test_online_push__implicit_tgt(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
do_push(specs2, ARRAY_SIZE(specs2),
exp_stats2, ARRAY_SIZE(exp_stats2),
- exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0);
+ exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0, 0);
}
void test_online_push__fast_fwd(void)
@@ -611,19 +658,19 @@ void test_online_push__fast_fwd(void)
do_push(specs_init, ARRAY_SIZE(specs_init),
exp_stats_init, ARRAY_SIZE(exp_stats_init),
- exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1);
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1, 1);
do_push(specs_ff, ARRAY_SIZE(specs_ff),
exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
- exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0);
do_push(specs_reset, ARRAY_SIZE(specs_reset),
exp_stats_init, ARRAY_SIZE(exp_stats_init),
- exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0);
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0, 0);
do_push(specs_ff_force, ARRAY_SIZE(specs_ff_force),
exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
- exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0);
}
void test_online_push__tag_commit(void)
@@ -633,7 +680,7 @@ void test_online_push__tag_commit(void)
expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__tag_tree(void)
@@ -643,7 +690,7 @@ void test_online_push__tag_tree(void)
expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__tag_blob(void)
@@ -653,7 +700,7 @@ void test_online_push__tag_blob(void)
expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__tag_lightweight(void)
@@ -663,7 +710,7 @@ void test_online_push__tag_lightweight(void)
expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
}
void test_online_push__tag_to_tag(void)
@@ -673,7 +720,7 @@ void test_online_push__tag_to_tag(void)
expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 0, 0);
}
void test_online_push__force(void)
@@ -690,16 +737,17 @@ void test_online_push__force(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
do_push(specs2, ARRAY_SIZE(specs2),
NULL, 0,
- exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0, 0);
/* Non-fast-forward update with force should pass. */
+ record_callbacks_data_clear(&_record_cbs_data);
do_push(specs2_force, ARRAY_SIZE(specs2_force),
exp_stats2_force, ARRAY_SIZE(exp_stats2_force),
- exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1);
+ exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1, 1);
}
void test_online_push__delete(void)
@@ -730,7 +778,7 @@ void test_online_push__delete(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
/* When deleting a non-existent branch, the git client sends zero for both
* the old and new commit id. This should succeed on the server with the
@@ -740,23 +788,23 @@ void test_online_push__delete(void)
*/
do_push(specs_del_fake, ARRAY_SIZE(specs_del_fake),
exp_stats_fake, 1,
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
do_push(specs_del_fake_force, ARRAY_SIZE(specs_del_fake_force),
exp_stats_fake, 1,
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
/* Delete one of the pushed branches. */
do_push(specs_delete, ARRAY_SIZE(specs_delete),
exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
- exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0);
/* Re-push branches and retry delete with force. */
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
do_push(specs_delete_force, ARRAY_SIZE(specs_delete_force),
exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
- exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0);
}
void test_online_push__bad_refspecs(void)
@@ -790,11 +838,11 @@ void test_online_push__expressions(void)
/* TODO: Find a more precise way of checking errors than a exit code of -1. */
do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
NULL, 0,
- NULL, 0, -1, 0);
+ NULL, 0, -1, 0, 0);
do_push(specs_right_expr, ARRAY_SIZE(specs_right_expr),
exp_stats_right_expr, ARRAY_SIZE(exp_stats_right_expr),
- NULL, 0, 0, 1);
+ NULL, 0, 0, 1, 1);
}
void test_online_push__notes(void)
@@ -814,7 +862,7 @@ void test_online_push__notes(void)
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
git_signature_free(signature);
}