简体   繁体   English

用户输入git pre-receive hook

[英]User input in git pre-receive hook

So instead of putting ACLs in a git pre-receive hook, I just want to put a confirmation message (y/n) to anyone pushing into the master branch (which happens to be my release branch as well) of my project. 因此,与其将ACL置于git pre-receive钩子中,不如向所有推送到项目的master分支(也恰好是我的发布分支)的人添加确认消息(y / n)。

Something like this works for a client side hook, but I'm unsure of how to achieve this on server side: 这样的事情适用于客户端挂钩,但是我不确定如何在服务器端实现这一点:

while true; do
  read -p "[pre-commit hook] Really want to commit into master? (Y/n) " yn
  if [ "$yn" = "" ]; then
    yn='Y'
  fi  
  case $yn in
      [Yy] ) exit 0; break;;
      [Nn] ) exit 1;; 
      * ) echo "Please answer y or n for yes or no.";;
  esac
done

(this snippet has been taken from a stackoverflow answer, the link to which I'll put later, in the comments section) (此摘录摘自stackoverflow答案,我将在后面的评论部分中添加到该链接)

How do I do something like this with a pre-receive server side hook? 我如何使用预接收服务器端挂钩执行类似的操作?

Thanks! 谢谢!

As Zeeker suggested in a comment , you can't do this in a server hook: it has no input connection back to the user (said user may be using ssh to connect, via a git ssh:// URL, but that ssh is not hooked to his or her keyboard in any way). 正如Zeeker在评论中建议的那样 ,您不能在服务器挂钩中执行此操作:它没有返回到用户的输入连接(该用户可能正在通过ssh:// URL使用ssh进行连接,但是ssh是不会以任何方式钩住他或她的键盘)。

In the specific case of a pre-receive hook, the standard input is connected to a pipe, 1 the write end of which is connected to the command producing the oldsha1 newsha1 refname tuples (one per line). 在预接收钩子的特定情况下,标准输入连接到管道,管道1的写端连接到产生oldsha1 newsha1 refname元组(每行一个)的命令。 An update hook has its standard input connected to /dev/null (or the moral equivalent, depending on system). 一个更新钩子的标准输入连接到/dev/null (或等同于道德,取决于系统)。 There is no controlling terminal, so opening /dev/tty is not possible either. 没有控制终端,因此也无法打开/dev/tty


1 I wrote a program that copies the pipe data to a temporary file and then runs one or more subsidiary hooks with the input coming from the temporary file, with its seek offset reset to 0 for each separate hook. 1我编写了一个程序,该程序将管道数据复制到一个临时文件,然后运行一个或多个辅助钩子,输入来自该临时文件,对于每个单独的钩子,其查找偏移都重置为0。 This allows using multiple hooks, any one of which can reject the update. 这允许使用多个挂钩,其中任何一个都可以拒绝更新。 The pipe method is annoying since once one hook has consumed all the input, it cannot chain to a second hook, as the input is all gone. 管道方法很烦人,因为一旦一个钩子耗尽了所有输入,就无法链接到另一个钩子,因为输入已全部消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM