di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
5.94k stars 311 forks source link

[Bug]: `opencommit hook set` not working when git project is a submodule #224

Open TravelingTice opened 1 year ago

TravelingTice commented 1 year ago

Opencommit Version

2.4.1

Node Version

18.12.1

NPM Version

8.19.2

What OS are you seeing the problem on?

Mac

What happened?

When running opencommit hook set in a repository that is a submodule of another repository, it displays the following error:

┌  setting opencommit as 'prepare-commit-msg' hook at .git/hooks/prepare-commit-msg
│
└  ✖ Error: ENOTDIR: not a directory, mkdir '.git/hooks'

It's trying to add the hook to the folder in the .git folder but this is not a folder, rather a file, pointing to the parent repo with a git subfolder:

gitdir: ../.git/modules/malong

Expected Behavior

When running opencommit hook set the hook will be set for the submodule repository.

Current Behavior

It's giving an error when trying to do this: ✖ Error: ENOTDIR: not a directory, mkdir '.git/hooks'

Possible Solution

Maybe it's possible to check the file and locate the git folder for this submodule... or maybe change the way the hook is set by using git commands for this? I'm afraid I don't really have the knowledge for this..

Steps to Reproduce

  1. Create a repository.
  2. Create a repository which is a git submodule of the parent repository.
  3. Run opencommit hook set on the submodule repository
  4. See the error coming up ✖ Error: ENOTDIR: not a directory, mkdir '.git/hooks'

Relevant log output

┌  setting opencommit as 'prepare-commit-msg' hook at .git/hooks/prepare-commit-msg
│
└  ✖ Error: ENOTDIR: not a directory, mkdir '.git/hooks'
github-actions[bot] commented 1 year ago

Stale issue message