-
I had the same problem as #88 How to avoid an empty commit which was closed without a satisfactory answer. I want to run CSharpier auto-formatting, but not create an empty commit in case the end result is that all my changes were reverted. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Based on this answer, the git check that you should not make an empty commit, runs before the I managed to achieve something very similar using an extra task in the Husky.Net task runner: {
"$schema": "https://alirezanet.github.io/Husky.Net/schema.json",
"tasks": [
{
"name": "Format using CSharpier",
"group": "pre-commit",
"command": "dotnet",
"args": ["csharpier", "${staged}"],
"include": ["**/*.cs"]
},
{
"name": "Check for empty commit",
"group": "pre-commit",
"command": "sh",
"args": ["-c", "! git diff --cached --quiet"]
}
]
} The second command runs your standard POSIX compliant shell, executes Note that you can run an arbitrary number of pre-commit hooks, each with their own logic, before the check for empty commit. As long as that check is last, you won't accidentally check in an empty commit when your changes are automatically reverted by another pre-commit hook. |
Beta Was this translation helpful? Give feedback.
Based on this answer, the git check that you should not make an empty commit, runs before the
pre-commit
hook. I want the check to apply after my other pre-commit hook has run.I managed to achieve something very similar using an extra task in the Husky.Net task runner:
Th…