-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix Merge With AI Bug - Execute Git Merge After Semantic Analysis #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
ed6a005
e74c53b
38b0f1d
544b241
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -743,20 +743,68 @@ def _try_smart_merge_inner( | |
| "preview": preview, | ||
| } | ||
|
|
||
| # All conflicts can be auto-merged or no conflicts | ||
| print(muted(" All changes compatible, proceeding with merge...")) | ||
| # All conflicts can be auto-merged or no conflicts - execute git merge | ||
| spec_branch = f"auto-claude/{spec_name}" | ||
| print(muted(f" All changes compatible, merging {spec_branch}...")) | ||
|
|
||
| # Build merge command with conditional --no-commit flag | ||
| merge_cmd = ["merge", "--no-ff", spec_branch] | ||
| if no_commit: | ||
| merge_cmd.insert(1, "--no-commit") | ||
|
|
||
| # Execute git merge | ||
| merge_result = run_git( | ||
| merge_cmd, | ||
| cwd=project_dir, | ||
| ) | ||
|
|
||
| if merge_result.returncode != 0: | ||
| if "already up to date" in merge_result.stdout.lower(): | ||
| # Already up to date - treat as success | ||
| if progress_callback is not None: | ||
| progress_callback( | ||
| MergeProgressStage.COMPLETE, | ||
| 100, | ||
| "Merge complete (already up to date)", | ||
| ) | ||
| return { | ||
| "success": True, | ||
| "resolved_files": [], | ||
| "stats": { | ||
| "git_merge": True, | ||
| "files_merged": 0, | ||
| "auto_resolved": 0, | ||
| }, | ||
| } | ||
| else: | ||
| # Merge failed - abort to restore clean state and raise error | ||
| run_git(["merge", "--abort"], cwd=project_dir) | ||
| raise Exception(f"Git merge failed: {merge_result.stderr}") | ||
|
|
||
| # Get list of files that were actually merged | ||
| diff_result = run_git( | ||
| ["diff", "--cached", "--name-only"], | ||
| cwd=project_dir, | ||
| ) | ||
| merged_files = [ | ||
|
Comment on lines
+801
to
+804
This comment was marked as outdated.
Sorry, something went wrong. |
||
| f.strip() | ||
| for f in diff_result.stdout.splitlines() | ||
| if f.strip() and not _is_auto_claude_file(f.strip()) | ||
| ] | ||
|
|
||
| if progress_callback is not None: | ||
| progress_callback( | ||
| MergeProgressStage.COMPLETE, | ||
| 100, | ||
| f"Analysis complete ({files_to_merge} files compatible)", | ||
| f"Merge complete ({len(merged_files)} files merged)", | ||
| ) | ||
|
|
||
| return { | ||
| "success": True, | ||
| "resolved_files": merged_files, | ||
| "stats": { | ||
| "files_merged": files_to_merge, | ||
| "git_merge": True, | ||
| "files_merged": len(merged_files), | ||
| "auto_resolved": auto_mergeable, | ||
| }, | ||
|
Comment on lines
+836
to
839
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: A failed git commit is not propagated as an error, causing the function to return a success status while files remain staged but uncommitted. Suggested FixAfter the Prompt for AI Agent |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better error handling and maintainability, it's recommended to raise a more specific exception than the base
Exception. UsingRuntimeErroror a custom exception class (e.g.,GitMergeError) would allow upstream callers to catch this specific failure more granularly.