我是否可以从python git预接收挂钩返回消息,前缀错误:而不是远程:
我在python中编写了一个git预接收钩子,如果用户试图推送到禁止的目录,它将中止该进程 执行此操作的函数将获取filepath的一个参数,并在这些参数上迭代以查找顽皮的dir,如下所示我是否可以从python git预接收挂钩返回消息,前缀错误:而不是远程:,python,git,hook,Python,Git,Hook,我在python中编写了一个git预接收钩子,如果用户试图推送到禁止的目录,它将中止该进程 执行此操作的函数将获取filepath的一个参数,并在这些参数上迭代以查找顽皮的dir,如下所示 for filename in changed: pieces = filename.split('/') if(len(pieces) >3 and pieces[0] == 'application' and pieces[1] == 'modules' and pieces[3]
for filename in changed:
pieces = filename.split('/')
if(len(pieces) >3 and pieces[0] == 'application' and pieces[1] == 'modules' and pieces[3] == 'core'):
# User is trying to push to application/modules/[MODULE_NAME]/core directory, they must be stopped!
msg = 'You are pushing code that will be over-written by framework updates: ' + filename + '. THIS IS NOT ALLOWED!'
print(msg)
exit(1)
它可以工作,并返回如下格式的消息
for filename in changed:
pieces = filename.split('/')
if(len(pieces) >3 and pieces[0] == 'application' and pieces[1] == 'modules' and pieces[3] == 'core'):
# User is trying to push to application/modules/[MODULE_NAME]/core directory, they must be stopped!
msg = 'You are pushing code that will be over-written by framework updates: ' + filename + '. THIS IS NOT ALLOWED!'
print(msg)
exit(1)
远程:您正在推送将被覆盖的代码..等等
然后是
错误:无法推送某些引用…等
但是,我想做的是替换print调用,并将消息作为错误返回,因此它是这样读的
错误:您正在推送的代码将被覆盖…等等
我的理由是,我怀疑不同的gui-git客户机会以不同的方式显示错误(即红色、带有弹出窗口、感叹号等),并且它们更有可能被试图推送的人读取。有人知道怎么做吗?你不知道,因为git的钩子处理代码只会接收返回的每个字符串(特别是在边带通道2上;这就是钩子输出结束的地方),并将单词
remote:
粘贴在它前面(请参见sideband.c
中的recv_sideband()
)。您可以让它打印remote:error:
并用手指交叉,gui可能会将其识别为错误字符串。:-) 真可惜。我不能像从web服务返回异常或类似的东西?我描述的代码是针对本机git协议的(通过git://和ssh://连接使用)。web界面略有不同,但最终做的事情与我想的差不多(我对它的经验要少得多)。