Method: Rugged::SubmoduleCollection#update

Defined in:
ext/rugged/rugged_submodule_collection.c

#update(submodule, settings) ⇒ nil #update(name, settings) ⇒ nil

Update settings for the given submodule in the submodule config.

Existing Rugged::Submodule instances are not updated, but can be reloaded by calling #reload.

The following options can be passed in the settings Hash:

:url

Updates the URL for the submodule.

:ignore_rule

See ‘Rugged::Submodule#ignore_rule` for a list of accepted rules.

:update_rule

See ‘Rugged::Submodule#update_rule` for a list of accepted rules.

:fetch_recurse_submodules

Updates the fetchRecurseSubmodules rule.

Overloads:

  • #update(submodule, settings) ⇒ nil

    Returns:

    • (nil)
  • #update(name, settings) ⇒ nil

    Returns:

    • (nil)


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'ext/rugged/rugged_submodule_collection.c', line 273

static VALUE rb_git_submodule_update(VALUE self, VALUE rb_name_or_submodule, VALUE rb_settings)
{
	git_repository *repo;
	git_submodule_ignore_t ignore_rule = GIT_SUBMODULE_IGNORE_UNSPECIFIED;
	git_submodule_update_t update_rule = GIT_SUBMODULE_UPDATE_DEFAULT;
	const char *submodule_name;
	int fetch_recurse_submodules = 0;
	VALUE rb_repo = rugged_owner(self);
	VALUE rb_url, rb_fetch_recurse_submodules, rb_ignore_rule, rb_update_rule;

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	if (rb_obj_is_kind_of(rb_name_or_submodule, rb_cRuggedSubmodule))
		rb_name_or_submodule = rb_funcall(rb_name_or_submodule, rb_intern("name"), 0);

	if (TYPE(rb_name_or_submodule) != T_STRING)
		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Submodule instance");

	rb_url = rb_hash_aref(rb_settings, CSTR2SYM("url"));
	rb_fetch_recurse_submodules = rb_hash_aref(rb_settings, CSTR2SYM("fetch_recurse_submodules"));
	rb_ignore_rule = rb_hash_aref(rb_settings, CSTR2SYM("ignore_rule"));
	rb_update_rule = rb_hash_aref(rb_settings, CSTR2SYM("update_rule"));

	if (!NIL_P(rb_url)) {
		Check_Type(rb_url, T_STRING);
	}

	if (!NIL_P(rb_fetch_recurse_submodules)) {
		fetch_recurse_submodules = rugged_parse_bool(rb_fetch_recurse_submodules);
	}

	if (!NIL_P(rb_ignore_rule)) {
		ignore_rule = rb_git_subm_ignore_rule_toC(rb_ignore_rule);
	}

	if (!NIL_P(rb_update_rule)) {
		update_rule = rb_git_subm_update_rule_toC(rb_update_rule);
	}

	submodule_name = StringValueCStr(rb_name_or_submodule);

	if (!NIL_P(rb_url)) {
		rugged_exception_check(
			git_submodule_set_url(repo,
				submodule_name,
				StringValueCStr(rb_url)
			)
		);
	}

	if (!NIL_P(rb_fetch_recurse_submodules)) {
		rugged_exception_check(
			git_submodule_set_fetch_recurse_submodules(repo,
				submodule_name,
				fetch_recurse_submodules
			)
		);
	}

	if (!NIL_P(rb_ignore_rule)) {
		rugged_exception_check(
			git_submodule_set_ignore(repo,
				submodule_name,
				ignore_rule
			)
		);
	}

	if (!NIL_P(rb_update_rule)) {
		rugged_exception_check(
			git_submodule_set_update(repo,
				submodule_name,
				update_rule
			)
		);
	}

	return Qnil;
}