【问题标题】:git pre-push: connection closed by remote host while running testsgit pre-push:运行测试时远程主机关闭连接
【发布时间】:2016-01-11 14:48:30
【问题描述】:

我的 git 存储库中有一个运行测试的预推送脚本。如果测试通过,则推送继续。如果测试失败,它将中止推送。

脚本运行了一段时间,直到测试开始超过 3 分钟。标准输出在测试输出中间显示“与远程主机关闭的 bitbucket 的连接”。然后所有的测试都通过了,推送实际上并没有通过。

这是预推送脚本

#!/bin/sh
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# This script runs tests before any push to the MASTER branch and fails
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
echo "Current branch: "$current_branch
if [ $current_branch = "master" ]
then
    echo "Pushing to MASTER branch requires tests to pass..."
    ./run.sh test
    if [ $? = 0 ]
    then
        exit 0
    else
        echo "***ERROR> Failed to pass tests! Get tests to pass and then try again..."
        exit 1
    fi
else
    echo "Skipping tests since we're not pushing to MASTER..."
fi

【问题讨论】:

  • @greg0ire,我已经尝试过 600 次睡眠,它对我来说效果很好。 exit 1 代码停止推送
  • 没看懂,能详细点吗?

标签: git testing githooks


【解决方案1】:

你检查过bitbucket.properties吗?也许您遇到了一些超时,例如:process.timeout.executionplugin.bitbucket-scm-git.backend.timeout.idle。可能快速检查一下是否有一些超时设置为 180 秒。 Here 您可以找到有关可用属性的更多详细信息。

【讨论】:

  • 在哪里可以设置这些参数?
  • 我们没有托管自己的 bitbucket 服务器,所以我认为我无权访问这些属性
【解决方案2】:

我最终在成功案例中致电git push --no-verify。所以它有效地推动了两次。

#!/bin/sh
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# This script runs tests before any push to the MASTER branch and fails
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
echo "Current branch: "$current_branch
if [ $current_branch = "master" ]
then
    echo "Pushing to MASTER branch requires tests to pass..."
    ./run.sh test
    if [ $? = 0 ]
    then
        # workaround to guarantee my push goes through even if the first attempt times out
        git push --no-verify
        exit 0
    else
        echo "***ERROR> Failed to pass tests! Get tests to pass and then try again..."
        exit 1
    fi
else
    echo "Skipping tests since we're not pushing to MASTER..."
fi

【讨论】:

  • 当您还没有设置远程跟踪分支时,该脚本不起作用。如果您还想涵盖这种情况,它会变得更加复杂,因为您需要读取推送到的远程哈希(使用stackoverflow.com/a/42462882/4521402)。
  • 感谢朋友的分享!这解决了我在 2021 年的问题!
【解决方案3】:

答案应该解释为什么 git 试图访问 Gitlab 或 Bitbucket 或其他任何东西(在我的情况下是 Gitlab),即使预推送脚本尚未完成

pre-push 钩子在 commit ec55559, Jan. 2013, Git v1.8.2-rc0 中引入

它是as/pre-push-hook 补丁的一部分:

参见Aaron Schrab (aschrab)@commit 87c86ddcommit ec55559commit 5a7da2d(2013 年 1 月 13 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit bb9a696,2013 年 1 月 24 日)

唯一的其他修改是 commit af65f68(2015 年 11 月 16 日)由 Clemens Buchacher (drizzd) 忽略 SIGPIPE,意思是忽略它 标准输入流。 (由 Jeff King -- peff -- 合并于 commit 40fdcc5,2015 年 12 月 1 日)

documentation does include:

钩子的标准中提供了有关要推送的内容的信息 输入表格行:

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

例如,如果命令 +git push origin master:foreign+ 运行 hook 会收到如下一行:

refs/heads/master 67890 refs/heads/foreign 12345

虽然将提供完整的 40 个字符的 SHA1。

  • 如果外部引用尚不存在,&lt;remote SHA1&gt; 将为 40 0
  • 如果要删除引用,&lt;local ref&gt; 将提供为(delete)&lt;local SHA1&gt; 将为 40 0

为了确定远程 SHA1 的正确值,transport.c 必须与远程存储库(在您的情况下为 GitLab)交换

【讨论】:

  • 现在这就是我所说的出色答案!赏金授予:)
  • @greg0ire 谢谢。 Tarun Lalwani's comment above 怎么样?这是一种可能的解决方法吗?
  • TBH 我不明白他的评论……你呢?
  • @greg0ire 不,我也不知道,也许您可​​以要求澄清一下,以防他的提示可能会阻止联系远程服务器。 (或者可能是联系到了,但是提前退出让一切都停止了)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-23
  • 2014-07-30
  • 2020-04-28
  • 1970-01-01
  • 1970-01-01
  • 2012-08-30
  • 1970-01-01
相关资源
最近更新 更多