Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git submodules #83

Closed
roblabla opened this issue Aug 6, 2018 · 10 comments
Closed

Git submodules #83

roblabla opened this issue Aug 6, 2018 · 10 comments
Milestone

Comments

@roblabla
Copy link

roblabla commented Aug 6, 2018

Currently, cargo-generate ignores git submodules (does not clone them recursively). I'm working on a Rust toolchain for the Nintendo Switch, and I'd like to have my template contain a git submodule for my fork of the rust stdlibd.

I believe cargo generate should clone templates recursively.

@ashleygwilliams
Copy link
Collaborator

i totally think we should do this! my only thought is- should this be default behavior or a flag- any thoughts @roblabla or @killercup ? i can't imagine that doing it by default would cause issue, but i also rarely use git submodules so don't have a ton of experience to draw on here. open to either!

@roblabla
Copy link
Author

roblabla commented Aug 6, 2018

By default, git does not clone submodules because it can take a large amount of time to clone, and might not be necessary.

But in the context of a template, IMO the default should be to clone it. I can't imagine a case where a template would have a submodule the author didn't intend to get cloned. Curious to hear if anyone has a use-case for a non-cloned submodule in a template though.

@ashleygwilliams
Copy link
Collaborator

yeah i tend to agree with you @roblabla - let's leave this open for a few days and see if there's any comments. otherwise i'm quite happy to accept a PR for this (if you are interested- go for it!)

@k0pernicus
Copy link
Collaborator

k0pernicus commented Oct 1, 2018

I just checked the git2-rs crate and there is a method that clone the repository and the submodules recursively: https://docs.rs/git2/0.7.5/git2/struct.Repository.html#method.clone_recurse

Maybe, first, we can check if the repository contains submodules - if it does, we can use clone_recurse, otherwise we can just clone it.
The problem here is: how can we check if the repository contains submodules if we can't clone it...

The first solution, and the most simpler one, is to let the developer explain the situation in the template's README.
To help the user, we can create a new option in the CLI, like with-submodules: cargo generate --git https://github.com/user/example --with-submodules --name myexample.

The second solution, and the most complex one, is to clone the template, check if it contains submodules, and so init and clone recursively all the submodules manually.

What do you think of that?

@k0pernicus
Copy link
Collaborator

k0pernicus commented Oct 1, 2018

@ashleygwilliams Actually, I just read your thoughts about removing libgit2 here...
So the best solution here may be the second one.

Otherwise, I don't know what is the behaviour of git clone --recursive ... if the repository does not contains any submodule.
Does it crash? Does it stopped to the main repository?
Also, I am not so sure that each git 2.X version has the same behaviour for this option 🤔

@ashleygwilliams
Copy link
Collaborator

@k0pernicus i think we will hold off a bit longer on replacing libgit2- after talking briefly with @alexcrichton it seems that libgit2 does still have some benefit- particularly for Windows users. i'll need to talk a little more with him about the tradeoffs (mostly that installing cargo-generate is a bit unfun) - if you'd like to proceed with the clone_reverse solution i think that works well.

because you asked, in my experience git clone --recurisve on a non submodules repo just does what git clone would do.

@k0pernicus
Copy link
Collaborator

No problem.
I will create a PR for the clone_reverse solution if you are ok with that.

@ashleygwilliams
Copy link
Collaborator

yup! that's great. i should note that i was planning on doing a release today- let me know what your time constraints are. if we think we can get this in today that'd be awesome, but i don't want to put too much pressure. let me know!

@ashleygwilliams ashleygwilliams added this to the 0.2.0 milestone Oct 3, 2018
@k0pernicus
Copy link
Collaborator

@ashleygwilliams I can work on it right now ;)

@ashleygwilliams
Copy link
Collaborator

closed by #104 - thanks @k0pernicus ! @roblabla we'll be making a release tomorrow- please try that out as it should resolve your issue! closing this now, please file an issue if you run into any problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants