Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-vcs/src/git/test.rs')
| -rw-r--r-- | helix-vcs/src/git/test.rs | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/helix-vcs/src/git/test.rs b/helix-vcs/src/git/test.rs index 164040f5..9c67d2c3 100644 --- a/helix-vcs/src/git/test.rs +++ b/helix-vcs/src/git/test.rs @@ -2,7 +2,7 @@ use std::{fs::File, io::Write, path::Path, process::Command}; use tempfile::TempDir; -use crate::git; +use crate::{DiffProvider, Git}; fn exec_git_cmd(args: &str, git_dir: &Path) { let res = Command::new("git") @@ -54,7 +54,7 @@ fn missing_file() { let file = temp_git.path().join("file.txt"); File::create(&file).unwrap().write_all(b"foo").unwrap(); - assert!(git::get_diff_base(&file).is_err()); + assert!(Git.get_diff_base(&file).is_err()); } #[test] @@ -64,7 +64,7 @@ fn unmodified_file() { let contents = b"foo".as_slice(); File::create(&file).unwrap().write_all(contents).unwrap(); create_commit(temp_git.path(), true); - assert_eq!(git::get_diff_base(&file).unwrap(), Vec::from(contents)); + assert_eq!(Git.get_diff_base(&file).unwrap(), Vec::from(contents)); } #[test] @@ -76,7 +76,7 @@ fn modified_file() { create_commit(temp_git.path(), true); File::create(&file).unwrap().write_all(b"bar").unwrap(); - assert_eq!(git::get_diff_base(&file).unwrap(), Vec::from(contents)); + assert_eq!(Git.get_diff_base(&file).unwrap(), Vec::from(contents)); } /// Test that `get_file_head` does not return content for a directory. @@ -95,16 +95,12 @@ fn directory() { std::fs::remove_dir_all(&dir).unwrap(); File::create(&dir).unwrap().write_all(b"bar").unwrap(); - assert!(git::get_diff_base(&dir).is_err()); + assert!(Git.get_diff_base(&dir).is_err()); } -/// Test that `get_diff_base` resolves symlinks so that the same diff base is -/// used as the target file. -/// -/// This is important to correctly cover cases where a symlink is removed and -/// replaced by a file. If the contents of the symlink object were returned -/// a diff between a literal file path and the actual file content would be -/// produced (bad ui). +/// Test that `get_file_head` does not return content for a symlink. +/// This is important to correctly cover cases where a symlink is removed and replaced by a file. +/// If the contents of the symlink object were returned a diff between a path and the actual file would be produced (bad ui). #[cfg(any(unix, windows))] #[test] fn symlink() { @@ -112,41 +108,14 @@ fn symlink() { use std::os::unix::fs::symlink; #[cfg(not(unix))] use std::os::windows::fs::symlink_file as symlink; - let temp_git = empty_git_repo(); let file = temp_git.path().join("file.txt"); - let contents = Vec::from(b"foo"); - File::create(&file).unwrap().write_all(&contents).unwrap(); + let contents = b"foo".as_slice(); + File::create(&file).unwrap().write_all(contents).unwrap(); let file_link = temp_git.path().join("file_link.txt"); - symlink("file.txt", &file_link).unwrap(); - create_commit(temp_git.path(), true); - assert_eq!(git::get_diff_base(&file_link).unwrap(), contents); - assert_eq!(git::get_diff_base(&file).unwrap(), contents); -} - -/// Test that `get_diff_base` returns content when the file is a symlink to -/// another file that is in a git repo, but the symlink itself is not. -#[cfg(any(unix, windows))] -#[test] -fn symlink_to_git_repo() { - #[cfg(unix)] - use std::os::unix::fs::symlink; - #[cfg(not(unix))] - use std::os::windows::fs::symlink_file as symlink; - - let temp_dir = tempfile::tempdir().expect("create temp dir"); - let temp_git = empty_git_repo(); - - let file = temp_git.path().join("file.txt"); - let contents = Vec::from(b"foo"); - File::create(&file).unwrap().write_all(&contents).unwrap(); create_commit(temp_git.path(), true); - - let file_link = temp_dir.path().join("file_link.txt"); - symlink(&file, &file_link).unwrap(); - - assert_eq!(git::get_diff_base(&file_link).unwrap(), contents); - assert_eq!(git::get_diff_base(&file).unwrap(), contents); + assert!(Git.get_diff_base(&file_link).is_err()); + assert_eq!(Git.get_diff_base(&file).unwrap(), Vec::from(contents)); } |