我尝试使用VS2022中的dotnet format在预提交挂钩中进行一些代码检查。但问题是,当我使用VS Git GUI提交更改时,预提交挂钩似乎没有被调用,即使在命令行中使用时它是可以工作的。即使命令行正确地取消了提交,GUI错误地创建了一个提交。
我该如何让VS实际使用预提交挂钩呢? 我已经看到它可以正确使用预推挂钩。
预提交:
我该如何让VS实际使用预提交挂钩呢? 我已经看到它可以正确使用预推挂钩。
预提交:
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
echo >&2 "Running git format"
LC_ALL=C
# Select files to format
FILES=$(git diff --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Format all selected files
echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --files
# Add back the modified files to staging
echo "$FILES" | xargs git add
echo >&2 "Deliberate failure"
exit 1
命令行输出:
C:\Users\<username>\source\repos\WpfApp1>git commit -m "Test"
Running git format
xargs: dotnet-format: No such file or directory
Deliberate failure