我想使用读取 git 全局配置文件git config --list
,所以我可以使用读取和更新全局配置文件?
问问题
3123 次
3 回答
2
这将为您提供 ~/.gitconfig 类型的配置:
globalconfig = git.GitConfigParser([os.path.normpath(os.path.expanduser("~/.gitconfig"))], read_only=True)
这或多或少是 gitpython 本身所做的,除了它还使用“system”和“repo”级别的配置(其中 system 是“/etc/gitconfig”),请参阅
def _get_config_path(self, config_level):
和
def config_reader(self, config_level=None):
在 gitpython 源码中的 git/base.py
于 2014-12-13T11:03:28.960 回答
1
gitconfig可能正是您所需要的。
于 2014-02-26T17:49:20.623 回答
0
自从@unhammer 在 2014 年发布他们的答案以来,他们GitPython
一直在不断发展。以下是如何使用 Python 3 和GitPython
v3.1.11 读取全局用户名的示例:
def git_user_name() -> str:
from git import Repo
reader = Repo(path=None).config_reader()
field = reader.get_value("user", "name")
return field
这适用于任何目录,不需要本地存储库。
于 2020-12-02T18:01:23.657 回答