You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cloning git sub modules using "nodegit" npm module #560
Hi @tbranyen, one thing i am not able to understand that "libgit2sharp" is a native module, i want to clone recursively without installing git on my system. Instead i want to use node module to clone recursively. i used nodegit module like " var clone = require("nodegit").Clone.clone;
// Clone a given repository into a specific folder.
clone("https://github.com/xyz.git", "bootplate-moonstone", null)
.then(function(repo) {
finish();
})
.catch(function(err) { finish(err, {msg : 'error while cloning'});});" but it wont clones sub modules.
Could you please guide me how to clone sub modules using "nodegit"?
Libgit2sharp is a wrapper for libgit2 in c#, the same way that nodegit is a wrapper for libgit2 for javascript (albeit largely written in C++). The same series of commands you would use in one shouldmostly apply in the other.
What Tim was saying is that this is the algorithm for doing what you want to do, just use nodegit commands instead of libgit2sharp commands, since the structure carries over.
Instead, to ugly-fix my needs, I made a loop over the submodule list grabbed from the modules list in .gitmodules
Ini = require('ini');
var config = Ini.parse(fs.readFileSync(path.normalize( localPath + '/.gitmodules'), 'utf-8'));
//if startswith submodule, push into modules
modules = [];
for (var i in config) {
if (i.indexOf('submodule') === 0){
modules.push(config[i]);
}
}
for (var i in modules) {
var modulePath = modules[i].path;
Git.Submodule.lookup(repository, modulePath).then(function(submodule) {
// Use submodule
log.success("got submodule '" + submodule.path() + "'");
try{
submodule.init(1);
log.success("submodule init worked");
}catch(e){
log.error("submodule init failed "+ e);
}
try{
submodule.update(1,new Git.CheckoutOptions);
log.success("submodule update worked");
}catch(e){
log.error("submodule update failed "+ e);
}
},function(err){
log.error('cant get submodule : '+err)
});
}
This doesn't need to be recursive, submodules of submodules are retrieved with the init or update function.
This is quite ugly but I'm posting it here if it can help anybody. Maybe one day I will dive into the writing of tests you talked about, but not now :)
@ggendre, I can't believe I didn't find your post sooner. I looked everywhere for an example of how to do this and couldn't find anything! I too had the same issue and decided to manually parse the .gitmodules file and I even was having trouble getting the right syntax for submodule.update (didn't know about new Git.CheckoutOptions). Thanks!
Activity
tbranyen commentedon May 11, 2015
Yes it is possible. See the OP here for clues on how to do it: libgit2/libgit2sharp#640
shivakumarpm commentedon May 13, 2015
Hi @tbranyen, one thing i am not able to understand that "libgit2sharp" is a native module, i want to clone recursively without installing git on my system. Instead i want to use node module to clone recursively. i used nodegit module like " var clone = require("nodegit").Clone.clone;
// Clone a given repository into a specific folder.
clone("https://github.com/xyz.git", "bootplate-moonstone", null)
.then(function(repo) {
finish();
})
.catch(function(err) { finish(err, {msg : 'error while cloning'});});" but it wont clones sub modules.
Could you please guide me how to clone sub modules using "nodegit"?
maxkorp commentedon May 13, 2015
Libgit2sharp is a wrapper for libgit2 in c#, the same way that nodegit is a wrapper for libgit2 for javascript (albeit largely written in C++). The same series of commands you would use in one shouldmostly apply in the other.
What Tim was saying is that this is the algorithm for doing what you want to do, just use nodegit commands instead of libgit2sharp commands, since the structure carries over.
If you need more help, talk to us in our gitter room https://gitter.im/nodegit/nodegit and we'll get you all sorted out 👍
ggendre commentedon Aug 4, 2015
Hi,
I'm having the same need as @shivakumarpm : I want to clone my repository and init and update all submodules recursively.
I understand from @maxkorp reply that I should use the same algorithm as used in the linked commit. Which is :
So, my problem is to get the submodule list with nodegit. I can't find any function that gives me the submodules list. Did I miss something ?
tbranyen commentedon Aug 4, 2015
@ggendre nope, but we are: https://github.com/nodegit/nodegit/blob/master/generate/input/descriptor.json#L1931-L1933 I don't remember why we don't compile it, but that method is ignored atm
johnhaley81 commentedon Aug 4, 2015
@ggendre A PR with that method enabled and some tests confirming the functionality would be amazing hint hint nudge nudge
ggendre commentedon Aug 5, 2015
Sorry, I have not enough time to dive into this.
Instead, to ugly-fix my needs, I made a loop over the submodule list grabbed from the modules list in .gitmodules
This doesn't need to be recursive, submodules of submodules are retrieved with the init or update function.
This is quite ugly but I'm posting it here if it can help anybody. Maybe one day I will dive into the writing of tests you talked about, but not now :)
have a good day,
papiro commentedon Sep 19, 2015
@ggendre, I can't believe I didn't find your post sooner. I looked everywhere for an example of how to do this and couldn't find anything! I too had the same issue and decided to manually parse the .gitmodules file and I even was having trouble getting the right syntax for submodule.update (didn't know about new Git.CheckoutOptions). Thanks!
ggendre commentedon Jul 15, 2016
for the record, nodegit now has a
foreachandlookupmethod to browse submodulesfelixfbecker commentedon Dec 28, 2016
@ggendre Do you have a small snippet that essentially does
git clone --recursive? Completely lostallomov commentedon Dec 12, 2017
@felixfbecker here is a recursive function I have come to.