如何在Python中判断一个目录是否是git仓库(裸仓或非裸仓)
有没有办法在Python中判断一个文件夹是不是GIT仓库呢?
我想检查一下那个文件夹下面有没有“.git”这个文件夹,但这样的方法在裸仓库(bare repo)中不管用。
1 个回答
3
你可以使用 GitPython 这个工具:
from git import Repo, InvalidGitRepositoryError
try:
Repo(path_to_repo)
print 'is git repo'
except InvalidGitRepositoryError:
print 'isn`t git repo'