Better handling of lock files during merge conflicts

This commit is contained in:
AndyMik90
2025-12-16 23:50:56 +01:00
parent 4eb66f5004
commit 460c76de42
+19 -13
View File
@@ -688,6 +688,7 @@ def _resolve_git_conflicts_with_ai(
simple_merges: list[ simple_merges: list[
tuple[str, str | None] tuple[str, str | None]
] = [] # (file_path, merged_content or None for delete) ] = [] # (file_path, merged_content or None for delete)
lock_files_excluded: list[str] = [] # Lock files excluded from merge
debug(MODULE, "Categorizing conflicting files for parallel processing") debug(MODULE, "Categorizing conflicting files for parallel processing")
@@ -727,10 +728,11 @@ def _resolve_git_conflicts_with_ai(
else: else:
# File exists in both - check if it's a lock file # File exists in both - check if it's a lock file
if _is_lock_file(file_path): if _is_lock_file(file_path):
# Lock files should never go through AI - just take worktree version # Lock files should be excluded from merge entirely
# User can run package manager install to regenerate if needed # They must be regenerated after merge by running the package manager
simple_merges.append((file_path, worktree_content)) # (e.g., npm install, pnpm install, uv sync, cargo update)
debug(MODULE, f" {file_path}: lock file (taking worktree version)") lock_files_excluded.append(file_path)
debug(MODULE, f" {file_path}: lock file (excluded - regenerate after merge)")
else: else:
# Regular file - needs AI merge # Regular file - needs AI merge
files_needing_ai_merge.append( files_needing_ai_merge.append(
@@ -767,15 +769,7 @@ def _resolve_git_conflicts_with_ai(
["git", "add", file_path], cwd=project_dir, capture_output=True ["git", "add", file_path], cwd=project_dir, capture_output=True
) )
resolved_files.append(file_path) resolved_files.append(file_path)
# Determine the type for display print(success(f"{file_path} (new file)"))
if _is_lock_file(file_path):
print(
success(
f"{file_path} (lock file - took worktree version)"
)
)
else:
print(success(f"{file_path} (new file)"))
else: else:
# Delete the file # Delete the file
target_path = project_dir / file_path target_path = project_dir / file_path
@@ -911,6 +905,7 @@ def _resolve_git_conflicts_with_ai(
"ai_assisted": ai_merged_count, "ai_assisted": ai_merged_count,
"auto_merged": auto_merged_count, "auto_merged": auto_merged_count,
"parallel_ai_merges": len(files_needing_ai_merge), "parallel_ai_merges": len(files_needing_ai_merge),
"lock_files_excluded": len(lock_files_excluded),
}, },
} }
@@ -926,6 +921,17 @@ def _resolve_git_conflicts_with_ai(
print(muted(f" - {conflict['file']}: {conflict['reason']}")) print(muted(f" - {conflict['file']}: {conflict['reason']}"))
print(muted(" These files may need manual review.")) print(muted(" These files may need manual review."))
# Notify about excluded lock files that need regeneration
if lock_files_excluded:
result["lock_files_excluded"] = lock_files_excluded
print()
print(muted(f" {len(lock_files_excluded)} lock file(s) excluded from merge:"))
for lock_file in lock_files_excluded:
print(muted(f" - {lock_file}"))
print()
print(warning(" Run your package manager to regenerate lock files:"))
print(muted(" npm install / pnpm install / yarn / uv sync / cargo update"))
return result return result