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:
이충영 에이닷서비스개발
2026-03-14 20:48:25 +09:00
parent 0858675076
commit af05fc1ddb
2 changed files with 34 additions and 22 deletions

View File

@@ -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,25 +271,36 @@ 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:
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
subprocess.run(
["git", "branch", "-D", branch_name],
cwd=cwd, capture_output=True,
)
logger.info(" Deleted empty branch: %s", branch_name)
except Exception:
pass # best-effort cleanup
# 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:
result = subprocess.run(
["git", "log", "--oneline", f"HEAD..{branch_name}"],
cwd=cwd, capture_output=True, text=True,
)
has_branch_commits = bool(result.stdout.strip())
except Exception:
pass
return branch_name if committed else None
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,
)
logger.info(" Deleted empty branch: %s", branch_name)
except Exception:
pass # best-effort cleanup
if not committed:
logger.warning(" No agentic changes to commit (empty diff)")
return None
def _run_simple_pipeline(