Skip to content

Conversation

Seif-Mamdouh
Copy link
Collaborator

@Seif-Mamdouh Seif-Mamdouh commented May 23, 2025

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 Seif-Mamdouh marked this pull request as draft May 23, 2025 19:14
@Seif-Mamdouh Seif-Mamdouh requested a review from Copilot May 29, 2025 03:09
@Seif-Mamdouh Seif-Mamdouh marked this pull request as ready for review May 29, 2025 03:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in git hook setup for worktrees by correcting the path resolution and ensuring that the hooks directory is created when missing. It also adds a new doctor_handler to check the git hooks directory and updates relevant tests to verify the changes.

  • Fix wrong hook path resolution in git_service by using git's built-in command.
  • Ensure handle_setup_hook creates missing directories.
  • Add doctor_handler to provide status information about the git hooks directory.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test_hook_setup.py Adds tests for verifying that missing hooks directories are created and checking local git hooks.
ai_commit_msg/services/llm_service.py Minor formatting update; no functional changes.
ai_commit_msg/services/git_service.py Updates hook path determination to use git's rev-parse command.
ai_commit_msg/cli/hook_handler.py Ensures hooks directory is created before writing the hook file.
ai_commit_msg/cli/doctor_handler.py Introduces a new utility for checking the git hooks directory.
Comments suppressed due to low confidence (1)

test_hook_setup.py:34

  • [nitpick] Consider using assert statements to validate test outcomes instead of relying solely on print outputs, which would enable automated test failure detection.
print("✅ Test completed successfully!")

hooks_dir = execute_cli_command(
["git", "rev-parse", "--git-path", "hooks"]
).stdout.strip()
return hooks_dir + "/prepare-commit-msg"
Copy link
Preview

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using os.path.join(hooks_dir, 'prepare-commit-msg') to build the path, which improves cross-platform compatibility.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant