Branch Coverage

deps/libgit2/src/rebase.c
Criterion Covered Total %
branch 227 498 45.5


line true false branch
96 0 3 if (git_buf_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
99 0 3 if (git_path_isdir(git_buf_cstr(&path))) {
105 0 3 if (git_buf_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
108 1 2 if (git_path_isdir(git_buf_cstr(&path))) {
116 1 2 if (type != GIT_REBASE_NONE && path_out)
1 0 if (type != GIT_REBASE_NONE && path_out)
134 7 0 if ((error = git_buf_joinpath(state_path, state_path->ptr, filename)) < 0 ||
7 0 if ((error = git_buf_joinpath(state_path, state_path->ptr, filename)) < 0 ||
152 0 2 if ((error = rebase_readfile(asc_out, state_path, filename)) < 0)
155 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) {
170 0 4 if ((error = rebase_readfile(str_out, state_path, filename)) < 0)
173 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) {
189 0 9 assert((type == GIT_REBASE_OPERATION_EXEC) == !id);
190 0 9 assert((type == GIT_REBASE_OPERATION_EXEC) == !!exec);
192 2 7 if ((operation = git_array_alloc(rebase->operations)) == NULL)
7 0 if ((operation = git_array_alloc(rebase->operations)) == NULL)
0 9 if ((operation = git_array_alloc(rebase->operations)) == NULL)
210 0 1 if ((error = git_buf_puts(&state_path, rebase->state_path)) < 0)
214 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 &&
218 1 0 if (msgnum) {
224 0 1 if ((error = rebase_readint(&end, &buf, &state_path, END_FILE)) < 0)
228 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 &&
234 0 1 GIT_ERROR_CHECK_ARRAY(rebase->operations);
236 3 1 for (i = 0; i < end; i++) {
239 3 0 if ((error = git_buf_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
3 0 if ((error = git_buf_printf(&cmt, "cmt.%" PRIuZ, (i+1))) < 0 ||
244 0 3 GIT_ERROR_CHECK_ALLOC(operation);
248 0 1 if ((error = rebase_readfile(&buf, &state_path, ONTO_NAME_FILE)) < 0)
264 0 4 GIT_ERROR_CHECK_ALLOC(rebase);
268 4 0 if (rebase_opts)
273 4 0 if (rebase_opts && rebase_opts->rewrite_notes_ref) {
0 4 if (rebase_opts && rebase_opts->rewrite_notes_ref) {
275 0 0 GIT_ERROR_CHECK_ALLOC(rebase->options.rewrite_notes_ref);
285 0 4 GIT_ERROR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
287 4 0 if (given_opts)
288 0 4 GIT_ERROR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options");
304 0 1 assert(repo);
306 0 1 if ((error = rebase_check_versions(given_opts)) < 0)
309 0 1 if (rebase_alloc(&rebase, given_opts) < 0)
314 0 1 if ((error = rebase_state_type(&rebase->type, &rebase->state_path, repo)) < 0)
317 0 1 if (rebase->type == GIT_REBASE_NONE) {
323 0 1 if ((error = git_buf_puts(&path, rebase->state_path)) < 0)
328 1 0 if ((error = git_buf_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
1 0 if ((error = git_buf_joinpath(&path, path.ptr, HEAD_NAME_FILE)) < 0 ||
334 1 0 if (strcmp(ORIG_DETACHED_HEAD, orig_head_name.ptr) == 0)
339 0 1 if ((error = git_buf_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0)
342 0 1 if (!git_path_isfile(path.ptr)) {
346 0 0 if ((error = git_buf_joinpath(&path, path.ptr, HEAD_FILE)) < 0)
350 0 1 if ((error = git_futils_readbuffer(&orig_head_id, path.ptr)) < 0)
355 0 1 if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0)
360 1 0 if ((error = git_buf_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
1 0 if ((error = git_buf_joinpath(&path, path.ptr, ONTO_FILE)) < 0 ||
366 0 1 if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0)
369 0 1 if (!rebase->head_detached)
389 1 0 if (error == 0)
403 2 0 if (!rebase || rebase->inmemory)
0 2 if (!rebase || rebase->inmemory)
407 1 1 git_futils_rmdir_r(rebase->state_path, NULL, GIT_RMDIR_REMOVE_FILES) :
422 24 0 if ((error = git_buf_joinpath(&path, rebase->state_path, filename)) == 0)
433 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)
435 0 2 else if (onto->ref_name)
449 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 ||
453 3 2 for (i = 0; i < git_array_size(rebase->operations); i++) {
454 3 0 operation = git_array_get(rebase->operations, i);
461 0 3 if ((error = rebase_setupfile(rebase, commit_filename.ptr, 0,
479 0 2 if (p_mkdir(rebase->state_path, REBASE_DIR_MODE) < 0) {
484 0 2 orig_head_name = rebase->head_detached ? ORIG_DETACHED_HEAD :
488 2 0 rebase_setupfile(rebase, HEAD_NAME_FILE, 0, "%s\n", orig_head_name) < 0 ||
489 2 0 rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 ||
490 0 2 rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 ||
491 1 1 rebase_setupfile(rebase, QUIET_FILE, 0, rebase->quiet ? "t\n" : "\n") < 0)
499 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(
516 0 2 if ((error = rebase_state_type(&type, NULL, repo)) < 0)
519 0 2 if (type != GIT_REBASE_NONE) {
538 2 3 if (check_index) {
539 2 0 if ((error = git_repository_head_tree(&head, repo)) < 0 ||
2 0 if ((error = git_repository_head_tree(&head, repo)) < 0 ||
540 2 0 (error = git_repository_index(&index, repo)) < 0 ||
544 0 2 if (git_diff_num_deltas(diff) > 0) {
554 5 0 if (check_workdir) {
557 0 5 if ((error = git_diff_index_to_workdir(&diff, repo, index, &diff_opts)) < 0)
560 0 5 if (git_diff_num_deltas(diff) > 0) {
589 0 3 if (!upstream)
592 3 0 if ((error = git_revwalk_new(&revwalk, rebase->repo)) < 0 ||
3 0 if ((error = git_revwalk_new(&revwalk, rebase->repo)) < 0 ||
593 3 0 (error = git_revwalk_push(revwalk, git_annotated_commit_id(branch))) < 0 ||
599 6 3 while ((error = git_revwalk_next(&id, revwalk)) == 0) {
600 0 6 if ((error = git_commit_lookup(&commit, repo, &id)) < 0)
606 0 6 if (merge)
610 0 6 GIT_ERROR_CHECK_ALLOC(operation);
635 0 2 if ((error = git_buf_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
639 0 2 GIT_ERROR_CHECK_ALLOC(rebase->state_path);
641 0 2 if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
0 0 if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
643 0 0 GIT_ERROR_CHECK_ALLOC(rebase->orig_head_name);
649 0 2 GIT_ERROR_CHECK_ALLOC(rebase->onto_name);
656 2 0 if ((error = rebase_setupfiles(rebase)) < 0 ||
2 0 if ((error = rebase_setupfiles(rebase)) < 0 ||
658 2 0 "rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
660 2 0 &onto_commit, repo, git_annotated_commit_id(onto))) < 0 ||
701 3 0 bool inmemory = (given_opts && given_opts->inmemory);
1 2 bool inmemory = (given_opts && given_opts->inmemory);
704 3 0 assert(repo && (upstream || onto));
0 3 assert(repo && (upstream || onto));
0 0 assert(repo && (upstream || onto));
708 0 3 if (!onto)
711 0 3 if ((error = rebase_check_versions(given_opts)) < 0)
714 2 1 if (!inmemory) {
715 2 0 if ((error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
2 0 if ((error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
716 2 0 (error = rebase_ensure_not_in_progress(repo)) < 0 ||
721 0 3 if (!branch) {
722 0 0 if ((error = git_repository_head(&head_ref, repo)) < 0 ||
0 0 if ((error = git_repository_head(&head_ref, repo)) < 0 ||
729 0 3 if (rebase_alloc(&rebase, given_opts) < 0)
736 0 3 if ((error = rebase_init_operations(rebase, repo, branch, upstream, onto)) < 0)
739 1 2 if (inmemory)
744 3 0 if (error == 0)
751 0 3 if (error < 0) {
766 3 0 if (!checkout_opts->ancestor_label)
769 3 0 if (rebase->type == GIT_REBASE_MERGE) {
770 3 0 if (!checkout_opts->our_label)
773 3 0 if (!checkout_opts->their_label)
782 3 2 size_t next = rebase->started ? rebase->current + 1 : 0;
784 1 4 if (next == git_array_size(rebase->operations))
810 3 0 operation = git_array_get(rebase->operations, rebase->current);
812 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 ||
813 3 0 (error = git_commit_tree(¤t_tree, current_commit)) < 0 ||
817 0 3 if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
821 3 0 } else if (parent_count) {
822 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 ||
831 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 ||
832 3 0 (error = rebase_setupfile(rebase, MSGNUM_FILE, 0, "%" PRIuZ "\n", rebase->current+1)) < 0 ||
833 3 0 (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 ||
834 3 0 (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 ||
835 3 0 (error = git_merge__check_result(rebase->repo, index)) < 0 ||
836 3 0 (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 ||
868 1 0 operation = git_array_get(rebase->operations, rebase->current);
870 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 ||
874 0 1 if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
878 1 0 } else if (parent_count) {
879 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 ||
884 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 ||
888 1 0 if (!rebase->index) {
892 0 0 if ((error = git_index_read_index(rebase->index, index)) < 0)
915 5 0 assert(out && rebase);
0 5 assert(out && rebase);
917 1 4 if ((error = rebase_movenext(rebase)) < 0)
920 1 3 if (rebase->inmemory)
922 3 0 else if (rebase->type == GIT_REBASE_MERGE)
934 1 0 assert(out && rebase && rebase->index);
1 0 assert(out && rebase && rebase->index);
0 1 assert(out && rebase && rebase->index);
962 3 0 operation = git_array_get(rebase->operations, rebase->current);
964 0 3 if (git_index_has_conflicts(index)) {
970 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 ||
971 3 0 (error = git_commit_tree(&parent_tree, parent_commit)) < 0 ||
972 3 0 (error = git_index_write_tree_to(&tree_id, index, rebase->repo)) < 0 ||
976 0 3 if (git_oid_equal(&tree_id, git_tree_id(parent_tree))) {
982 0 3 if (!author)
985 3 0 if (!message) {
990 0 3 if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
994 0 3 if (rebase->options.signing_cb) {
999 0 0 if (error == GIT_PASSTHROUGH) {
1004 0 0 } else if (error < 0)
1008 0 3 if (git_buf_is_allocated(&commit_signature)) {
1009 0 0 assert(git_buf_contains_nul(&commit_signature));
1013 0 3 if (git_buf_is_allocated(&signature_field)) {
1014 0 0 assert(git_buf_contains_nul(&signature_field));
1018 0 3 if ((error = git_commit_create_with_signature(&commit_id, rebase->repo,
1023 0 3 if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)
1029 0 3 if (error < 0)
1057 3 0 operation = git_array_get(rebase->operations, rebase->current);
1058 0 3 assert(operation);
1060 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 ||
1061 3 0 (error = git_repository_head(&head, rebase->repo)) < 0 ||
1062 3 0 (error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)) < 0 ||
1063 3 0 (error = git_repository_index(&index, rebase->repo)) < 0 ||
1065 3 0 author, committer, message_encoding, message)) < 0 ||
1073 0 3 if ((error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND,
1098 0 0 assert(rebase->index);
1099 0 0 assert(rebase->last_commit);
1100 0 0 assert(rebase->current < rebase->operations.size);
1102 0 0 if ((error = rebase_commit__create(&commit, rebase, rebase->index,
1112 0 0 if (error < 0)
1128 3 0 assert(rebase && committer);
0 3 assert(rebase && committer);
1130 0 3 if (rebase->inmemory)
1133 3 0 else if (rebase->type == GIT_REBASE_MERGE)
1148 0 1 assert(rebase);
1150 0 1 if (rebase->inmemory)
1155 1 0 &rebase->orig_head_id, 1, "rebase: aborting") :
1160 0 1 if (error < 0)
1163 1 0 if ((error = git_commit_lookup(
1164 1 0 &orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
1183 0 1 if (rebase->options.rewrite_notes_ref) {
1190 1 0 if ((error = git_repository_config(&config, rebase->repo)) < 0 ||
1 0 if ((error = git_repository_config(&config, rebase->repo)) < 0 ||
1193 0 1 if (error != GIT_ENOTFOUND)
1201 1 0 git_config_get_string_buf(out, config, "notes.rewriteref") :
1221 0 0 if ((error = git_note_read(¬e, rebase->repo, notes_ref, from)) < 0) {
1222 0 0 if (error == GIT_ENOTFOUND) {
1230 0 0 if (!committer) {
1231 0 0 if((error = git_signature_default(&who, rebase->repo)) < 0) {
1232 0 0 if (error != GIT_ENOTFOUND ||
0 0 if (error != GIT_ENOTFOUND ||
1262 1 0 if ((error = notes_ref_lookup(¬es_ref, rebase)) < 0) {
1263 1 0 if (error == GIT_ENOTFOUND) {
1271 0 0 if ((error = git_buf_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
0 0 if ((error = git_buf_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
1277 0 0 while (*pair_list) {
1280 0 0 if ((end = strchr(fromstr, '\n')) == NULL)
1286 0 0 if ((end = strchr(fromstr, ' ')) == NULL)
1292 0 0 if (strlen(fromstr) != GIT_OID_HEXSZ ||
0 0 if (strlen(fromstr) != GIT_OID_HEXSZ ||
1293 0 0 strlen(tostr) != GIT_OID_HEXSZ ||
1294 0 0 git_oid_fromstr(&from, fromstr) < 0 ||
1298 0 0 if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0)
1328 0 0 if ((error = git_buf_printf(&branch_msg,
1330 0 0 rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
1333 0 0 rebase->orig_head_name)) == 0 &&
1334 0 0 (error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
1336 0 0 terminal_ref, GIT_OBJECT_COMMIT)) == 0 &&
1361 0 1 assert(rebase);
1363 0 1 if (rebase->inmemory)
1366 0 1 if (!rebase->head_detached)
1369 1 0 if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
1 0 if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
1393 0 10 assert(rebase);
1400 0 3 assert(rebase);
1402 2 1 return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION;
1407 0 6 assert(rebase);
1409 5 1 return git_array_get(rebase->operations, idx);
1414 0 4 if (rebase == NULL)