cargo-generate: Unable to generate new project (ssh issue?)

When trying to generate a new project (on Windows 10, using WSL shell), cargo-generate errors out while trying to generate a project:

playground $ cargo generate --git https://github.com/cloudflare/worker-template
 Project Name: Testing
 Renaming project called `Testing` to `testing`...
 Creating project called `testing`...
 Git Error: failed to clone into: /mnt/c/Users/Kristian Freeman/src/playground/testing6aQq65

(This issue was moved from https://github.com/cloudflare/wrangler/issues/322)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 36

Most upvoted comments

Hi! I’m here following attempting to use Cloudflare wrangler as follows:

$ wrangler generate testproject https://github.com/EverlastingBugstopper/worker-typescript-template
⬇️ Installing cargo-generate...
  Generating a new webpack worker project with name 'testproject'...
 Creating project called `testproject`...
 Git Error: failed to clone into: /home/cj/Projects/testprojectVSl3HA                                
Error: No such file or directory (os error 2)

After a bit of googling, I found that the issue was related to my ~/.gitconfig file.

I have the following lines (I think from some golang stuff? can’t remember):

[url "git@github.com:"]
	insteadOf = https://github.com/

Commenting out those two lines fixes the above issue:

$ wrangler generate testproject https://github.com/EverlastingBugstopper/worker-typescript-template
⬇️ Installing cargo-generate...
  Generating a new webpack worker project with name 'testproject'...
 Creating project called `testproject`...
 Done! New project created /home/cj/Projects/testproject

referencing https://github.com/rust-lang/cargo/issues/3381 for pointing me in this direction.

hope this helps!

@cj123 Thanks man! I can confirm I use ssh for git, temporarily commented out these line:

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/
[url "ssh://git@bitbucket.org/"]
	insteadOf = https://bitbucket.org/
[url "ssh://git@gitlab.com/"]
	insteadOf = https://gitlab.com/

Works now… hope it gets fixed!

I also encountered this issue in Win10+WSL2, and found I was able to work around by setting the “git-fetch-with-cli” flag to true https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

[net]
git-fetch-with-cli = true

seems like this bypasses the libgit library cargo otherwise uses, which may be the issue

I also encountered this issue on macOS Big Sur, and thought I’d post my findings just incase it’s helpful to anyone else.

I found thanks to some other comments above that I did not have any insteadOf configuration lines in my .gitconfig, but I did have this line:

[init]
	templatedir = ~/.git-templates

Which for some reason causes the generate command to break. When I comment out this line the generate command works as expected.

It turned out that I don’t actually have a directory at ~/.git-templates, so perhaps that’s the root cause of my problem, however I’ve never had an issue using git clone or git init with this line present in my config before.

FYI for people coming here that your gitconfig might look somewhat differently than shown in https://github.com/ashleygwilliams/cargo-generate/issues/168#issuecomment-537093190

If yours looks like this, temporarily removing or commenting out these similar lines also will workaround it:

# [url "git@github.com:"]
# insteadOf = https://github.com/

I get a similar, though slightly different error on Win10 + WSL2. Didn’t want to add another issue considering how similar it is.

root@0a8ea053daed:/workspaces/first-wasm-mod-rust# cargo generate --git https://github.com/rustwasm/wasm-pack-template
 Project Name: rust-calculate
 Creating project called `rust-calculate`...
warning: spurious network error (2 tries remaining): failed to mmap. Could not write data: Permission denied; class=Os (2)
warning: spurious network error (1 tries remaining): failed to mmap. Could not write data: Permission denied; class=Os (2)
Error:  Git Error: failed to clone into: /workspaces/first-wasm-mod-rust/rust-calculateZmJGgm  

However calling git clone directly works.

root@0a8ea053daed:/workspaces/first-wasm-mod-rust# git clone https://github.com/rustwasm/wasm-pack-template rust-calculate
Cloning into 'rust-calculate'...
remote: Enumerating objects: 188, done.
remote: Total 188 (delta 0), reused 0 (delta 0), pack-reused 188
Receiving objects: 100% (188/188), 38.43 KiB | 855.00 KiB/s, done.
Resolving deltas: 100% (90/90), done.

I’m just sort of playing around with this windows setup, I’m not very familiar with windows in general.

I checked the WSL2 container’s .gitconfig and there are no url rewrites taking place.

So is direct clone of the repo enough? What steps could I take, using raw git clone as a workaround to proceed? Is cargo generate doing anything more that git clone would have done?

Update: Okay so replacing the {{project-name}} and {{authors}} in the Cargo.toml and then running the build command succeeds. I ran into other node related issues and I’m giving up for now. Hopefully this helps someone else.

Yep, it is with WSL! Any other info I can provide to make diagnosing easier?