Skip to content

Commit a776594

Browse files
committed
Fix: use original file path for context in semantic diff generation
Adjust diff generation to correctly handle renamed or deleted files. - Introduce `single` as the first file chunk to inspect rename/deletion flags. - Compute `context_file_path` using the old file path when the chunk represents a rename or deletion, otherwise fall back to the current path. - Ensure `context_file_path` defaults to `file_path` if it is `None`. - Retrieve old file lines with `_get_file_lines(context_file_path, base_hash)` instead of always using `file_path`.
1 parent a473949 commit a776594

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/codestory/core/diff/patch/semantic_patch_generator.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ def _generate_diff(
108108
patches[file_path] = ("\n".join(out_lines) + "\n").encode("utf-8")
109109
continue
110110

111-
old_file_lines = self._get_file_lines(file_path, base_hash)
111+
single = file_chunks[0]
112+
# Use old path for context when the base file lives at the old name
113+
# (renames or deletions). Otherwise use the canonical path.
114+
context_file_path = (
115+
single.old_file_path
116+
if (single.is_file_rename or single.is_file_deletion)
117+
else file_path
118+
)
119+
if context_file_path is None:
120+
context_file_path = file_path
121+
122+
old_file_lines = self._get_file_lines(context_file_path, base_hash)
112123
sorted_file_chunks = sorted(file_chunks, key=lambda c: c.get_sort_key())
113124

114125
last_line_emitted = 0

0 commit comments

Comments
 (0)