Method: Rugged::Repository#apply

Defined in:
ext/rugged/rugged_repo.c

#apply(diff, options = {}) ⇒ Boolean

Applies the given diff to the repository. The following options can be passed in the options Hash:

:location

Whether to apply the changes to the workdir (default for non-bare), the index (default for bare) or both. Valid values: :index, :workdir, :both.

:delta_callback

While applying the patch, this callback will be executed per delta (file). The current delta will be passed to the block. The block’s return value determines further behavior. When the block evaluates to:

- +true+: the hunk will be applied and the apply process will continue.
- +false+: the hunk will be skipped, but the apply process continues.
- +nil+: the hunk is not applied, and the apply process is aborted.
:hunk_callback

While applying the patch, this callback will be executed per hunk. The current hunk will be passed to the block. The block’s return value determines further behavior, as per :delta_callback.

Returns:

  • (Boolean)
[View source]

1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'ext/rugged/rugged_repo.c', line 1017

static VALUE rb_git_repo_apply(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_diff, rb_options;
	git_diff *diff;
	git_repository *repo;
	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
	git_apply_location_t location;
	struct rugged_apply_cb_payload payload = { Qnil, Qnil, 0 };
	int error;

	Data_Get_Struct(self, git_repository, repo);
	if (git_repository_is_bare(repo)) {
		location = GIT_APPLY_LOCATION_INDEX;
	} else {
		location = GIT_APPLY_LOCATION_WORKDIR;
	}

	rb_scan_args(argc, argv, "11", &rb_diff, &rb_options);

	if (!rb_obj_is_kind_of(rb_diff, rb_cRuggedDiff)) {
		rb_raise(rb_eArgError, "Expected a Rugged::Diff.");
	}

	if (!NIL_P(rb_options)) {
		Check_Type(rb_options, T_HASH);
		rugged_parse_apply_options(&opts, &location, rb_options, &payload);
	}

	Data_Get_Struct(rb_diff, git_diff, diff);

	error = git_apply(repo, diff, location, &opts);

	rugged_exception_check(error);

	return Qtrue;
}