the-cafe / git-ai-commit

let AI write your commit messages
https://pypi.org/project/git-ai-commit/
52 stars 0 forks source link

fix bugs for v1.0.7 #60

Closed ming1in closed 3 months ago

ming1in commented 3 months ago

Description

Patch a crash that occurs when you execute husky setup in a repo that doesn't have it

> gac hook --setup  
Traceback (most recent call last):
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/utils/utils.py", line 7, in execute_cli_command
    result = subprocess.run(
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'config', '--get', 'core.hooksPath']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ming1in/.pyenv/versions/3.9.6/bin/gac", line 8, in <module>
    sys.exit(main())
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/main.py", line 68, in main
    hook_handler(args)
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/cli/hook_handler.py", line 90, in hook_handler
    if HuskyService.repo_has_husky_framework():
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/services/husky_service.py", line 11, in repo_has_husky_framework
    git_hook_path_config_value = GitService.get_git_config_value(GitConfigKeysEnum.hookPath.value)
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/services/git_service.py", line 111, in get_git_config_value
    return execute_cli_command(['git', 'config', '--get', key]).stdout.strip()
  File "/Users/ming1in/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ai_commit_msg/utils/utils.py", line 24, in execute_cli_command
    raise Exception(error_msg)
Exception: 🚨 Total failure to call: git config --get core.hooksPath

Test Plan

Build and install the latest change

> pip install . && pre-commit install && pre-commit autoupdate

Run this command in a repo without husky installed

> gac hook --setup