Class: Rugged::Submodule

Inherits:
Object
  • Object
show all
Defined in:
ext/rugged/rugged_submodule.c

Instance Method Summary collapse

Instance Method Details

#add_to_index([options]) ⇒ Object

Add current submodule HEAD commit to the index of superproject.

The following options can be passed in the options Hash:

:write_index ::

(default +true+) If this should immediately write the index file.
If passed as +false+, Rugged::Repository#index can be used to explicitly
call Rugged::Index#write to save the change.


401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'ext/rugged/rugged_submodule.c', line 401

static VALUE rb_git_submodule_add_to_index(int argc, VALUE *argv, VALUE self)
{
	git_submodule *submodule;
	VALUE rb_options;
	int write_index = 1;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rb_scan_args(argc, argv, ":", &rb_options);

	if (!NIL_P(rb_options)) {
		VALUE rb_val;

		rb_val = rb_hash_aref(rb_options, CSTR2SYM("write_index"));
		write_index = (rb_val != Qfalse);
	}

	rugged_exception_check(
		git_submodule_add_to_index(submodule, write_index)
	);

	return self;
}

#added_to_index?Boolean

Returns true if submodule is in index, not in HEAD.

Returns:

  • (Boolean)


244
245
246
247
# File 'ext/rugged/rugged_submodule.c', line 244

static VALUE rb_git_submodule_status_added_to_index(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_ADDED)
}

#added_to_workdir?Boolean

Returns true if submodule is in workdir, not index.

Returns:

  • (Boolean)


288
289
290
291
# File 'ext/rugged/rugged_submodule.c', line 288

static VALUE rb_git_submodule_status_added_to_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_ADDED)
}

#deleted_from_index?Boolean

Returns true if submodule is in HEAD, not in index

Returns:

  • (Boolean)


255
256
257
258
# File 'ext/rugged/rugged_submodule.c', line 255

static VALUE rb_git_submodule_status_deleted_from_index(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_DELETED)
}

#deleted_from_workdir?Boolean

Returns true if submodule is in index, not workdir.

Returns:

  • (Boolean)


299
300
301
302
# File 'ext/rugged/rugged_submodule.c', line 299

static VALUE rb_git_submodule_status_deleted_from_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_DELETED)
}

#dirty_workdir?Boolean

Returns true if the submodule workdir is dirty.

The workdir is considered dirty if the workdir index is modified, there are modified files in the workdir or if there are untracked files in the workdir.

Returns:

  • (Boolean)


383
384
385
386
# File 'ext/rugged/rugged_submodule.c', line 383

static VALUE rb_git_submodule_status_dirty_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_WD_DIRTY)
}

#dirty_workdir_index?Boolean

Returns true if submodule workdir index is dirty.

Returns:

  • (Boolean)


321
322
323
324
# File 'ext/rugged/rugged_submodule.c', line 321

static VALUE rb_git_submodule_status_dirty_workdir_index(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
}

#fetch_recurse_submodules?Boolean

Returns the fetchRecurseSubmodules rule for a submodule.

This accesses the submodule..fetchRecurseSubmodules value for the submodule that controls fetching behavior for the submodule.

Note that at this time, Rugged does not honor this setting and the fetch functionality currently ignores submodules.

Returns:

  • (Boolean)


628
629
630
631
632
633
634
# File 'ext/rugged/rugged_submodule.c', line 628

static VALUE rb_git_submodule_fetch_recurse_submodules(VALUE self)
{
	git_submodule *submodule;
	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	return git_submodule_fetch_recurse_submodules(submodule) ? Qtrue : Qfalse;
}

#finalize_addObject

Resolve the setup of a new submodule.

This should be called on a submodule once Rugged::SubmoduleCollection#setup_add is finished and the sumodule repo is cloned.

