简体   繁体   English

GitPython:检查git是否可用

[英]GitPython: check if git is available

GitPython depends on having the command line version of git installed (otherwise, you get the issue in this question: OSError: [Errno 2] No such file or directory on GitPython ). GitPython依赖于安装了git的命令行版本(否则,您将在以下问题中得到问题: OSError:[Errno 2] GitPython上没有此类文件或目录 )。

Is there any way from the GitPython API to check if the executable is found, or, do you need to wrap all GitPython calls in exception handling to account for this possibility? GitPython API是否有任何方法可以检查是否找到了可执行文件,或者您是否需要将所有GitPython调用包装在异常处理中以解决这种可能性?

I don't particularly recommend this, but I actually did it at least once: try one git command while catching the OSError case to see if you can run git (and by running it, capture the git version number as well, in my case). 我不特别推荐这样做,但是实际上我至少这样做了一次:在捕获OSError的情况下尝试执行一个git命令,看看是否可以运行git(在我的情况下,通过运行它,还可以捕获git版本号)。 If git fails to run, complain and disable further invocations of git (or exit immediately or whatever). 如果git无法运行,请投诉并禁用git的进一步调用(或立即退出或执行其他操作)。 If not, assume further invocations will continue to work. 如果没有,请假设进一步的调用将继续起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM