Skip to content

Commit

Permalink
Fix TestFilesystem::read_dir_diff_paths
Browse files Browse the repository at this point in the history
This function collects the files present in the `left` and `right` directories.
It should return the path suffix with the `left` and `right` prefix stripped.
This is necessary because `process_opts` will add the `left` and `right` prefix
back to the paths returned by `read_dir_diff_paths`. If we don't strip the
prefix, we will end up with invalid paths where the prefix is duplicated.

This went unnoticed since the current tests don't diff directories. I will add
a test that diffs directories in a subsequent commit.
  • Loading branch information
emesterhazy authored and arxanas committed May 11, 2024
1 parent 473eb23 commit ba2744d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/scm_diff_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,11 +1088,17 @@ mod tests {

impl Filesystem for TestFilesystem {
fn read_dir_diff_paths(&self, left: &Path, right: &Path) -> Result<BTreeSet<PathBuf>> {
Ok(self
let left_files = self
.files
.keys()
.filter(|path| path.starts_with(left) || path.starts_with(right))
.cloned()
.filter_map(|path| path.strip_prefix(left).ok());
let right_files = self
.files
.keys()
.filter_map(|path| path.strip_prefix(right).ok());
Ok(left_files
.chain(right_files)
.map(|path| path.to_path_buf())
.collect())
}

Expand Down

0 comments on commit ba2744d

Please sign in to comment.