Skip to content

Commit

Permalink
Update Pre-commit.md (#1293)
Browse files Browse the repository at this point in the history
Improve docs:
- Add missing steps
- Use the husky built-in attach method instead of manual csproj change.

(I would move Husky.Net to the first option as well, considering it's a
.NET tool and doesn't require Node to be installed, although I haven't
changed the order yet.)
  • Loading branch information
alirezanet authored Jun 13, 2024
1 parent b791ce6 commit 3d6f93a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions docs/Pre-commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,12 @@ repos:
From the root of your repository
```bash
cd <Your project root directory>
dotnet new tool-manifest
dotnet tool install husky
dotnet husky install
```

Optionally - add this to one of your projects to automate the install for future developers
```xml
<!-- set HUSKY to 0 in CI/CD disable this -->
<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High"
<!-- update this to be the root of your solution -->
WorkingDirectory="../../" />
</Target>
```

Modify the file at `.husky/task-runner.json`
```json
{
Expand All @@ -85,6 +76,12 @@ You can run and test your task with the following command.
dotnet husky run
```

Optionally - add this to one of your projects to automate the installation for future developers
You can set the HUSKY environment variable to 0 to disable Husky in CI/CD pipelines.
```bash
dotnet husky attach <path-to-project-file>
```

Once you are sure the task is working properly, you can add it as a pre-commit hook.
```bash
dotnet husky add pre-commit -c "dotnet husky run"
Expand Down

0 comments on commit 3d6f93a

Please sign in to comment.