Nutlope / aicommits

A CLI that writes your git commit messages for you with AI
https://www.npmjs.com/package/aicommits
MIT License
7.53k stars 360 forks source link

Pre-Commit Hook Not Working with Husky #237

Open Armadillidiid opened 11 months ago

Armadillidiid commented 11 months ago

Bug description

Issue Description: I am encountering an issue with the aicommits pre-commit hook when using it alongside husky in my Git repository. The aicommits tool is designed to generate commit messages based on the staged files, but when I stage my files and attempt to commit, no generated commits appear in the commit editor.

Steps to Reproduce:

  1. Install and set up husky in the Git repository for pre-commit hook management.
  2. Install and configure aicommits to generate commit messages based on staged files.
  3. Stage one or more files using git add .
  4. Attempt to make a commit using git commit.

Expected Behavior:

Upon running git commit, the aicommits pre-commit hook should generate a commit message based on the staged files, and this message should appear in the commit editor for review before the actual commit is made.

Actual Behavior:

After staging files and running git commit, the commit editor is opened, but there are no generated commit messages. I am required to write a commit message manually instead of seeing the generated commit message as expected.

Additional Information:

I have verified that aicommits is properly installed and working outside of Husky, generating commit messages as expected when using git commit directly.
I have double-checked that Husky is configured correctly in the repository and other pre-commit hooks (if any) are working as intended.
I am using husky 8.0.0 version
The issue occurs on both Unix-like

Husky pre-commit file

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

npx lint-staged

aicommits version

v1.11.0

Environment

System:
    OS: Linux 6.3 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
    Memory: 6.49 GB / 15.00 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 19.7.0 - ~/.nvm/versions/node/v19.7.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.5.0 - ~/.nvm/versions/node/v19.7.0/bin/npm

Can you contribute a fix?

Keshavdulal commented 9 months ago

Similar case: https://github.com/Nutlope/aicommits/issues/250#issuecomment-1733451662