使用gitpython git上传后如何获取Gerrit URL?

时间:2018-06-26 20:18:09

标签: git gerrit gitpython

repo=Repo.clone_from(my_repo,'/path/to/clone')
git=repo.git
#cd to repo and do some update to my_file
git.add([my_file])
git.commit("My commit message")
#Upload to gerrit
git.push("origin","HEAD:refs/for/master")

此方法有效,我遵循了gitPython文档,但是不确定上传后如何获得Gerrit编号,我需要在相同的git.push上进行开发人员验证,只是返回一个空字符串。

Blockquote

1 个答案:

答案 0 :(得分:1)

您需要在with_extended_output=True中传递git.push()并使用元组(status, stdout, stderr)来获取输出。

status,out,err = git.push("origin","HEAD:refs/for/master",with_extended_output=True)

如果err,则可以在status == 0中找到数字和url。 err是一个字符串,您需要对其进行解析以获取确切的数字。

with_extended_output默认为False。它适用于所有git.xxx()方法。这些方法调用execute。有关更多详细信息,请参见链接。

相关问题