Git-hooks pre-push脚本不通过STDIN接收输入

dco*_*cow 6 git bash githooks

GIT-钩预推文档指出的第一行的stdin将与本地ref和sha,并远程ref和SHA这样来填充:

<local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF

但是,我的简单预推脚本:

#!/bin/bash

echo "params=[$@]"

read line
echo "stdin=[$line]"

exit 1
Run Code Online (Sandbox Code Playgroud)

$git push运行时返回以下输出:

params=[origin [url]:[branch].git]
stdin=[]
error: failed to push some refs to '[remote]'
Run Code Online (Sandbox Code Playgroud)

脚本的参数如文档中所指定(远程的名称和路径).错误是预期的,因为我的脚本以状态1退出.但是,我似乎无法弄清楚为什么我没有收到文档指定的stdin上的本地和远程引用.

这是git中的错误吗?或者,我错过了什么?

M S*_*lle 8

抱歉,如果这说明显而易见,但如果没有什么可以推动,你就不会在stdin上获得任何线条.样本.git/hooks/pre-push.sample有一个while循环:

IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
    ...
done
Run Code Online (Sandbox Code Playgroud)

当我在这里尝试使用回路内部的循环而没有别的东西时,这似乎有效 - 当我没有任何东西可以推动时,我什么也得不到,当我这样做时输出.