I'm trying to run the equivalent of git clone
in Go but I want to exit out of the command if prompted for input from stdin (ex: authentication if an ssh key hasn't been set up in the remote repository). Is there a way to do this? Right now it will simply block on input.
如何在Go中禁用凭据提示以进行git clone?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- duandian2725 2017-09-27 12:19关注
UPDATE: special git solution.
Since v 2.3 git supports environment setting
GIT_TERMINAL_PROMPT=0
which says not to ask for credentials but fail.func main() { cmd := exec.Command("git", "clone", "https://github.com/some/non-existing-repo") os.Setenv("GIT_SSH_COMMAND", "ssh -oBatchMode=yes") // cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=1", "GIT_SSH_COMMAND='ssh -oBatchMode=yes'") cmd.Stdout = os.Stdout err := cmd.Run() if err != nil { log.Println("Error: ", err) } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥35 平滑拟合曲线该如何生成
- ¥100 c语言,请帮蒟蒻写一个题的范例作参考
- ¥15 名为“Product”的列已属于此 DataTable
- ¥15 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集