如果你想完全控制SSH连接的方式,并且你使用的是git 2.3或更新版本,你可以使用GIT_SSH_COMMAND环境变量集来实例化git。它指向一个名为的脚本,代替了ssh的。因此,您可以确定是否需要密码,并启动其他GUI以获取所需的输入。
在代码中,它会是这个样子:
remote_repo = self.repo.remotes[remote]
# here is where you could choose an executable based on the platform.
# Shell scripts might just not work plainly on windows.
ssh_executable = os.path.join(rw_dir, 'my_ssh_executable.sh')
# This permanently changes all future calls to git to have the given environment variables set
# You can pass additional information in your own environment variables as well.
self.repo.git.update_environment(GIT_SSH_COMMAND=ssh_executable)
# now all calls to git which require SSH interaction call your executable
remote_repo.push(self.repo.active_branch.name)
请注意,这只适用于通过SSH访问资源。例如,如果协议是HTTPS,则可能会提供密码提示。
在git 2.3之前,您可以使用GIT_SSH环境变量。它的工作方式不同,因为它只包含ssh程序的路径,其中会传递附加参数。当然,这可能是您的脚本,与上面显示的类似。我想更准确地指出这两个环境变量之间的差异,但我缺乏这样做的个人经验。

270

被折叠的 条评论
为什么被折叠?



