python - 使用 python 读取和更新 git 配置?
问题描述
我试过configparser
了,但它不尊重 git 配置文件的缩进(git 配置文件在部分内有缩进,而不是没有缩进的 linux 通常格式)。更新配置文件后,所有缩进都消失了。
这里有类似的问题:如何使用 gitPython 模拟读取和更新 git 全局配置文件?
不过,我想知道是否可以使用本机 python 来做同样的事情?还是gitpython
最好的选择?
例如,在更新之前,配置如下所示:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
在我用 更新它后configparser
,它看起来像这样:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
test = 10
PS 建议gitconfig
的库似乎甚至不存在。它没有安装,说它是某种虚拟项目。
解决方案
这对我有用:
with repo.config_writer() as config:
config.set_value("git-p4", "client", p4client)
推荐阅读
- excel - 根据上面单元格中的文本求和
- javascript - AJAX - 在选择输入中更改事件时更改元素的 innerHTML 不起作用
- python - 没有可重定向到的 URL
- c++ - 用于在 char 数组之间复制 x 元素的更短代码
- java - 在整个活动中改变音量
- javascript - jQuery 根据值和数据属性检查 Cookie 和隐藏内容
- javascript - 如何在JS中增加数组索引
- java - 在枚举中实现接口时,为什么 eclipse 会自动在被覆盖的接口方法之前放置一个分号?
- python-3.x - python3 mysql.connector - 从光标获取结果/输出
- testing - 收到错误 WebDriverException:消息:未知错误:调用函数结果缺少“值”