我尝试过configparser
,但它不支持git配置文件的缩进(git配置文件在节中有缩进,而linux通常的格式没有缩进)。在我更新配置文件后,所有的缩进都消失了。
这里也有类似的问题:how do I emulate read and update git global config file using gitPython?
不过,我想知道是否可以使用原生python来做同样的事情?或者gitpython
是最好的替代方案?
例如,在更新之前,config如下所示:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
在我用configparser
更新它之后,它看起来是这样的:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
test = 10
附注:建议的gitconfig
库似乎根本不存在。它没有安装,说它是某种虚拟项目。
发布于 2020-02-27 01:06:57
以下是对我有效的方法:
with repo.config_writer() as config:
config.set_value("git-p4", "client", p4client)
发布于 2021-01-28 22:59:50
您可以使用以下命令从配置文件中获取任何属性:
repo = Repo(dir_of_repository)
user_name = repo.config_reader().get_value("user", "name")
https://stackoverflow.com/questions/60222627
复制相似问题