Initial upload: Git AI Documentation Generator v0.1.0
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
59
src/commands/commit.py
Normal file
59
src/commands/commit.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"""Commit message generation command."""
|
||||||
|
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from src.config import Config
|
||||||
|
from src.git_utils import NotGitRepositoryError, get_repo, get_staged_diff, get_unstaged_diff
|
||||||
|
from src.ollama_client import OllamaClient, OllamaConnectionError
|
||||||
|
from src.output import (
|
||||||
|
console,
|
||||||
|
display_commit_message,
|
||||||
|
display_error,
|
||||||
|
display_info,
|
||||||
|
display_model_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("--staged/--all", default=True, help="Use staged changes (default) or all changes")
|
||||||
|
@click.option("--language", "-l", help="Programming language context (for better prompts)")
|
||||||
|
@click.pass_context
|
||||||
|
def commit(ctx: click.Context, staged: bool, language: str | None) -> None:
|
||||||
|
"""Generate a commit message from git changes."""
|
||||||
|
config: Config = ctx.obj["config"]
|
||||||
|
client = OllamaClient(config)
|
||||||
|
|
||||||
|
try:
|
||||||
|
display_info("Connecting to Ollama...")
|
||||||
|
client.connect_with_retry()
|
||||||
|
display_model_info(config.ollama_host, config.model)
|
||||||
|
except OllamaConnectionError as e:
|
||||||
|
display_error(str(e))
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
repo = get_repo()
|
||||||
|
except NotGitRepositoryError:
|
||||||
|
display_error("Current directory is not a git repository")
|
||||||
|
return
|
||||||
|
|
||||||
|
with console.status("Analyzing changes..."):
|
||||||
|
if staged:
|
||||||
|
diff_content = get_staged_diff(repo)
|
||||||
|
if not diff_content.strip():
|
||||||
|
display_info("No staged changes found. Stage your changes with 'git add' first.")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
changes = get_staged_diff(repo) + get_unstaged_diff(repo)
|
||||||
|
diff_content = changes
|
||||||
|
if not diff_content.strip():
|
||||||
|
display_info("No changes found")
|
||||||
|
return
|
||||||
|
|
||||||
|
with console.status("Generating commit message..."):
|
||||||
|
try:
|
||||||
|
message = client.generate_commit_message(diff_content, language=language)
|
||||||
|
display_commit_message(message, config.model)
|
||||||
|
except OllamaConnectionError as e:
|
||||||
|
display_error(str(e))
|
||||||
Reference in New Issue
Block a user