git-ai-commit
git-ai-commit copied to clipboard
feat(cli): add doctor_handler to check git hooks directory
Problem Description
Users were encountering a FileNotFoundError when running pip3 install git-ai-commit followed by gac.
The error occurred during the git hook setup process:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/user'sname/projs/cookd/.git/worktrees/candidate-search/hooks/prepare-commit-msg'
The issue was specifically happening in git worktrees, where the hooks directory doesn't exist by default and the code was using an incorrect path resolution method.
Root Cause Analysis
The problem was in two key areas:
Incorrect Path Resolution: The GitService.get_git_prepare_commit_msg_hook_path() method was using simple string concatenation (git_directory + "/hooks/prepare-commit-msg") instead of Git's proper path resolution.
Missing Directory Creation: The handle_setup_hook() function didn't create the hooks directory if it didn't exist, which is common in git worktrees.
Test Plan
recreated the bug by removing the the hook directory doesn't exist
Run this script to verify that the fix works correctly:
python3 test_hook_setup.py