fix: preserve agentic branch when intermediate commits exist
_finalize_worktree was returning None and deleting the branch when the final commit was empty, even though _commit_iteration had already committed changes during the pipeline. Now checks git log for any commits on the branch before deciding to clean up. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -263,8 +263,6 @@ def _finalize_worktree(
|
||||
)
|
||||
if committed:
|
||||
logger.info(" Agentic changes committed on branch: %s", branch_name)
|
||||
else:
|
||||
logger.warning(" No agentic changes to commit (empty diff)")
|
||||
except Exception:
|
||||
logger.warning(" Failed to commit agentic changes", exc_info=True)
|
||||
|
||||
@@ -273,16 +271,25 @@ def _finalize_worktree(
|
||||
except Exception:
|
||||
logger.warning("Failed to clean up worktree: %s", worktree_path)
|
||||
|
||||
# Check if branch has any commits beyond the base — if not, delete it
|
||||
if not committed:
|
||||
# Check if branch has any commits beyond the base (including intermediate
|
||||
# commits from _commit_iteration, not just the final commit).
|
||||
has_branch_commits = False
|
||||
try:
|
||||
# Check if branch has diverged from its base
|
||||
result = subprocess.run(
|
||||
["git", "log", "--oneline", f"HEAD..{branch_name}"],
|
||||
cwd=cwd, capture_output=True, text=True,
|
||||
)
|
||||
if not result.stdout.strip():
|
||||
# No commits on branch beyond base — clean up
|
||||
has_branch_commits = bool(result.stdout.strip())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if has_branch_commits:
|
||||
if not committed:
|
||||
logger.info(" Agentic changes on branch: %s (from intermediate commits)", branch_name)
|
||||
return branch_name
|
||||
|
||||
# No commits on branch at all — clean up
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "branch", "-D", branch_name],
|
||||
cwd=cwd, capture_output=True,
|
||||
@@ -291,7 +298,9 @@ def _finalize_worktree(
|
||||
except Exception:
|
||||
pass # best-effort cleanup
|
||||
|
||||
return branch_name if committed else None
|
||||
if not committed:
|
||||
logger.warning(" No agentic changes to commit (empty diff)")
|
||||
return None
|
||||
|
||||
|
||||
def _run_simple_pipeline(
|
||||
|
||||
@@ -71,8 +71,11 @@ class BuiltinAgentConfigTest(unittest.TestCase):
|
||||
|
||||
self.assertIn("--dangerously-skip-permissions", coder_args)
|
||||
self.assertIn("bypassPermissions", coder_args)
|
||||
self.assertIn("plan", reviewer_args)
|
||||
self.assertIn("plan", senior_args)
|
||||
# Reviewers/seniors use -p without --permission-mode plan
|
||||
self.assertIn("-p", reviewer_args)
|
||||
self.assertIn("-p", senior_args)
|
||||
self.assertNotIn("plan", reviewer_args)
|
||||
self.assertNotIn("plan", senior_args)
|
||||
|
||||
def test_codex_builtin_agents_skip_git_repo_check(self) -> None:
|
||||
for agent_name in ("codex-coder", "codex-reviewer", "codex-senior"):
|
||||
|
||||
Reference in New Issue
Block a user