This adds the .gitmodules file and the newly cloned submodule to the index to be ready to be committed (but doesn't actually do the commit).



772
773
774
775
776
777
778
779
780
781
782
# File 'ext/rugged/rugged_submodule.c', line 772

static VALUE rb_git_submodule_finalize_add(VALUE self)
{
	git_submodule *submodule;
	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rugged_exception_check(
		git_submodule_add_finalize(submodule)
	);

	return self;
}

#head_oidString?

Returns the OID for the submodule in the current HEAD tree or nil if the submodule is not in the HEAD.

Returns:

  • (String, nil)


581
582
583
584
# File 'ext/rugged/rugged_submodule.c', line 581

static VALUE rb_git_submodule_head_id(VALUE self)
{
	RB_GIT_OID_GETTER(submodule, head_id);
}

#ignore_ruleObject

Returns the ignore rule for a submodule.

There are four ignore values:

:none (default)::

will consider any change to the contents of the submodule from
a clean checkout to be dirty, including the addition of untracked files.

:untracked ::

examines the contents of the working tree but untracked files will not
count as making the submodule dirty.

:dirty ::

means to only check if the +HEAD+ of the submodule has moved for status.
This is fast since it does not need to scan the working tree
of the submodule at all.

:all ::

means not to open the submodule repository. The working directory will be
considered clean so long as there is a checked out version present.

See #status on how ignore rules reflect the returned status info for a submodule.



677
678
679
680
681
682
683
684
685
686
# File 'ext/rugged/rugged_submodule.c', line 677

static VALUE rb_git_submodule_ignore_rule(VALUE self)
{
	git_submodule *submodule;
	git_submodule_ignore_t ignore;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
	ignore = git_submodule_ignore(submodule);

	return rb_git_subm_ignore_rule_fromC(ignore);
}

#in_config?Boolean

Returns true if superproject .gitmodules has submodule.

Returns:

  • (Boolean)


208
209
210
211
# File 'ext/rugged/rugged_submodule.c', line 208

static VALUE rb_git_submodule_status_in_config(VALUE self)
{
	RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_CONFIG)
}

#in_head?Boolean

Returns true if superproject HEAD contains submodule.

Returns:

  • (Boolean)


186
187
188
189
# File 'ext/rugged/rugged_submodule.c', line 186

static VALUE rb_git_submodule_status_in_head(VALUE self)
{
	RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_HEAD)
}

#in_index?Boolean

Returns true if superproject index contains submodule.

Returns:

  • (Boolean)


197
198
199
200
# File 'ext/rugged/rugged_submodule.c', line 197

static VALUE rb_git_submodule_status_in_index(VALUE self)
{
	RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_INDEX)
}

#in_workdir?Boolean

Returns true if superproject workdir has submodule.

Returns:

  • (Boolean)


219
220
221
222
# File 'ext/rugged/rugged_submodule.c', line 219

static VALUE rb_git_submodule_status_in_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_WD)
}

#index_oidString?

Returns the OID for the submodule in the index or nil if the submodule is not in the index.

Returns:

  • (String, nil)


593
594
595
596
# File 'ext/rugged/rugged_submodule.c', line 593

static VALUE rb_git_submodule_index_id(VALUE self)
{
	RB_GIT_OID_GETTER(submodule, index_id);
}

#init([options]) ⇒ Object

Copy submodule info into .git/config file.

Just like "git submodule init", this copies information about the submodule into .git/config.

The following options can be passed in the options Hash:

:overwrite ::

(defaults to +false+) - By default, existing entries
will not be overwritten, but setting this to +true+ forces them to be
updated.


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'ext/rugged/rugged_submodule.c', line 485

static VALUE rb_git_submodule_init(int argc, VALUE *argv, VALUE self)
{
	git_submodule *submodule;
	VALUE rb_options;
	int overwrite = 0;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rb_scan_args(argc, argv, ":", &rb_options);

	if (!NIL_P(rb_options)) {
		VALUE rb_val;

		rb_val = rb_hash_aref(rb_options, CSTR2SYM("overwrite"));
		overwrite = RTEST(rb_val);
	}

	rugged_exception_check(
		git_submodule_init(submodule, overwrite)
	);

	return self;
}

