alirezanet / Husky.Net

Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
https://alirezanet.github.io/Husky.Net/
MIT License
632 stars 29 forks source link

How to avoid empty commit? #87

Closed SunilDSK closed 10 months ago

SunilDSK commented 10 months ago

Version

0.6.0

Details

I have a webapi project with environment specific appsettings.json file. I don't want the appsettings.Development.json to be committed or pushed(its already tracked). I have a pre-commit hook with one command - git reset appsettings.Development.json. When I have appsettings.Development.json as only file, the pre-commit is unstaging the appsettings.Development.json file, but it is also creating an empty commit with no files. How do I avoid the empty commit?

Steps to reproduce

alirezanet commented 10 months ago

Hi @SunilDSK, I don't see it as a bug since I didn't fully understand what do you expect Husky does for you?

if you wanna prevent commits if appsettings.Development.json is staged I would suggest to use the task-runner instead.

something like: e.g pre-commit file

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

dotnet husky run -v --group "pre-commit"

task-runner.json

{
 "tasks": [
      {
         "name": "Verify staged files",
         "group": "pre-commit",
         "include": "appsettings.Development.json",
         "command": "cmd",
         "args": ["/c", "git reset appsettings.Development.json & exit 1", "${staged}"]
      }
]
}

This would automatically unstage the appsettings.Development.json file if it is staged and prevent the commits including this file.

also using taks-runner makes your console log prettier :)