From ed71b2d601cc1ac41874dd4bd61db25b10108006 Mon Sep 17 00:00:00 2001 From: Kent Krantz Date: Fri, 27 Nov 2020 13:14:06 +0800 Subject: [PATCH] Fixed bug of smoke_merge_file --- src/repo.rs | 74 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/repo.rs b/src/repo.rs index 0cc5f32a7c..49f8d0d90f 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -3424,6 +3424,8 @@ mod tests { assert!(index.has_conflicts(), "index should have conflicts"); + let mut conflict_count = 0; + let index_conflicts = index.conflicts().unwrap(); for conflict in index_conflicts { let conflict = conflict.unwrap(); @@ -3437,41 +3439,56 @@ mod tests { let theirs_blob; if let Some(ancestor) = conflict.ancestor { - ancestor_blob = repo - .find_blob(ancestor.id.clone()) - .expect("failed to find blob of index entry to make MergeFileInput"); - let ancestor_content = ancestor_blob.content(); - let mut input = MergeFileInput::new(); - input.path(String::from_utf8(ancestor.path).unwrap()); - input.mode(Some(FileMode::from(ancestor.mode.try_into().unwrap()))); - input.content(Some(&ancestor_content)); - ancestor_input = Some(input); + match repo.find_blob(ancestor.id.clone()) { + Ok(b) => { + ancestor_blob = b; + let ancestor_content = ancestor_blob.content(); + let mut input = MergeFileInput::new(); + input.path(String::from_utf8(ancestor.path).unwrap()); + input.mode(Some(FileMode::from(ancestor.mode.try_into().unwrap()))); + input.content(Some(&ancestor_content)); + ancestor_input = Some(input); + } + Err(_e) => { + ancestor_input = None; + } + } } else { ancestor_input = None; } if let Some(ours) = conflict.our { - ours_blob = repo - .find_blob(ours.id.clone()) - .expect("failed to find blob of index entry to make MergeFileInput"); - let ours_content = ours_blob.content(); - let mut input = MergeFileInput::new(); - input.path(String::from_utf8(ours.path).unwrap()); - input.mode(Some(FileMode::from(ours.mode.try_into().unwrap()))); - input.content(Some(&ours_content)); - ours_input = Some(input); + match repo.find_blob(ours.id.clone()) { + Ok(b) => { + ours_blob = b; + let ours_content = ours_blob.content(); + let mut input = MergeFileInput::new(); + input.path(String::from_utf8(ours.path).unwrap()); + input.mode(Some(FileMode::from(ours.mode.try_into().unwrap()))); + input.content(Some(&ours_content)); + ours_input = Some(input); + } + Err(_e) => { + ours_input = None; + } + } } else { ours_input = None; } if let Some(theirs) = conflict.their { - theirs_blob = repo - .find_blob(theirs.id.clone()) - .expect("failed to find blob of index entry to make MergeFileInput"); - let theirs_content = theirs_blob.content(); - let mut input = MergeFileInput::new(); - input.path(String::from_utf8(theirs.path).unwrap()); - input.mode(Some(FileMode::from(theirs.mode.try_into().unwrap()))); - input.content(Some(&theirs_content)); - theirs_input = Some(input); + match repo.find_blob(theirs.id.clone()) { + Ok(b) => { + theirs_blob = b; + let theirs_content = theirs_blob.content(); + let mut input = MergeFileInput::new(); + input.path(String::from_utf8(theirs.path).unwrap()); + input.mode(Some(FileMode::from(theirs.mode.try_into().unwrap()))); + input.content(Some(&theirs_content)); + theirs_input = Some(input); + } + Err(_e) => { + theirs_input = None; + } + } } else { theirs_input = None; } @@ -3498,7 +3515,10 @@ mod tests { }, merge_file_result_content ); + + conflict_count += 1; } + assert_eq!(conflict_count, 1, "There should be one conflict!"); } /// create the following: