Method: Rugged::Index#merge_file

Defined in:
ext/rugged/rugged_index.c

#merge_file(path[, options]) ⇒ nil #merge_file(path) ⇒ nil

Return merge_file (in memory) from the ancestor, our side and their side of the conflict at path.

If :ancestor, :ours or :theirs is nil, that indicates that path did not exist in the respective tree.

Returns nil if no conflict is present at path.

The following options can be passed in the options Hash:

:ancestor_label

The name of the ancestor branch used to decorate conflict markers.

:our_label

The name of our branch used to decorate conflict markers.

:their_label

The name of their branch used to decorate conflict markers.

:favor

Specifies how and if conflicts are auto-resolved by favoring a specific file output. Can be one of ‘:normal`, `:ours`, `:theirs` or `:union`. Defaults to `:normal`.

:style

Specifies the type of merge file to produce. Can be one of ‘:standard`, `:diff3`. Defaults to `:standard`

:simplify

If true, the merge file is simplified by condensing non-alphanumeric regions.

Overloads:

  • #merge_file(path[, options]) ⇒ nil

    Returns:

    • (nil)
  • #merge_file(path) ⇒ nil

    Returns:

    • (nil)
[View source]

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
# File 'ext/rugged/rugged_index.c', line 878

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;
}