Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/git/internal/object/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//!

use std::fmt::Display;
use std::path::PathBuf;
use std::str;

use crate::git::errors::GitError;
Expand Down Expand Up @@ -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<String, GitError> {
pub fn write_to_file(&self, path: &str) -> Result<PathBuf, GitError> {
self.meta.write_to_file(path)
}

Expand Down Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions src/git/internal/object/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//!
//!
use std::fmt::Display;
use std::path::PathBuf;

use bstr::ByteSlice;

Expand Down Expand Up @@ -121,7 +122,7 @@ impl Commit {
}

#[allow(unused)]
pub fn write_to_file(&self, path: &str) -> Result<String, GitError> {
pub fn write_to_file(&self, path: &str) -> Result<PathBuf, GitError> {
self.meta.write_to_file(path)
}
}
Expand Down Expand Up @@ -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());
}
}
8 changes: 3 additions & 5 deletions src/git/internal/object/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, GitError> {
pub fn write_to_file(&self, root: &str) -> Result<PathBuf, GitError> {
// 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);

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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());
}
}
7 changes: 4 additions & 3 deletions src/git/internal/object/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -307,7 +308,7 @@ impl Tree {

/// Write to a file with path
#[allow(unused)]
pub fn write_to_file(&self, path: &str) -> Result<String, GitError> {
pub fn write_to_file(&self, path: &str) -> Result<PathBuf, GitError> {
self.meta.write_to_file(path)
}
}
Expand Down Expand Up @@ -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]
Expand Down