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

First `husky add` some command is not line-terminated #12

Closed atifaziz closed 2 years ago

atifaziz commented 2 years ago

Running dotnet husky add with some command is not line-terminated. Another execution will put the second command together with the first one. The bug only happens for the first invocation.

To Reproduce

Run the following commands in a shell, in a new directory and in the shown sequence:

git init
dotnet new tool-manifest
dotnet tool install Husky
dotnet husky install
dotnet husky add .husky/pre-commit "echo 'Husky is awesome!'"
dotnet husky add .husky/pre-commit "echo 'Husky is awesome!'"
git commit --allow-empty -m "Keep calm and commit"

The final git commit will print the following:

Husky is awesome!echo Husky is awesome!
[master (root-commit) 656c076] Keep calm and commit

Note that what gets printed from the hook is the single line Husky is awesome!echo Husky is awesome!.

Expected behavior

I would have expected the following output:

Husky is awesome!
Husky is awesome!
[master (root-commit) 656c076] Keep calm and commit

That is Husky is awesome! printed on two separate lines.

Additional information

It's clear why this is happening when one inspects the content of .husky/pre-commit:

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

## husky task runner examples -------------------
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky'

## run all tasks
#husky run

### run all tasks with group: 'group-name'
#husky run --group group-name

## run task with name: 'task-name'
#husky run --name task-name

## or put your custom commands -------------------
#echo 'Husky.Net is awesome!'

echo 'Husky is awesome!'echo 'Husky is awesome!'

The first command was not line-terminated.

This does not happen for subsequent runs of husky add. For example, following-up with the commands:

dotnet husky add .husky/pre-commit "echo 'Husky is awesome!'"
git commit --allow-empty -m "Keep calm and commit"

prints:

Husky is awesome!echo Husky is awesome!
Husky is awesome!
[master 51f1c2b] Keep calm and commit

The third addition correctly printed on its own line.

atifaziz commented 2 years ago

Closed via f77ebfa3be829bed5ccd51ae0b5b502bd5665c94 that was a merge of PR #13.