Details
Be able to run hooks only for staged (commit-msg, pre-commit) or committed (pre-push) changes.
The problem:
- When developer runs
dotnet format via pre-commit hook all upstaged changes are formatted and committed. This will include lines that are not intended to be part of the commit. Developer could have used git add -i for staging the changes.
- When developers run
dotnet build / dotnet tests via pre-push hook the project is build with uncommitted changes. This could lead to pushing changes that are passing locally but failing in CI/CD pipeline and vice-versa.
Solution:
Stash upstaged / uncommitted changes when hook is invoked
Details
Be able to run hooks only for staged (
commit-msg,pre-commit) or committed (pre-push) changes.The problem:
dotnet formatviapre-commithook all upstaged changes are formatted and committed. This will include lines that are not intended to be part of the commit. Developer could have usedgit add -ifor staging the changes.dotnet build/dotnet testsviapre-pushhook the project is build with uncommitted changes. This could lead to pushing changes that are passing locally but failing in CI/CD pipeline and vice-versa.Solution:
Stash upstaged / uncommitted changes when hook is invoked