【发布时间】:2021-12-14 08:50:02
【问题描述】:
我正在尝试在 VS2022 的预提交挂钩中使用 dotnet 格式进行一些 linting。问题是,当我使用 VS Git gui 提交更改时,似乎没有调用 pre-commit 挂钩,即使它在我使用命令行时有效。因此,即使命令行正确取消了提交,如下所示,gui 也会错误地创建提交。
如何让 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
【问题讨论】: