Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash exit 1 doesn't work #71

Open
aliasadidev opened this issue Apr 17, 2023 · 4 comments · May be fixed by #72
Open

bash exit 1 doesn't work #71

aliasadidev opened this issue Apr 17, 2023 · 4 comments · May be fixed by #72
Labels
bug Something isn't working

Comments

@aliasadidev
Copy link
Contributor

Version

0.5.4

Details

The tool doesn't care about the errors, the information attached into Steps to reproduce section

Steps to reproduce

setup and config

dotnet new console -n App1
git init

dotnet new tool-manifest
dotnet tool install Husky
dotnet husky install

dotnet husky add pre-commit -c "dotnet husky run --group pre-commit'"

add .editorconfig file

https://github.com/RehanSaeed/EditorConfig/blob/main/.editorconfig

pre-commit file content

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

dotnet husky run --group pre-commit

# I want to run a condition here, e.g if dotnet format updated some files then the git commit would be rejected 
exit 1 # <============ didn't work for c# files

Task-runner.json

{
  "tasks": [
    {
      "name": "Dotnet Format",
      "command": "cmd",
      "pathMode": "relative",
      "args": [
        "/c",
        "dotnet",
        "format",
        "--include",
        "${staged}"
      ],
      "group": "pre-commit"
    }
  ]
}

Update program.cs (with bad format)

using App1;

internal class Program
{
    private static void Main(string[] args)
    {
   int x=100;
int xx=x;
    }
}

Add all files

git add .
git commit -m "init"

The problem is when I send the git commit, it will be stored successfully, but it shouldn't be.

image

As you can see the file should be placed in the change section.

image

Dotnet format worked correctly (added the file as a new file changed)

image

@aliasadidev aliasadidev added the bug Something isn't working label Apr 17, 2023
@aliasadidev aliasadidev linked a pull request Apr 17, 2023 that will close this issue
11 tasks
@aliasadidev
Copy link
Contributor Author

#72 fixed on this pr

@aliasadidev
Copy link
Contributor Author

@alirezanet
Hi, I'm back again :)
the problem solved when i added that flag

@alirezanet
Copy link
Owner

Hi @aliasadidev,
thank you for the contribution but your pr is still open, this issue will automatically close after we merge it. also, I want to check what is going on later

@alirezanet
Copy link
Owner

alirezanet commented Apr 18, 2023

Hi @aliasadidev,
Checking your issue and PR I still don't get why this is needed, if you want to write a condition in the hook itself why do you need husky? the main goal of this library is to avoid editing hooks manually, and since dotnet format doesn't exit with a non-zero exit code husky doesn't interfere with the commit.

I think the better approach to solving similar problems is to use a csx script or some other script file and call it from the husky(instead of calling dotnet-format directly), this way your logic is separated and maintainable and your hook file is not complicated. unless I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants