git-ai-commit icon indicating copy to clipboard operation
git-ai-commit copied to clipboard

feat(cli): add doctor_handler to check git hooks directory

Open Seif-Mamdouh opened this issue 6 months ago • 0 comments

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

Screenshot 2025-05-28 at 11 08 04 PM

Run this script to verify that the fix works correctly:

python3 test_hook_setup.py

Expected Outcome

Screenshot 2025-05-28 at 11 09 35 PM

Seif-Mamdouh avatar May 23 '25 19:05 Seif-Mamdouh