diff --git a/src/auto_commit_service/scheduler/__pycache__/daemon.cpython-312.pyc b/src/auto_commit_service/scheduler/__pycache__/daemon.cpython-312.pyc index f114649..354ee05 100644 Binary files a/src/auto_commit_service/scheduler/__pycache__/daemon.cpython-312.pyc and b/src/auto_commit_service/scheduler/__pycache__/daemon.cpython-312.pyc differ diff --git a/src/auto_commit_service/scheduler/__pycache__/processor.cpython-312.pyc b/src/auto_commit_service/scheduler/__pycache__/processor.cpython-312.pyc index 93302e3..b51554a 100644 Binary files a/src/auto_commit_service/scheduler/__pycache__/processor.cpython-312.pyc and b/src/auto_commit_service/scheduler/__pycache__/processor.cpython-312.pyc differ diff --git a/src/auto_commit_service/scheduler/daemon.py b/src/auto_commit_service/scheduler/daemon.py index 66e3d0b..1f28de6 100644 --- a/src/auto_commit_service/scheduler/daemon.py +++ b/src/auto_commit_service/scheduler/daemon.py @@ -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") diff --git a/src/auto_commit_service/scheduler/processor.py b/src/auto_commit_service/scheduler/processor.py index c8e51f3..e1153f1 100644 --- a/src/auto_commit_service/scheduler/processor.py +++ b/src/auto_commit_service/scheduler/processor.py @@ -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: