fix: reject apply_diff when search matches replace content

Prevents attempting to apply diffs where search and replace content are identical,
which would result in no changes being made. Instead, provide a helpful error
message explaining why the operation was rejected.

Fixes: #1350

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-20 22:08:23 -07:00
parent 1b8bac66fd
commit c7321b0107

View file

@ -275,6 +275,19 @@ Only use a single line of '=======' between search and replacement content, beca
replaceContent = stripLineNumbers(replaceContent)
}
// Validate that search and replace content are not identical
if (searchContent === replaceContent) {
diffResults.push({
success: false,
error:
`Search and replace content are identical - no changes would be made\n\n` +
`Debug Info:\n` +
`- Search and replace must be different to make changes\n` +
`- Use read_file to verify the content you want to change`,
})
continue
}
// Split content into lines, handling both \n and \r\n
const searchLines = searchContent === "" ? [] : searchContent.split(/\r?\n/)
const replaceLines = replaceContent === "" ? [] : replaceContent.split(/\r?\n/)