Files
git-commit-ai/git_commit_ai/core/git_handler.py
7000pctAUTO 14e1132daf
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
fix: resolve CI build failures
2026-01-31 04:00:16 +00:00

21 lines
806 B
Python

import subprocess
from git import Repo, GitCommandError
def get_staged_changes():
"""Get staged changes from git."""
try:
repo = Repo('.')
staged = repo.index.diff('HEAD')
return [item.a_path for item in staged]
except (GitCommandError, ValueError):
diff = subprocess.run(['git', 'diff', '--cached', '--name-only'], capture_output=True, text=True)
return diff.stdout.strip().split('\n') if diff.stdout.strip() else []
def get_commit_history(limit=5):
"""Get recent commit messages for context."""
try:
result = subprocess.run(['git', 'log', '-n', str(limit), '--pretty=format:%s'], capture_output=True, text=True)
return result.stdout.strip().split('\n') if result.stdout.strip() else []
except Exception:
return []