From 7f334656b1d45a78c98cd451ce8f740085aec59b Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 17 Feb 2023 09:02:48 -0800 Subject: [PATCH] tree: return early when trying to resolve modify/delete conflict Modify/delete conflicts cannot be automatically resolved, so there's no point in wasting resources calculating the diff(s). --- lib/src/tree.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/tree.rs b/lib/src/tree.rs index 78370fbbb..2760e578f 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -653,6 +653,12 @@ fn try_resolve_file_conflict( filename: &RepoPath, conflict: &Conflict, ) -> Result, bool)>, TreeMergeError> { + // If the file was missing from any side (typically a modify/delete conflict), + // we can't automatically merge it. + if conflict.adds.len() != conflict.removes.len() + 1 { + return Ok(None); + } + // If there are any non-file parts in the conflict, we can't merge it. We check // early so we don't waste time reading file contents if we can't merge them // anyway. At the same time we determine whether the resulting file should