fix(auto-commit-service): 🛠 resolve git status handling in daemon.py

This commit is contained in:
Lilith 2026-01-09 22:37:39 -08:00
parent 006ec0c8d0
commit fa3a4ffeb2
4 changed files with 38 additions and 8 deletions

View file

@ -10,7 +10,7 @@ from typing import Any
from ..commit_history import CommitHistory
from ..config import AutoCommitSettings
from ..git import Repository, discover_git_repos
from ..git import Repository, discover_git_repos, git_status
from ..llm import LlamaCommitClient
from ..models import CycleResult, ProcessStatus, RepoProcessResult
from ..recovery import ErrorHandler
@ -546,12 +546,39 @@ class CommitDaemon:
logger.info("Daemon stopped, aborting cycle")
break
# Get status first to know the branch and if we need to push
try:
status = await git_status(repo.path)
except Exception as e:
logger.error(f"[{cycle_id}] {repo.name}: Failed to get status - {e}")
results.append(RepoProcessResult(
repo_name=repo.name,
status=ProcessStatus.ERROR,
error=f"Failed to get git status: {e}",
))
continue
# Step 1: Commit
result = await self.processor.commit_repo(repo)
if result.status == ProcessStatus.NO_CHANGES:
logger.debug(f"[{cycle_id}] {repo.name}: No changes")
results.append(result)
# Check if we still need to push unpushed commits
if status.ahead > 0:
logger.info(f"[{cycle_id}] {repo.name}: No new changes, but {status.ahead} commits to push")
# Create a synthetic COMMITTED result for push
push_result = await self.processor.push_repo(
repo,
RepoProcessResult(repo_name=repo.name, status=ProcessStatus.COMMITTED),
branch=status.branch,
)
if push_result.status == ProcessStatus.SUCCESS:
logger.info(f"[{cycle_id}] {repo.name}: Pushed {status.ahead} commits successfully")
elif push_result.status == ProcessStatus.ERROR:
logger.error(f"[{cycle_id}] {repo.name}: Push failed - {push_result.error}")
results.append(push_result)
else:
logger.debug(f"[{cycle_id}] {repo.name}: No changes")
results.append(result)
continue
if result.status == ProcessStatus.ERROR:
@ -562,7 +589,7 @@ class CommitDaemon:
# Step 2: Push (only if committed)
if result.status == ProcessStatus.COMMITTED:
logger.info(f"[{cycle_id}] {repo.name}: Committed {result.commit_hash}, pushing...")
result = await self.processor.push_repo(repo, result)
result = await self.processor.push_repo(repo, result, branch=status.branch)
if result.status == ProcessStatus.SUCCESS:
logger.info(f"[{cycle_id}] {repo.name}: Pushed successfully")

View file

@ -208,6 +208,7 @@ class CommitProcessor:
self,
repo: Repository,
result: RepoProcessResult,
branch: str,
max_retries: int = 3,
) -> RepoProcessResult:
"""Push a committed repo to remote with retry logic.
@ -215,6 +216,7 @@ class CommitProcessor:
Args:
repo: Repository to push
result: The commit result to update
branch: The actual branch to push (from git_status)
max_retries: Maximum number of push attempts (default 3)
Returns:
@ -233,13 +235,13 @@ class CommitProcessor:
await git_pull_rebase(
repo.path,
remote=self.settings.git_remote,
branch=self.settings.git_branch,
branch=branch,
)
push_result = await git_push(
repo.path,
remote=self.settings.git_remote,
branch=self.settings.git_branch,
branch=branch,
)
if not push_result.success:
@ -298,6 +300,7 @@ class CommitProcessor:
self,
repo: Repository,
result: RepoProcessResult,
branch: str,
) -> RepoProcessResult:
"""Handle push rejection by rebasing and retrying."""
try:
@ -305,14 +308,14 @@ class CommitProcessor:
await git_pull_rebase(
repo.path,
remote=self.settings.git_remote,
branch=self.settings.git_branch,
branch=branch,
)
# Retry push
push_result = await git_push(
repo.path,
remote=self.settings.git_remote,
branch=self.settings.git_branch,
branch=branch,
)
if push_result.success: