简体   繁体   中英

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.

#!/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."
The output window doesn't have any special message about the problem, just about the successful build from the commit. 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.
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.

Link to the problem on the forum: https://developercommunity.visualstudio.com/t/Failed-to-push-to-the-remote-repository/10238402

I will try to keep this answer updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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