Method: Rugged::SubmoduleCollection#setup_add
- Defined in:
- ext/rugged/rugged_submodule_collection.c
#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/modulesvs. 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);
}
|