dsfsfdsf4544 2017-09-27 05:18
浏览 128
已采纳

如何在Go中禁用凭据提示以进行git clone?

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.

  • 写回答

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)
        }
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?