diff --git a/src/commands/push.rs b/src/commands/push.rs index 6a7c84d..cee0e40 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -27,6 +27,12 @@ pub fn push() { let staged_objs = status::get_all_staged(); + // exit if there is nothing to push + if staged_objs.len() == 0 { + println!("Everything up-to-date"); + std::process::exit(0); + } + // path that certify that all its children can be push whithout hesistation // (e.g. if remote dir has no changes since last sync all children // can be pushed without verification) diff --git a/src/commands/remote_diff.rs b/src/commands/remote_diff.rs index aae905f..bf40b73 100644 --- a/src/commands/remote_diff.rs +++ b/src/commands/remote_diff.rs @@ -14,16 +14,16 @@ pub fn remote_diff() { let (folders, files) = get_diff(relative_p); for folder in folders { - println!("should pull {}", folder.clone().relative_s.unwrap()); + println!("should pull {}", folder.clone().relative_s.unwrap()); } for file in files { - println!("should pull {}", file.clone().relative_s.unwrap()); + println!("should pull {}", file.clone().relative_s.unwrap()); } } pub fn get_diff(path: PathBuf) -> (Vec, Vec) { - let depth = "2"; // todo + let depth = "2"; // todo opti let api_props = get_api_props(); enumerate_remote( diff --git a/src/commands/status.rs b/src/commands/status.rs index e218c15..c6fe93b 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -145,7 +145,7 @@ pub fn get_all_staged() -> Vec { let mut staged_objs = vec![]; for line in lines { - let obj = Blob::new(PathBuf::from(line)).get_local_obj(); + let obj = Blob::new(line).get_local_obj(); if obj.state != State::Default { staged_objs.push(obj); } diff --git a/src/store/object/blob.rs b/src/store/object/blob.rs index 8b69a56..966ea93 100644 --- a/src/store/object/blob.rs +++ b/src/store/object/blob.rs @@ -7,6 +7,7 @@ use std::time::SystemTime; use crypto::sha1::Sha1; use crypto::digest::Digest; use crate::commands::status::{LocalObj, State}; +use crate::utils::into::IntoPathBuf; use crate::utils::path::path_buf_to_string; use crate::utils::{path, read}; use crate::store::head; @@ -24,7 +25,8 @@ pub struct Blob { } impl Blob { - pub fn new(r_path: PathBuf) -> Blob { + pub fn new(r_path: S) -> Blob where S: IntoPathBuf { + let r_path = r_path.into(); let mut hasher = Sha1::new(); hasher.input_str(r_path.to_str().unwrap()); let hash = hasher.result_str(); @@ -351,7 +353,7 @@ impl Blob { } else if !has_obj_ref && blob_exists { let identical_blobs = self.get_all_identical_blobs(); if identical_blobs.len() != 0 { - let identical_blob = Blob::new(identical_blobs[0].clone().into()) + let identical_blob = Blob::new(identical_blobs[0].clone()) .get_local_obj(); if identical_blob.state == State::Deleted { path_from = Some(identical_blob.path); diff --git a/src/utils.rs b/src/utils.rs index 1d32f8e..64d4b34 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,3 +4,4 @@ pub mod nextsyncignore; pub mod api; pub mod time; pub mod remote; +pub mod into; diff --git a/src/utils/into.rs b/src/utils/into.rs new file mode 100644 index 0000000..98a0076 --- /dev/null +++ b/src/utils/into.rs @@ -0,0 +1,18 @@ +use std::path::PathBuf; + +pub trait IntoPathBuf { + fn into(self) -> PathBuf; +} + +impl IntoPathBuf for PathBuf { + fn into(self) -> PathBuf { + self + } +} + +impl IntoPathBuf for String { + fn into(self) -> PathBuf { + PathBuf::from(self) + } +} +