Class: Rugged::SubmoduleCollection
- Inherits:
-
Object
- Object
- Rugged::SubmoduleCollection
- Includes:
- Enumerable
- Defined in:
- lib/rugged/submodule_collection.rb,
ext/rugged/rugged_submodule_collection.c
Instance Method Summary collapse
-
#[](name) ⇒ nil
Lookup
submodule
byname
orpath
(they are usually the same) inrepository
. -
#add(url, path, options = {}) ⇒ Object
call-seq: submodules.setup_add(url, path[, options]) -> submodule.
-
#each ⇒ Object
Iterate through all the tracked submodules in the collection’s
repository
. -
#new(repo) ⇒ Object
constructor
Creates and returns a new collection of submodules for the given
repo
. -
#setup_add(url, path[, options]) ⇒ Object
Setup a new
submodule
for checkout inrepository
. -
#update(rb_name_or_submodule, rb_settings) ⇒ Object
Update settings for the given submodule in the submodule config.
Constructor Details
#new(repo) ⇒ Object
Creates and returns a new collection of submodules for the given repo
.
20 21 22 23 24 25 |
# File 'ext/rugged/rugged_submodule_collection.c', line 20
static VALUE rb_git_submodule_collection_initialize(VALUE self, VALUE rb_repo)
{
rugged_check_repo(rb_repo);
rugged_set_owner(self, rb_repo);
return self;
}
|
Instance Method Details
#[](name) ⇒ nil
Lookup submodule
by name
or path
(they are usually the same) in repository
.
Returns nil
if submodule does not exist.
Raises Rugged::SubmoduleError
if submodule exists only in working directory (i.e. there is a subdirectory that is a valid self-contained git repository) and is not mentioned in the HEAD
, the index and the config.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/rugged/rugged_submodule_collection.c', line 59
static VALUE rb_git_submodule_collection_aref(VALUE self, VALUE rb_name)
{
git_repository *repo;
git_submodule *submodule;
int error;
VALUE rb_repo = rugged_owner(self);
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_name, T_STRING);
error = git_submodule_lookup(
&submodule,
repo,
StringValueCStr(rb_name)
);
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
return rugged_submodule_new(rb_repo, submodule);
}
|
#add(url, path, options = {}) ⇒ Object
call-seq:
submodules.setup_add(url, path[, options]) -> submodule
Add a new submodule
.
This does "git submodule add"
incuding fetch and checkout of the submodule contents.
-
url
: URL for the submodule’s remote -
path
: path at which the submodule should be created
The options
hash accepts all options supported by Rugged::Remote#fetch and the following:
- :gitlink
-
(defaults to
true
) should workdir contain a gitlink to the repository in.git/modules
vs. repository directly in workdir.
Returns the newly created submodule
28 29 30 31 32 |
# File 'lib/rugged/submodule_collection.rb', line 28 def add(url, path, = {}) submodule = setup_add(url, path, **) clone_submodule(submodule.repository, **) submodule.finalize_add end |
#each {|submodule| ... } ⇒ Object #each ⇒ Object
Iterate through all the tracked submodules in the collection’s repository
.
The given block
will be called once with each submodule
as a Rugged::Submodule instance. If no block is given, an enumerator will be returned.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'ext/rugged/rugged_submodule_collection.c', line 122
static VALUE rb_git_submodule_collection_each(VALUE self)
{
git_repository *repo;
int error;
struct rugged_cb_payload payload;
VALUE rb_repo;
RETURN_ENUMERATOR(self, 0, 0);
rb_repo = rugged_owner(self);
Data_Get_Struct(rb_repo, git_repository, repo);
payload.exception = 0;
payload.rb_data = rb_repo;
error = git_submodule_foreach(repo, &cb_submodule__each, &payload);
if (payload.exception)
rb_jump_tag(payload.exception);
rugged_exception_check(error);
return Qnil;
}
|
#setup_add(url, path[, options]) ⇒ Object
Setup a new submodule
for checkout in repository
.
This does "git submodule add"
up to the fetch and checkout of the submodule contents. It prepares a new submodule, creates an entry in .gitmodules
and creates an empty initialized repository either at the given path
in the working directory or in .git/modules
with a gitlink from the working directory to the new repository.
To fully emulate "git submodule add"
call this function, then open the submodule repository and perform the clone step as needed. Lastly, call Submodule#finalize_add to wrap up adding the new submodule and .gitmodules
to the index to be ready to commit.
-
url
: URL for the submodule’s remote -
path
: path at which the submodule should be created
The following options can be passed in the options
Hash:
- :gitlink
-
(defaults to
true
) should workdir contain a gitlink to the repository in.git/modules
vs. repository directly in workdir.
Returns the newly created submodule
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'ext/rugged/rugged_submodule_collection.c', line 173
static VALUE rb_git_submodule_setup_add(int argc, VALUE *argv, VALUE self)
{
git_submodule *submodule;
git_repository *repo;
int error;
int use_gitlink = 1;
VALUE rb_repo, rb_url, rb_path, rb_options;
rb_scan_args(argc, argv, "20:", &rb_url, &rb_path, &rb_options);
Check_Type(rb_url, T_STRING);
Check_Type(rb_path, T_STRING);
rb_repo = rugged_owner(self);
Data_Get_Struct(rb_repo, git_repository, repo);
if (!NIL_P(rb_options)) {
VALUE rb_val;
rb_val = rb_hash_aref(rb_options, CSTR2SYM("gitlink"));
use_gitlink = (rb_val != Qfalse);
}
error = git_submodule_add_setup(
&submodule,
repo,
StringValueCStr(rb_url),
StringValueCStr(rb_path),
use_gitlink
);
rugged_exception_check(error);
return rugged_submodule_new(rb_repo, submodule);
}
|
#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.
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;
}
|