相关疑难解决方法(0)

如何在commit-msg挂钩中提示用户?

我想警告用户,如果他们的提交消息不遵循某组指南,然后给他们选项来编辑他们的提交消息,忽略警告或取消提交.问题是我似乎无法访问stdin.

下面是我的commit-msg文件:

function verify_info {
    if [ -z "$(grep '$2:.*[a-zA-Z]' $1)" ]
    then
        echo >&2 $2 information should not be omitted
        local_editor=`git config --get core.editor`
        if [ -z "${local_editor}" ]
        then
            local_editor=${EDITOR}
        fi
        echo "Do you want to"
        select CHOICE in "edit the commit message" "ignore this warning" "cancel the commit"; do
            case ${CHOICE} in
                i*) echo "Warning ignored"
                    ;;
                e*) ${local_editor} $1
                    verify_info "$1" $2
                    ;;
                *)  echo "CHOICE = ${CHOICE}"
                    exit 1
                    ;;
            esac
        done
    fi
}

verify_info …
Run Code Online (Sandbox Code Playgroud)

git hook commit-message

69
推荐指数
3
解决办法
2万
查看次数

是否可以接受用户输入作为远程git post-receive hook的一部分?

每当我们推送master时,我都有一个post-receive钩子来部署我们的master分支.

我想使部署可选; 钩子要求简单的Y/N响应来实现这一点; 下面的bash伪代码:

echo "Should I deploy this code now? Enter Y/N"
read deploy_code

case ${deploy_code} in
  "Y") do_a_deploy ;;
  "N") exit ;;
    *) # ask the question again if not Y or N ;;
esac 
Run Code Online (Sandbox Code Playgroud)

由于post-receive钩子在stdin上获取其参数的方式,该 read 行不会暂停用户的输入,并且脚本循环遍历尝试获得Y/N答案.

我认为特别要求来/dev/tty解决这个问题;

read deploy_code < /dev/tty
Run Code Online (Sandbox Code Playgroud)

但这仍然导致脚本无休止地循环,因为输入不是来自键盘.

在这种情况下,实际上是否可以获得键盘输入?

编辑: 啊.看起来它实际上是责备.现在看输出我添加了 < /dev/tty 我看到/ dev/tty:没有这样的设备或地址

如果我在本地运行脚本,我可以模仿这个,但是通过ssh:

ssh 127.0.0.1 "echo 40913e300c8bf4ed7ea91b5ef61a522f3be2c05f e2aabfc865547d8b494b76c96947bab0c62acfec refs/heads/master | /path/to/post-receive"
Run Code Online (Sandbox Code Playgroud)

编辑2:

所以我可以将-t选项设置为ssh,以便在ssh会话中根据启用tty请求tty,或者我可以在每个密钥的基础上在服务器上的authorised_keys文件中启用它

编辑3:

创建〜/ bin/ssh -t之后

#!/bin/sh
ssh -tt "$@"
Run Code Online (Sandbox Code Playgroud)

(双-t选项强制tty)并设置GIT_SSH指向它,我现在得到可怕的 …

git ssh bash hook tty

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

标签 统计

git ×2

hook ×2

bash ×1

commit-message ×1

ssh ×1

tty ×1