Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git预推钩子-缺少构建文件_Git_Githooks - Fatal编程技术网

git预推钩子-缺少构建文件

git预推钩子-缺少构建文件,git,githooks,Git,Githooks,我尝试使用git的预推钩子在每次推之前执行构建任务。到目前为止,这种方法可以很好地构建、添加和提交文件,但不会推送文件。代码如下: #!/bin/sh # Pre-Push hook to to build # files before pushing them. # If files are in the staging area # the push aborts. unstagedFiles=`expr $(git status --porcelain 2>/dev/null| g

我尝试使用git的预推钩子在每次推之前执行构建任务。到目前为止,这种方法可以很好地构建、添加和提交文件,但不会推送文件。代码如下:

#!/bin/sh
# Pre-Push hook to to build
# files before pushing them.
# If files are in the staging area
# the push aborts.

unstagedFiles=`expr $(git status --porcelain 2>/dev/null| grep "^ M" | wc -l)`
stagedFiles=`expr $(git diff --cached --numstat | wc -l)`

# if there are unstaged files abort push
if [ "$unstagedFiles" -gt 0 ]; then
    echo "Pre-Push-Hook: ERROR - You have unstaged files! - please add and commit them"
    exit 1
fi

# if there are staged files abort push
if [ "$stagedFiles" -gt 0 ]; then
    echo "Pre-Push-Hook: ERROR - You have uncommited files! - please commit them"
    exit 1
fi

echo "Pre-Push-Hook: Building files"
grunt build
echo "Pre-Push-Hook: Files built"

echo "Pre-Push-Hook: Adding following build-files"
git add -A .

git commit -m "automatically added build files"
echo "Pre-Push-Hook: Build-files commited"

exit 0
我尝试在脚本中进行另一次推送,如下所示:

branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
git push origin $branch --no-verify
exit 1
这工作得很好,但退出时当然会出现一条错误消息,这并不是很完美!在脚本中使用另一个推送并使用1退出时,是否有人有任何想法使实际推送工作或隐藏错误消息


已经有人问过类似的问题,但答案让这个问题悬而未决……

如果我正确理解了您的方法,我认为您需要密切关注链接中提供的答案,特别是以下内容:

预推钩用于验证该推送操作是否正常, 不是将此推送更改为其他不同的推送操作。 使用预推钩作为验证工具;如果你想要一个脚本 调用git推送。。。将其作为脚本编写,使用不同的名称,例如 建立和推动


您到底得到了什么错误?我得到了以下错误消息,这是由钩子中的出口1导致的标准消息:未能将某些引用推送到'git@github.com:…'目标是迫使开发人员在提交之前进行构建,而不依赖他们执行单独的脚本。我读过这一节,但我认为我仍然可以用它来完成这一点。。。