This project provides a pre-commit hook for Git that automatically applies ReSharper code formatting rules using JetBrains CLI tools. It ensures consistent code formatting across your project by applying the rules defined in your .DotSettings
files before each commit.
- Automatically detects and applies the nearest
.DotSettings
file for each staged file - Uses JetBrains CLI tools to apply ReSharper formatting rules
- Prevents commits if files are reformatted, requiring you to review and stage the changes
- Supports nested
.DotSettings
files in different directories - Cross-platform compatible (works on Windows, macOS, and Linux)
- JetBrains CLI tools installed and available in your PATH
dotnet tool install -g JetBrains.ReSharper.GlobalTools
.DotSettings
file(s) in your project
- Make the installation script executable:
chmod +x install.sh
- Run the script with your project directory as an argument:
./install.sh /path/to/your/project
The script will:
- Check if JetBrains CLI tools are installed and install them if needed
- Verify the project directory is a valid git repository
- Copy the pre-commit hook to the correct location
- Set the proper permissions
- Copy the
pre-commit
file to your project's.git/hooks
directory:
cp pre-commit .git/hooks/
chmod +x .git/hooks/pre-commit
- Make sure you have a
.DotSettings
file in your project root or in the appropriate subdirectories.
- Stage your changes as usual with
git add
- When you run
git commit
, the hook will:- Find the appropriate
.DotSettings
file for each staged file - Apply ReSharper formatting rules using the JetBrains CLI
- If any files are reformatted, the commit will be prevented
- Review the reformatted files and stage them again if you're satisfied with the changes
- Find the appropriate
This project is open source and available under the MIT License.