void test_merge_files__automerge_from_index(void) { git_merge_file_result result = {0}; git_index_entry ancestor, ours, theirs; git_oid_fromstr(&ancestor.id, "6212c31dab5e482247d7977e4f0dd3601decf13b"); ancestor.path = "automergeable.txt"; ancestor.mode = 0100644; git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); ours.path = "automergeable.txt"; ours.mode = 0100755; git_oid_fromstr(&theirs.id, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe"); theirs.path = "newname.txt"; theirs.mode = 0100644; cl_git_pass(git_merge_file_from_index(&result, repo, &ancestor, &ours, &theirs, 0)); cl_assert_equal_i(1, result.automergeable); cl_assert_equal_s("newname.txt", result.path); cl_assert_equal_i(0100755, result.mode); cl_assert_equal_i(strlen(AUTOMERGEABLE_MERGED_FILE), result.len); cl_assert_equal_strn(AUTOMERGEABLE_MERGED_FILE, result.ptr, result.len); git_merge_file_result_free(&result); }
static VALUE rb_git_merge_file(int argc, VALUE *argv, VALUE self) { VALUE rb_path, rb_options; VALUE rb_result = rb_hash_new(); VALUE rb_repo = rugged_owner(self); git_repository *repo; git_index *index; const git_index_entry *ancestor, *ours, *theirs; git_merge_file_result merge_file_result = {0}; git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT; int error; rb_scan_args(argc, argv, "1:", &rb_path, &rb_options); if (!NIL_P(rb_options)) { Check_Type(rb_options, T_HASH); rugged_parse_merge_file_options(&opts, rb_options); } Check_Type(rb_path, T_STRING); Data_Get_Struct(self, git_index, index); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); error = git_index_conflict_get(&ancestor, &ours, &theirs, index, StringValueCStr(rb_path)); if (error == GIT_ENOTFOUND) return Qnil; else rugged_exception_check(error); if (ours == NULL) rb_raise(rb_eRuntimeError, "The conflict does not have a stage 2 entry"); else if (theirs == NULL) rb_raise(rb_eRuntimeError, "The conflict does not have a stage 3 entry"); error = git_merge_file_from_index(&merge_file_result, repo, ancestor, ours, theirs, &opts); rugged_exception_check(error); rb_hash_aset(rb_result, CSTR2SYM("automergeable"), merge_file_result.automergeable ? Qtrue : Qfalse); rb_hash_aset(rb_result, CSTR2SYM("path"), rb_path); rb_hash_aset(rb_result, CSTR2SYM("filemode"), INT2FIX(merge_file_result.mode)); rb_hash_aset(rb_result, CSTR2SYM("data"), rb_str_new(merge_file_result.ptr, merge_file_result.len)); git_merge_file_result_free(&merge_file_result); return rb_result; }
static VALUE rb_git_merge_file(int argc, VALUE *argv, VALUE self) { VALUE rb_path, rb_options, rb_result; VALUE rb_repo = rugged_owner(self); git_repository *repo; git_index *index; const git_index_entry *ancestor, *ours, *theirs; git_merge_file_result merge_file_result = {0}; git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT; int error; rb_scan_args(argc, argv, "1:", &rb_path, &rb_options); if (!NIL_P(rb_options)) rugged_parse_merge_file_options(&opts, rb_options); Check_Type(rb_path, T_STRING); Data_Get_Struct(self, git_index, index); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); error = git_index_conflict_get(&ancestor, &ours, &theirs, index, StringValueCStr(rb_path)); if (error == GIT_ENOTFOUND) return Qnil; else rugged_exception_check(error); if (ours == NULL) rb_raise(rb_eRuntimeError, "The conflict does not have a stage 2 entry"); else if (theirs == NULL) rb_raise(rb_eRuntimeError, "The conflict does not have a stage 3 entry"); error = git_merge_file_from_index(&merge_file_result, repo, ancestor, ours, theirs, &opts); rugged_exception_check(error); rb_result = rb_merge_file_result_fromC(&merge_file_result); git_merge_file_result_free(&merge_file_result); return rb_result; }