我正在做一个git post-commit挂钩将我的提交消息发布到Twitter。我在服务器上设置了钩子,这意味着它只在我拨打git push
时运行。当推送到服务器时获取所有提交
为了与python的git接口,我使用的是GitPython。在我的代码中,我使用repo.head.commit.message
来获取最新的提交消息。这意味着如果我推送多个提交,它只会得到最后一个提交。
这是我到目前为止。
class GITHelper:
"This class interacts with GIT for us"
def __init__(self, path):
repo = git.Repo(path)
headcommit = repo.head.commit
self.message = headcommit.message
self.author = headcommit.author.name
如何从推送中获取所有提交?或者,我如何获得推送的提交数量?
repo.iter_commits('master', max_count=5)
可以得到尽可能多的提交,所以如果我知道有多少提交,我可以使用它。
编辑:我测试,当我运行git push
,看来这个钩子获取从最后头承诺,不是我只是推。如何创建一个post-commit钩子来从我刚推送到服务器的提交中获取消息?
编辑2:我实际上使用更新挂钩,而不是后提交挂钩,是在服务器上使用正确的挂钩?
http://twitter.com/isnotrss – 2011-06-09 03:26:42