Branch Coverage

deps/libgit2/src/libgit2/rebase.c
Criterion Covered Total %
branch 231 508 45.4


line true false branch
99 0 3 if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
102 0 3 if (git_fs_path_isdir(git_str_cstr(&path))) {
108 0 3 if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
111 1 2 if (git_fs_path_isdir(git_str_cstr(&path))) {
112 0 1 if (git_str_joinpath(&interactive_path, path.ptr, INTERACTIVE_FILE) < 0)
115 0 1 if (git_fs_path_isfile(interactive_path.ptr))
126 1 2 if (type != GIT_REBASE_NONE && path_out)
1 0 if (type != GIT_REBASE_NONE && path_out)
145 7 0 if ((error = git_str_joinpath(state_path, state_path->ptr, filename)) < 0 ||
7 0 if ((error = git_str_joinpath(state_path, state_path->ptr, filename)) < 0 ||
163 0 2 if ((error = rebase_readfile(asc_out, state_path, filename)) < 0)
166 2 0 if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) {
2 0 if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) {
0 2 if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) {
181 0 4 if ((error = rebase_readfile(str_out, state_path, filename)) < 0)
184 4 0 if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) {
0 4 if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) {
200 0 9 GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !id, NULL);
201 0 9 GIT_ASSERT_WITH_RETVAL((type == GIT_REBASE_OPERATION_EXEC) == !!exec, NULL);
203 2 7 if ((operation = git_array_alloc(rebase->operations)) == NULL)
2 0 if ((operation = git_array_alloc(rebase->operations)) == NULL)
0 9 if ((operation = git_array_alloc(rebase->operations)) == NULL)
221 0 1 if ((error = git_str_puts(&state_path, rebase->state_path)) < 0)
225 0 1 if ((error = rebase_readint(&msgnum, &buf, &state_path, MSGNUM_FILE)) < 0 &&
0 0 if ((error = rebase_readint(&msgnum, &buf, &state_path, MSGNUM_FILE)) < 0 &&
229 1 0 if (msgnum) {
235 0 1 if ((error = rebase_readint(&end, &buf, &state_path, END_FILE)) < 0)
239 0 1 if ((error = rebase_readoid(&id, &buf, &state_path, CURRENT_FILE)) < 0 &&
0 0 if ((error = rebase_readoid(&id, &buf, &state_path, CURRENT_FILE)) < 0 &&
245 0 1 GIT_ERROR_CHECK_ARRAY(rebase->operations);
247 3 1 for (i = 0; i < end; i++) {
250 3 0 if ((error = git_str_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
3 0 if ((error = git_str_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
255 0 3 GIT_ERROR_CHECK_ALLOC(operation);
259 0 1 if ((error = rebase_readfile(&buf, &state_path, ONTO_NAME_FILE)) < 0)
275 0 4 GIT_ERROR_CHECK_ALLOC(rebase);
279 4 0 if (rebase_opts)
284 4 0 if (rebase_opts && rebase_opts->rewrite_notes_ref) {
0 4 if (rebase_opts && rebase_opts->rewrite_notes_ref) {
286 0 0 GIT_ERROR_CHECK_ALLOC(rebase->options.rewrite_notes_ref);
296 0 4 GIT_ERROR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
298 4 0 if (given_opts)
299 0 4 GIT_ERROR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options");
315 0 1 GIT_ASSERT_ARG(repo);
317 0 1 if ((error = rebase_check_versions(given_opts)) < 0)
320 0 1 if (rebase_alloc(&rebase, given_opts) < 0)
325 0 1 if ((error = rebase_state_type(&rebase->type, &rebase->state_path, repo)) < 0)
328 0 1 if (rebase->type == GIT_REBASE_NONE) {
334 0 1 if ((error = git_str_puts(&path, rebase->state_path)) < 0)
339 1 0 if ((error = git_str_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
1 0 if ((error = git_str_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
345 1 0 if (strcmp(ORIG_DETACHED_HEAD, orig_head_name.ptr) == 0)
350 0 1 if ((error = git_str_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
353 0 1 if (!git_fs_path_isfile(path.ptr)) {
357 0 0 if ((error = git_str_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
361 0 1 if ((error = git_futils_readbuffer(&orig_head_id, path.ptr)) < 0)
366 0 1 if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0)
371 1 0 if ((error = git_str_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
1 0 if ((error = git_str_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
377 0 1 if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0)
380 0 1 if (!rebase->head_detached)
400 1 0 if (error == 0)
414 2 0 if (!rebase || rebase->inmemory)
0 2 if (!rebase || rebase->inmemory)
418 1 1 git_futils_rmdir_r(rebase->state_path, NULL, GIT_RMDIR_REMOVE_FILES) :
433 24 0 if ((error = git_str_joinpath(&path, rebase->state_path, filename)) == 0)
444 2 2 if (onto->ref_name && git__strncmp(onto->ref_name, "refs/heads/", 11) == 0)
2 0 if (onto->ref_name && git__strncmp(onto->ref_name, "refs/heads/", 11) == 0)
446 0 2 else if (onto->ref_name)
460 2 0 if ((error = rebase_setupfile(rebase, END_FILE, 0, "%" PRIuZ "\n", git_array_size(rebase->operations))) < 0 ||
2 0 if ((error = rebase_setupfile(rebase, END_FILE, 0, "%" PRIuZ "\n", git_array_size(rebase->operations))) < 0 ||
464 3 2 for (i = 0; i < git_array_size(rebase->operations); i++) {
465 3 0 operation = git_array_get(rebase->operations, i);
472 0 3 if ((error = rebase_setupfile(rebase, commit_filename.ptr, 0,
490 0 2 if (p_mkdir(rebase->state_path, REBASE_DIR_MODE) < 0) {
495 0 2 orig_head_name = rebase->head_detached ? ORIG_DETACHED_HEAD :
499 2 0 rebase_setupfile(rebase, HEAD_NAME_FILE, 0, "%s\n", orig_head_name) < 0 ||
500 2 0 rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 ||
501 0 2 rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 ||
502 1 1 rebase_setupfile(rebase, QUIET_FILE, 0, rebase->quiet ? "t\n" : "\n") < 0)
510 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(
527 0 2 if ((error = rebase_state_type(&type, NULL, repo)) < 0)
530 0 2 if (type != GIT_REBASE_NONE) {
549 2 3 if (check_index) {
550 2 0 if ((error = git_repository_head_tree(&head, repo)) < 0 ||
2 0 if ((error = git_repository_head_tree(&head, repo)) < 0 ||
551 2 0 (error = git_repository_index(&index, repo)) < 0 ||
555 0 2 if (git_diff_num_deltas(diff) > 0) {
565 5 0 if (check_workdir) {
568 0 5 if ((error = git_diff_index_to_workdir(&diff, repo, index, &diff_opts)) < 0)
571 0 5 if (git_diff_num_deltas(diff) > 0) {
600 0 3 if (!upstream)
603 3 0 if ((error = git_revwalk_new(&revwalk, rebase->repo)) < 0 ||
3 0 if ((error = git_revwalk_new(&revwalk, rebase->repo)) < 0 ||
604 3 0 (error = git_revwalk_push(revwalk, git_annotated_commit_id(branch))) < 0 ||
610 6 3 while ((error = git_revwalk_next(&id, revwalk)) == 0) {
611 0 6 if ((error = git_commit_lookup(&commit, repo, &id)) < 0)
617 0 6 if (merge)
621 0 6 GIT_ERROR_CHECK_ALLOC(operation);
646 0 2 if ((error = git_str_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
650 0 2 GIT_ERROR_CHECK_ALLOC(rebase->state_path);
652 0 2 if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
0 0 if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
654 0 0 GIT_ERROR_CHECK_ALLOC(rebase->orig_head_name);
660 0 2 GIT_ERROR_CHECK_ALLOC(rebase->onto_name);
667 2 0 if ((error = rebase_setupfiles(rebase)) < 0 ||
2 0 if ((error = rebase_setupfiles(rebase)) < 0 ||
669 2 0 "rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
671 2 0 &onto_commit, repo, git_annotated_commit_id(onto))) < 0 ||
712 3 0 bool inmemory = (given_opts && given_opts->inmemory);
1 2 bool inmemory = (given_opts && given_opts->inmemory);
715 0 3 GIT_ASSERT_ARG(repo);
716 0 3 GIT_ASSERT_ARG(upstream || onto);
0 0 GIT_ASSERT_ARG(upstream || onto);
720 0 3 if (!onto)
723 0 3 if ((error = rebase_check_versions(given_opts)) < 0)
726 2 1 if (!inmemory) {
727 2 0 if ((error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
2 0 if ((error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
728 2 0 (error = rebase_ensure_not_in_progress(repo)) < 0 ||
733 0 3 if (!branch) {
734 0 0 if ((error = git_repository_head(&head_ref, repo)) < 0 ||
0 0 if ((error = git_repository_head(&head_ref, repo)) < 0 ||
741 0 3 if (rebase_alloc(&rebase, given_opts) < 0)
748 0 3 if ((error = rebase_init_operations(rebase, repo, branch, upstream, onto)) < 0)
751 1 2 if (inmemory)
756 3 0 if (error == 0)
763 0 3 if (error < 0) {
778 3 0 if (!checkout_opts->ancestor_label)
781 3 0 if (rebase->type == GIT_REBASE_MERGE) {
782 3 0 if (!checkout_opts->our_label)
785 3 0 if (!checkout_opts->their_label)
794 3 2 size_t next = rebase->started ? rebase->current + 1 : 0;
796 1 4 if (next == git_array_size(rebase->operations))
822 3 0 operation = git_array_get(rebase->operations, rebase->current);
824 3 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
3 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
825 3 0 (error = git_commit_tree(¤t_tree, current_commit)) < 0 ||
829 0 3 if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
833 3 0 } else if (parent_count) {
834 3 0 if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
3 0 if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
843 3 0 if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
3 0 if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
844 3 0 (error = rebase_setupfile(rebase, MSGNUM_FILE, 0, "%" PRIuZ "\n", rebase->current+1)) < 0 ||
845 3 0 (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 ||
846 3 0 (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 ||
847 3 0 (error = git_merge__check_result(rebase->repo, index)) < 0 ||
848 3 0 (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 ||
880 1 0 operation = git_array_get(rebase->operations, rebase->current);
882 1 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
1 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
886 0 1 if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
890 1 0 } else if (parent_count) {
891 1 0 if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
1 0 if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
896 1 0 if ((error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
1 0 if ((error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
900 1 0 if (!rebase->index) {
904 0 0 if ((error = git_index_read_index(rebase->index, index)) < 0)
927 0 5 GIT_ASSERT_ARG(out);
928 0 5 GIT_ASSERT_ARG(rebase);
930 1 4 if ((error = rebase_movenext(rebase)) < 0)
933 1 3 if (rebase->inmemory)
935 3 0 else if (rebase->type == GIT_REBASE_MERGE)
947 0 1 GIT_ASSERT_ARG(out);
948 0 1 GIT_ASSERT_ARG(rebase);
949 0 1 GIT_ASSERT_ARG(rebase->index);
976 0 0 if ((error = git_commit__create_buffer(&commit_content,
985 0 0 if (error) {
986 0 0 if (error != GIT_PASSTHROUGH)
992 0 0 error = git_commit_create_with_signature(out, rebase->repo,
0 0 error = git_commit_create_with_signature(out, rebase->repo,
1021 3 0 operation = git_array_get(rebase->operations, rebase->current);
1023 0 3 if (git_index_has_conflicts(index)) {
1029 3 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
3 0 if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 ||
1030 3 0 (error = git_commit_tree(&parent_tree, parent_commit)) < 0 ||
1031 3 0 (error = git_index_write_tree_to(&tree_id, index, rebase->repo)) < 0 ||
1035 0 3 if (git_oid_equal(&tree_id, git_tree_id(parent_tree))) {
1041 0 3 if (!author)
1044 3 0 if (!message) {
1052 0 3 if (rebase->options.commit_create_cb) {
1062 0 3 else if (rebase->options.signing_cb) {
1069 3 0 if (error == GIT_PASSTHROUGH)
1074 0 3 if (error)
1077 0 3 if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)
1083 0 3 if (error < 0)
1108 3 0 operation = git_array_get(rebase->operations, rebase->current);
1109 0 3 GIT_ASSERT(operation);
1111 3 0 if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 ||
3 0 if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 ||
1112 3 0 (error = git_repository_head(&head, rebase->repo)) < 0 ||
1113 3 0 (error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)) < 0 ||
1114 3 0 (error = git_repository_index(&index, rebase->repo)) < 0 ||
1116 3 0 author, committer, message_encoding, message)) < 0 ||
1124 0 3 if ((error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND,
1149 0 0 GIT_ASSERT_ARG(rebase->index);
1150 0 0 GIT_ASSERT_ARG(rebase->last_commit);
1151 0 0 GIT_ASSERT_ARG(rebase->current < rebase->operations.size);
1153 0 0 if ((error = rebase_commit__create(&commit, rebase, rebase->index,
1163 0 0 if (error < 0)
1179 0 3 GIT_ASSERT_ARG(rebase);
1180 0 3 GIT_ASSERT_ARG(committer);
1182 0 3 if (rebase->inmemory)
1185 3 0 else if (rebase->type == GIT_REBASE_MERGE)
1200 0 1 GIT_ASSERT_ARG(rebase);
1202 0 1 if (rebase->inmemory)
1207 1 0 &rebase->orig_head_id, 1, "rebase: aborting") :
1212 0 1 if (error < 0)
1215 1 0 if ((error = git_commit_lookup(
1216 1 0 &orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
1235 0 1 if (rebase->options.rewrite_notes_ref) {
1242 1 0 if ((error = git_repository_config(&config, rebase->repo)) < 0 ||
1 0 if ((error = git_repository_config(&config, rebase->repo)) < 0 ||
1245 0 1 if (error != GIT_ENOTFOUND)
1253 1 0 git_config__get_string_buf(out, config, "notes.rewriteref") :
1273 0 0 if ((error = git_note_read(¬e, rebase->repo, notes_ref, from)) < 0) {
1274 0 0 if (error == GIT_ENOTFOUND) {
1282 0 0 if (!committer) {
1283 0 0 if((error = git_signature_default(&who, rebase->repo)) < 0) {
1284 0 0 if (error != GIT_ENOTFOUND ||
0 0 if (error != GIT_ENOTFOUND ||
1314 1 0 if ((error = notes_ref_lookup(¬es_ref, rebase)) < 0) {
1315 1 0 if (error == GIT_ENOTFOUND) {
1323 0 0 if ((error = git_str_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
0 0 if ((error = git_str_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
1329 0 0 while (*pair_list) {
1332 0 0 if ((end = strchr(fromstr, '\n')) == NULL)
1338 0 0 if ((end = strchr(fromstr, ' ')) == NULL)
1344 0 0 if (strlen(fromstr) != GIT_OID_HEXSZ ||
0 0 if (strlen(fromstr) != GIT_OID_HEXSZ ||
1345 0 0 strlen(tostr) != GIT_OID_HEXSZ ||
1346 0 0 git_oid_fromstr(&from, fromstr) < 0 ||
1350 0 0 if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0)
1380 0 0 if ((error = git_str_printf(&branch_msg,
1382 0 0 rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
1385 0 0 rebase->orig_head_name)) == 0 &&
1386 0 0 (error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
1388 0 0 terminal_ref, GIT_OBJECT_COMMIT)) == 0 &&
1413 0 1 GIT_ASSERT_ARG(rebase);
1415 0 1 if (rebase->inmemory)
1418 0 1 if (!rebase->head_detached)
1421 1 0 if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
1 0 if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
1428 0 1 GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1433 0 1 GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1438 0 1 GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1448 0 10 GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0);
1455 0 3 GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0);
1457 2 1 return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION;
1462 0 6 GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
1464 5 1 return git_array_get(rebase->operations, idx);
1469 0 4 if (rebase == NULL)