Reject duplicate resolved paths in apply_patch (#37867)

## What changed

- Reject patches containing multiple operations whose paths resolve to the same file, such as `duplicate.txt` and `./duplicate.txt`.
- Preserve support for patches that update multiple distinct files.

## Testing

- Add CLI integration coverage for distinct updates and duplicate resolved paths.

GitOrigin-RevId: 0fb7f69ae31acc5c677268ffd9e38ad8d8314276
This commit is contained in:
viyatb-oai
2026-08-10 18:44:58 +00:00
committed by copyberry
parent dd22460869
commit a1c88e865d
2 changed files with 61 additions and 0 deletions
+7
View File
@@ -232,6 +232,13 @@ async fn try_verify_apply_patch_args(
let mut changes = HashMap::new();
for hunk in hunks {
let path = hunk.resolve_path(&effective_cwd)?;
if changes.contains_key(&path) {
return Err(ParseError::InvalidPatchError(format!(
"multiple operations target {}",
path.inferred_native_path_string()
))
.into());
}
match hunk {
Hunk::AddFile { contents, .. } => {
changes.insert(path, ApplyPatchFileChange::Add { content: contents });