Is it possible to have Cargo fetch dependencies from a private remote git?

∥☆過路亽.° 提交于 2019-12-05 13:34:50

问题


I have an account on an ssh-friendly lab machine where I store a lot of private projects so I can access them from multiple computers (and it allows me to only use my few private Github repos for things multiple people will work on).

It seems like Rust is well-equipped to fetch local and public data by using things like

[dependencies.foo]
git = "https://github.com/bar/foo"

[dependencies.baz]
path = "/path/to/baz"

But I haven't found a way to get it to work using ssh git (e.g. git = "git@github.com:bar/foo", or in my case labmachine:bar/foo). I have passwordless/keygen ssh set up, if that helps.

It's not a big deal if it doesn't exist. At the moment I'm just manually cloning the repository and using path = ../foo, which works as long as I keep my directory structure the same and remember to manually pull all dependencies on all my machines. However, it would make things a lot easier if I could just set up Cargo to do it, especially if I just need to quickly demo something on my laptop or whatever.


回答1:


On macOS Sierra, I had to create a .ssh/config file like this:

Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/id_rsa

with the private key (RSA) file pointed to, and then issue the command:

ssh-add -K ~/.ssh/id_rsa

which (finally!) allowed an entry like:

git = "ssh://git@github.com/skipjaq/loda.git"

to work perfectly.

I do not know how often I will have to repeat the ssh-add command, but it appears this ought to hold at least until the next reboot.

This anomaly is apparently a feature of ssh-agent on macOS Sierra.




回答2:


Use a full SSH path rather than Git’s shorthand:

git = "ssh://landmachine/bar/foo"


来源:https://stackoverflow.com/questions/31704573/is-it-possible-to-have-cargo-fetch-dependencies-from-a-private-remote-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!