feat(cli): add doctor_handler to check git hooks directory #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
Users were encountering a FileNotFoundError when running
pip3 install git-ai-commit
followed bygac
.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
Expected Outcome