Custom logic that runs right before you create a Git commit.
- Checks for
FIXME
in any of the staged text files, so that you don't accidentally commit any code that you don't want to.- If it finds any, it stops the commit and tells you which file and line number it was found in, so you can fix the code.
- Checks staged .NET package lock files for
Microsoft.NET.ILLink.Tasks
, which is automatically added by Visual Studio and causes package restoration in locked mode to fail because it's not a real dependency of your project.- If it finds any, it automatically removes this dependency from
packages.lock.json
so thatdotnet restore --locked-mode
will succeed. This does not break Visual Studio either, which will either ignore it or try to add it again later. The commit continues automatically.
- If it finds any, it automatically removes this dependency from
- Git
- .NET 8 Runtime x64 or later
- Download
pre-commit.exe
from the latest release. - Save it to a Git hooks directory, depending on the scope you want it to apply to.
- One repository:
<repo>/git/hooks/pre-commit.exe
- All repositories for a user: any directory, then run
git config --global core.hookspath "<directory>"
- All repositories on a computer: any directory, then run
git config --system core.hookspath "<directory>"
- One repository:
Just run git commit
the way you normally would. If it commits successfully, there were no fatal errors.
If you want to test the hook without committing anything, you can run
git hook run pre-commit --no-ignore-missing