小编Mot*_*tto的帖子

在更新挂钩中查看新分支上的提交

我写了一个更新挂钩(服务器端),它检查所有提交消息(检查是否存在问题ID)

有一个我的python代码(update.py)的摘录:

[...]
if newrev == "0000000000000000000000000000000000000000":
  newrev_type = "delete"
elif oldrev == "0000000000000000000000000000000000000000":  
  newrev_type = "create"

  # HERE IS MY QUESTION, I want to get the commits SHA-1 :-)

else:
  POPnewrev_type = os.popen("git cat-file -t " + newrev)
  newrev_type = POPnewrev_type.read()[0:-1]
  # get the SHA-1
  POPanalyzelog = os.popen("git log " + oldrev + ".." + newrev + " --pretty=#%H")
  analyzelog = POPanalyzelog.read().split('#')
[...]
Run Code Online (Sandbox Code Playgroud)

所以,在这里,如果newrev_type ="delete",用户想要删除分支=>没问题.
在推入现有分支的情况下,我们得到提交的SHA-1 => OK
但是当用户创建分支时,我不知道如何获得SHA-1 ...

你有什么想法?

git hook githooks

1
推荐指数
1
解决办法
1612
查看次数

标签 统计

git ×1

githooks ×1

hook ×1