Skip to content

fix: works on Windows? #3555

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

Closed
2 of 4 tasks
aderchox opened this issue Mar 1, 2023 · 5 comments
Closed
2 of 4 tasks

fix: works on Windows? #3555

aderchox opened this issue Mar 1, 2023 · 5 comments
Labels

Comments

@aderchox
Copy link

aderchox commented Mar 1, 2023

Expected Behavior

Hi, I'm new to Husky and Commitlint, I've learned about these in a tutorial, but the tutor is using Zsh and I'm using Pwsh7 on Windows. I wonder if it's supposed to work in my case?

When I want to make a commit, e.g., git commit -m "feat: with husky" I get an error about my previous (the first one) commit:

⧗ input: initial commit
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]

✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
husky - pre-commit hook exited with code 1 (error)

Even if I do git commit --amend to change the commit message of the last commit to conventional style, I get the exact same error as above.

Current Behavior

I expect my commit message "feat: with husky" to be accepted.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Steps to Reproduce

Here are the steps I've taken:
0. pnpm dlx husky-init && pnpm install

  1. pnpm add @commitlint/cli @commitlint/config-conventional
  2. Add this to the pre-commit script (instead of npm test) : npx --no -- commitlint --edit $1
  3. Create the config file commitlint.config.js and add this in it: module.exports = {extends: ['@commitlint/config-conventional']}
  4. git commit -m "feat: with husky" // gives the error I explained earlier

Context

I'm trying to lint my commit messages and I'm using Powershell7 on Windows, I see that Husky's documentation says Windows is supported, but I'm not sure about commitlint, and if I can use it in my case (also I don't know if it's worth mentioning, but I'm using pnpm, but I guess it must not be related to this issue).

commitlint --version

@commitlint/[email protected]

git --version

git version 2.37.0.windows.1

node --version

v18.12.1

@aderchox aderchox added the bug label Mar 1, 2023
@escapedcat
Copy link
Member

Can you try if this works in your project? Just mto make sure commitlint and the config in general are working:

echo "feat: with husky" | npx commitlint

Looks like somehow husky is using a previous commit instead of your current one. Maybe huskys config is not correct.
What's the content of these files if you have those?:

  • .husky/commit-msg
  • .husky/pre-commit

@aderchox
Copy link
Author

aderchox commented Mar 3, 2023

Yes that command does not give any errors and runs and terminates without an issue (it doesn't print anything too, I don't know if this is what you expected?). However, for some reasons, creating separate commit-msg and pre-commit scripts has fixed it for me! To realize what the real issue was I tried things again and just for your information, when both scripts are made into one, the issue I'd said occurs.

So this is the working state:

# .husky/commit-msg:

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

npx --no -- commitlint --edit $1

#######

# .husky/pre-commit:

# .husky/commit-msg:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpx lint-staged

And this is the bad state:

# .husky/pre-commit:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpx lint-staged
npx --no -- commitlint --edit $1

@escapedcat
Copy link
Member

@aderchox nice! Do we need to adjust the docs (...again)?

@aderchox
Copy link
Author

aderchox commented Mar 6, 2023

@aderchox nice! Do we need to adjust the docs (...again)?

Honestly, I don't know. I'm pretty new to using husky and commitlint and I don't know what changes you've made to the docs in the past (talking of your "...again" lol). If you think other newcomers to this package might make the same mistake, I think a notice could be helpful. Or otherwise just ignore it and let's hope the curious will search issues and will find this issue here. :)

@escapedcat
Copy link
Member

If you like you can create a PR with a notice to the README. Apart from that I guess you could close this for now.

@aderchox aderchox closed this as completed Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants