繁体   English   中英

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

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

如果包含字符串“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

问题是当我尝试使用 visual studio git 界面将新代码推送到远程存储库时,我收到错误消息: “无法推送到远程存储库。有关详细信息,请参阅 Output window。”
output window 没有任何关于问题的特殊消息,只是关于从提交成功构建。 当我尝试将 VS 终端与git push一起使用时,如果 NDI 项目已更改,它会正常工作并成功运行单元测试。
旁注:对于预提交挂钩,它按预期工作。

截至今天,公认这是一个错误,目前微软正在考虑修复它。 修复错误的决定将取决于受该问题影响的人数。
同时,建议尝试变通解决方案或“关注问题单并对其进行投票”- Microsoft,以帮助确定修复的优先级。

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

我会尽量更新这个答案。

暂无
暂无

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

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