#modified_files_in_workdir?Boolean

Returns true if submodule workdir has modified files.

Returns:

  • (Boolean)


332
333
334
335
# File 'ext/rugged/rugged_submodule.c', line 332

static VALUE rb_git_submodule_status_modified_files_in_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
}

#modified_in_index?Boolean

Returns true if submodule in index and HEAD don't match.

Returns:

  • (Boolean)


266
267
268
269
# File 'ext/rugged/rugged_submodule.c', line 266

static VALUE rb_git_submodule_status_modified_in_index(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_MODIFIED)
}

#modified_in_workdir?Boolean

Returns true if submodule in index and workdir HEAD don't match.

Returns:

  • (Boolean)


310
311
312
313
# File 'ext/rugged/rugged_submodule.c', line 310

static VALUE rb_git_submodule_status_modified_in_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_MODIFIED)
}

#nameString

Returns the name of the submodule.

Returns:

  • (String)


515
516
517
518
519
520
521
522
523
524
525
# File 'ext/rugged/rugged_submodule.c', line 515

static VALUE rb_git_submodule_name(VALUE self)
{
	git_submodule *submodule;
	const char *name;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	name = git_submodule_name(submodule);

	return rb_str_new_utf8(name);
}

#pathString

Returns the path of the submodule.

The path is almost always the same as the #name, but the two are actually not required to match.

Returns:

  • (String)


555
556
557
558
559
560
561
562
563
564
565
# File 'ext/rugged/rugged_submodule.c', line 555

static VALUE rb_git_submodule_path(VALUE self)
{
	git_submodule *submodule;
	const char *path;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	path = git_submodule_path(submodule);

	return rb_str_new_utf8(path);
}

#reloadObject

Reread submodule info from config, index, and HEAD.

Call this to reread cached submodule information for this submodule if there is reason to believe that it has changed.



434
435
436
437
438
439
440
441
442
443
444
# File 'ext/rugged/rugged_submodule.c', line 434

static VALUE rb_git_submodule_reload(VALUE self)
{
	git_submodule *submodule;
	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rugged_exception_check(
		git_submodule_reload(submodule, 1)
	);

	return self;
}

#repositoryObject

Returns the repository for the submodule.

The returned repository is a newly opened Rugged::Repository object. This will only work if the submodule is checked out into the working directory.



745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'ext/rugged/rugged_submodule.c', line 745

static VALUE rb_git_submodule_repository(VALUE self)
{
	git_submodule *submodule;
	git_repository *repo;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rugged_exception_check(
		git_submodule_open(&repo, submodule)
	);

	return rugged_repo_new(rb_cRuggedRepo, repo);
}

#statusArray

Returns an array with the status flags for a submodule.

Depending on the #ignore_rule property of the submodule, some of the flags may never be returned because they indicate changes that are supposed to be ignored.

Submodule info is contained in 4 places: the HEAD tree, the index, config files (both .git/config and .gitmodules), and the working directory. Any or all of those places might be missing information about the submodule depending on what state the repository is in. We consider all four places to build the combination of status flags.

There are four values that are not really status, but give basic info about what sources of submodule data are available. These will be returned even if ignore is set to :all.

:in_head ::

superproject +HEAD+ contains submodule

:in_index ::

superproject index contains submodule

:in_config ::

superproject +.gitmodules+ has submodule

:in_workdir ::

superproject workdir has submodule

The following values will be returned as long as ignore is not :all.

:added_to_index ::

submodule is in index, not in +HEAD+

:deleted_from_index ::

submodule is in +HEAD+, not in index

:modified_in_index ::

submodule in index and +HEAD+ don't match

:uninitialized ::

submodule in workdir is not initialized

:added_to_workdir ::

submodule is in workdir, not index

:deleted_from_workdir ::

submodule is in index, not workdir

:modified_in_workdir ::

submodule in index and workdir +HEAD+ don't match

The following can only be returned if ignore is :none or :untracked.

:dirty_workdir_index ::

