diff --git a/src/git/internal/object/blob.rs b/src/git/internal/object/blob.rs index ec6923607..4b65c9c88 100644 --- a/src/git/internal/object/blob.rs +++ b/src/git/internal/object/blob.rs @@ -29,6 +29,7 @@ //! use std::fmt::Display; +use std::path::PathBuf; use std::str; use crate::git::errors::GitError; @@ -92,7 +93,7 @@ impl Blob { /// Write the Blob object to a file with the given root path. /// The file path is the root path + ID[..2] + ID[2..] #[allow(unused)] - pub fn write_to_file(&self, path: &str) -> Result { + pub fn write_to_file(&self, path: &str) -> Result { self.meta.write_to_file(path) } @@ -174,7 +175,8 @@ mod tests { dest.push("8a"); dest.push("b686eafeb1f44702738c8b0f24f2567c36da6d"); - assert_eq!(file, dest.as_path().to_str().unwrap()); + + assert_eq!(true, file.exists()); } #[test] diff --git a/src/git/internal/object/commit.rs b/src/git/internal/object/commit.rs index 5fcddc770..6854ba66b 100644 --- a/src/git/internal/object/commit.rs +++ b/src/git/internal/object/commit.rs @@ -4,6 +4,7 @@ //! //! use std::fmt::Display; +use std::path::PathBuf; use bstr::ByteSlice; @@ -121,7 +122,7 @@ impl Commit { } #[allow(unused)] - pub fn write_to_file(&self, path: &str) -> Result { + pub fn write_to_file(&self, path: &str) -> Result { self.meta.write_to_file(path) } } @@ -225,10 +226,11 @@ mod tests { } let mut dest = PathBuf::from(env::current_dir().unwrap()); - dest.push("tests/objects"); + dest = dest.join("tests"); + dest = dest.join("objects"); - let path = commit.write_to_file(dest.as_path().to_str().unwrap()).unwrap(); + let file = commit.write_to_file(dest.to_str().unwrap()).unwrap(); - assert_eq!(path, dest_file.as_path().to_str().unwrap()); + assert_eq!(true, file.exists()); } } \ No newline at end of file diff --git a/src/git/internal/object/meta.rs b/src/git/internal/object/meta.rs index 13162bb44..11807589e 100644 --- a/src/git/internal/object/meta.rs +++ b/src/git/internal/object/meta.rs @@ -115,7 +115,7 @@ impl Meta { /// TODO: Add a overwrite flag to control whether to overwrite the existing file. /// TODO: Add a file path parameter to control where to store the file without flow Git store spec. #[allow(unused)] - pub fn write_to_file(&self, root: &str) -> Result { + pub fn write_to_file(&self, root: &str) -> Result { // e is a ZlibEncoder, which is a wrapper around a Writer that compresses the data written to let mut e = ZlibEncoder::new(Vec::new(), Compression::Default); @@ -149,7 +149,7 @@ impl Meta { .with_context(|| format!("Failed to write to file: {}", path.display())) .unwrap(); - Ok(path.to_str().unwrap().to_string()) + Ok(path) } #[allow(unused)] @@ -288,8 +288,6 @@ mod tests { dest.push("tests/objects"); let file = m.write_to_file(dest.as_path().to_str().unwrap()).unwrap(); - dest.push("8a"); - dest.push("b686eafeb1f44702738c8b0f24f2567c36da6d"); - assert_eq!(file, dest.as_path().to_str().unwrap()); + assert_eq!(true, file.exists()); } } \ No newline at end of file diff --git a/src/git/internal/object/tree.rs b/src/git/internal/object/tree.rs index c785b975c..ebcc4a97e 100644 --- a/src/git/internal/object/tree.rs +++ b/src/git/internal/object/tree.rs @@ -15,6 +15,7 @@ //! operations like merging and rebasing more quickly and accurately. //! use std::fmt::Display; +use std::path::PathBuf; use bstr::ByteSlice; use colored::Colorize; @@ -307,7 +308,7 @@ impl Tree { /// Write to a file with path #[allow(unused)] - pub fn write_to_file(&self, path: &str) -> Result { + pub fn write_to_file(&self, path: &str) -> Result { self.meta.write_to_file(path) } } @@ -425,9 +426,9 @@ mod tests { let mut dest = PathBuf::from(env::current_dir().unwrap()); dest.push("tests/objects"); - let path = tree.write_to_file(dest.as_path().to_str().unwrap()).unwrap(); + let file = tree.write_to_file(dest.as_path().to_str().unwrap()).unwrap(); - assert_eq!(path, dest_file.as_path().to_str().unwrap()); + assert_eq!(true, file.exists()); } #[test]