opencommit icon indicating copy to clipboard operation
opencommit copied to clipboard

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

Open TravelingTice opened this issue 2 years ago • 2 comments

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'

TravelingTice avatar Jul 17 '23 13:07 TravelingTice

Stale issue message

github-actions[bot] avatar Aug 26 '23 21:08 github-actions[bot]

one can gets the submodule hook path by git rev-parse --git-path hooks like:

hook_dir=$(git rev-parse --git-path hooks)
mkdir -pv "$hook_dir"

then put opencommit link inside.

However this triggers a side issue about TTY initialization failure, whitch i have no clue:

┌  open-commit
│
◇  1 staged files:
  ...
│
◇  📝 Commit message generated
│
└  Generated commit message:
——————————————————
....
│
◇  ✖ Failed to generate the commit message
SystemError [ERR_TTY_INIT_FAILED]: TTY initialization failed: uv_tty_init returned EINVAL (invalid argument)
    at new WriteStream (node:tty:92:11)
    at xD2.prompt (/home/jethro/.local/share/mise/installs/node/20.18.0/lib/node_modules/opencommit/out/cli.cjs:46853:16)
    at Q3 (/home/jethro/.local/share/mise/installs/node/20.18.0/lib/node_modules/opencommit/out/cli.cjs:47087:8)
    at generateCommitMessageFromGitDiff (/home/jethro/.local/share/mise/installs/node/20.18.0/lib/node_modules/opencommit/out/cli.cjs:64638:69)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async trytm (/home/jethro/.local/share/mise/installs/node/20.18.0/lib/node_modules/opencommit/out/cli.cjs:64584:18)
    at async commit (/home/jethro/.local/share/mise/installs/node/20.18.0/lib/node_modules/opencommit/out/cli.cjs:64786:35) {
  code: 'ERR_TTY_INIT_FAILED',
  info: {
    errno: -22,
    code: 'EINVAL',
    message: 'invalid argument',
    syscall: 'uv_tty_init'
  },
  errno: [Getter/Setter: -22],
  syscall: [Getter/Setter: 'uv_tty_init']
}
│
└  ✖ TTY initialization failed: uv_tty_init returned EINVAL (invalid argument)

cometjc avatar Jan 07 '25 03:01 cometjc