submodule workdir index is dirty

:modified_files_in_workdir ::

submodule workdir has modified files

Lastly, the following will only be returned for ignore :none.

:untracked_files_in_workdir ::

submodule workdir contains untracked files

Returns:

  • (Array)


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/rugged/rugged_submodule.c', line 151

static VALUE rb_git_submodule_status(VALUE self)
{
	VALUE rb_repo = rugged_owner(self);
	git_submodule *submodule;
	git_repository *repo;
	unsigned int flags;

	rugged_check_repo(rb_repo);
	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rugged_exception_check(
		git_submodule_status(&flags, repo, git_submodule_name(submodule),
			GIT_SUBMODULE_IGNORE_UNSPECIFIED)
	);

	return submodule_status_flags_to_rb(flags);

}

#syncObject

Copy submodule remote info into submodule repository.

This copies the information about the submodules URL into the checked out submodule config, acting like "git submodule sync". This is useful if the URL for the submodule was altered (by a manual change, or a fetch of upstream changes) and the local repository needs to be updated.



457
458
459
460
461
462
463
464
465
466
467
# File 'ext/rugged/rugged_submodule.c', line 457

static VALUE rb_git_submodule_sync(VALUE self)
{
	git_submodule *submodule;
	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	rugged_exception_check(
		git_submodule_sync(submodule)
	);

	return self;
}

#uninitialized?Boolean

Returns true if submodule in workdir is not initialized.

Returns:

  • (Boolean)


277
278
279
280
# File 'ext/rugged/rugged_submodule.c', line 277

static VALUE rb_git_submodule_status_uninitialized(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)
}

#unmodified?Boolean

Returns true if the submodule is unmodified.

Returns:

  • (Boolean)


368
369
370
371
# File 'ext/rugged/rugged_submodule.c', line 368

static VALUE rb_git_submodule_status_unmodified(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_UNMODIFIED)
}

#untracked_files_in_workdir?Boolean

Returns true if submodule workdir contains untracked files.

Returns:

  • (Boolean)


343
344
345
346
# File 'ext/rugged/rugged_submodule.c', line 343

static VALUE rb_git_submodule_status_untracked_files_in_workdir(VALUE self)
{
	RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNTRACKED)
}

#update_ruleObject

Returns the update rule for a submodule.

There are four update_rule values:

:checkout (default)::

the new commit specified in the superproject will be checked out in the
submodule on a detached +HEAD+.

:rebase ::

the current branch of the submodule will be rebased onto the commit
specified in the superproject.

:merge ::

the commit specified in the superproject will be merged into the current
branch of the submodule.

:none ::

the submodule will not be updated


724
725
726
727
728
729
730
731
732
733
# File 'ext/rugged/rugged_submodule.c', line 724

static VALUE rb_git_submodule_update_rule(VALUE self)
{
	git_submodule *submodule;
	git_submodule_update_t update;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
	update = git_submodule_update_strategy(submodule);

	return rb_git_subm_update_rule_fromC(update);
}

#urlString?

Returns the URL of the submodule.

Returns:

  • (String, nil)


533
534
535
536
537
538
539
540
541
542
543
544
# File 'ext/rugged/rugged_submodule.c', line 533

static VALUE rb_git_submodule_url(VALUE self)
{

	git_submodule *submodule;
	const char *url;

	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);

	url = git_submodule_url(submodule);

	return url ? rb_str_new_utf8(url) : Qnil;
}

#workdir_oidString?

Returns the OID for the submodule in the current working directory or nil of the submodule is not checked out.

This returns the OID that corresponds to looking up HEAD in the checked out submodule. If there are pending changes in the index or anything else, this won't notice that. #status can be called for a more complete picture about the state of the working directory.

Returns:

  • (String, nil)


610
611
612
613
# File 'ext/rugged/rugged_submodule.c', line 610

static VALUE rb_git_submodule_wd_id(VALUE self)
{
	RB_GIT_OID_GETTER(submodule, wd_id);
}