简体   繁体   English

git 预推挂钩不适用于 visual studio git 界面

[英]git pre-push hook doesn't work with visual studio git interface

I have created a pre-push hook that runs all the unit tests (NUint) if a project that contains the string "NDI" has changed.如果包含字符串“NDI”的项目已更改,我已经创建了一个运行所有单元测试 (NUint) 的预推挂钩。

#!/bin/bash

# Get the current branch
branch=$(git rev-parse --abbrev-ref HEAD)

# Get the remote repository and branch
remote=$(git config --get branch.$branch.remote)
remote_branch=$(git config --get branch.$branch.merge | sed 's#^refs/heads/##')

# Check if any project containing "NDI" in its name has changed
if git diff --name-only $remote/$remote_branch HEAD | grep -q "NDI"; then
  # Run all NUnit tests
  dotnet test
fi

# If the tests failed, cancel the push
if [ $? -ne 0 ]
then
  echo "Tests failed. Push cancelled."
  exit 1
fi

The problem is when I try to use the visual studio git interface to push the new code to the remote repository I get the error message: "Failed to push to the remote repository. See the Output window for more details."问题是当我尝试使用 visual studio git 界面将新代码推送到远程存储库时,我收到错误消息: “无法推送到远程存储库。有关详细信息,请参阅 Output window。”
The output window doesn't have any special message about the problem, just about the successful build from the commit. output window 没有任何关于问题的特殊消息,只是关于从提交成功构建。 When I try to use the VS terminal with git push it does work and runs the unit tests successfully if an NDI project has changed.当我尝试将 VS 终端与git push一起使用时,如果 NDI 项目已更改,它会正常工作并成功运行单元测试。
Side note: it works as expected for the pre-commit hook.旁注:对于预提交挂钩,它按预期工作。

As of today, it is accepted that this is a bug and it is currently under Microsoft's consideration to be fixed.截至今天,公认这是一个错误,目前微软正在考虑修复它。 The decision to fix the bug will depend on the number of people affected by the issue.修复错误的决定将取决于受该问题影响的人数。
In the meantime, it is recommended to try workaround solutions or "follow and vote on that problem ticket" - Microsoft, in order to help prioritize a fix.同时,建议尝试变通解决方案或“关注问题单并对其进行投票”- Microsoft,以帮助确定修复的优先级。

Link to the problem on the forum: https://developercommunity.visualstudio.com/t/Failed-to-push-to-the-remote-repository/10238402论坛问题链接: https://developercommunity.visualstudio.com/t/Failed-to-push-to-the-remote-repository/10238402

I will try to keep this answer updated.我会尽量更新这个答案。

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

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