I'm trying to do some linting with dotnet format in a pre-commit hook in VS2022. The problem is that the pre-commit hook does not seem to be called when I use the VS Git gui to commit changes, even though it works when I use the command line. So even though the command line correctly cancels the commit as shown below, the gui erroneously creates a commit.
How can I get VS to actually use the pre-commit hook? I've seen it correctly use the pre-push hook.
pre-commit:
#!/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
command line output:
C:\Users\<username>\source\repos\WpfApp1>git commit -m "Test"
Running git format
xargs: dotnet-format: No such file or directory
Deliberate failure