title: Git pre-commit hook in Visual Studio 2022
body: <p>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.</p>
  <p>How can I get VS to actually use the pre-commit hook? I've seen it correctly use the pre-push hook.</p>
  <p>pre-commit:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/sh
  #
  # An example hook script to verify what is about to be committed.
  # Called by &quot;git commit&quot; 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 &quot;pre-commit&quot;.
  
  echo &gt;&amp;2 &quot;Running git format&quot;
  LC_ALL=C
  # Select files to format
  FILES=$(git diff --name-only --diff-filter=ACM &quot;*.cs&quot; | sed 's| |\\ |g')
  [ -z &quot;$FILES&quot; ] &amp;&amp; exit 0
  # Format all selected files
  echo &quot;$FILES&quot; | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --files
  # Add back the modified files to staging
  echo &quot;$FILES&quot; | xargs git add
  echo &gt;&amp;2 &quot;Deliberate failure&quot;
  exit 1
  </code></pre>
  <p>command line output:</p>
  <pre><code>C:\Users\&lt;username&gt;\source\repos\WpfApp1&gt;git commit -m &quot;Test&quot;
  Running git format
  xargs: dotnet-format: No such file or directory
  Deliberate failure
  </code></pre>