diff --git a/src/commands/push.rs b/src/commands/push.rs index a103ce3..1a489af 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -40,9 +40,11 @@ pub fn push() { let mut whitelist: Option = None; for obj in staged_objs { + dbg!(obj.clone()); if obj.otype == String::from("tree") { let push_factory = PushFactory.new_dir(obj.clone()); let res = push_factory.can_push(&mut whitelist); + dbg!(&res); match res { PushState::Valid => { match push_factory.push() { diff --git a/src/commands/push/push_factory.rs b/src/commands/push/push_factory.rs index 9765e15..8be4963 100644 --- a/src/commands/push/push_factory.rs +++ b/src/commands/push/push_factory.rs @@ -1,3 +1,4 @@ +use std::error::Error; use std::path::PathBuf; use std::io; use crate::commands::status::{State, LocalObj}; diff --git a/src/commands/status.rs b/src/commands/status.rs index aec850c..243d9c9 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -5,6 +5,7 @@ use crypto::sha1::Sha1; use colored::Colorize; use crate::utils::path::{self, path_buf_to_string}; use crate::store::object::blob::Blob; +use crate::store::object::object::Obj; use crate::store::object::tree::Tree; use crate::utils::read::read_folder; use crate::store::index; @@ -159,20 +160,15 @@ pub struct LocalObj { } pub fn get_all_staged() -> Vec { - let mut lines: Vec = vec![]; - - if let Ok(entries) = index::read_line() { - for entry in entries { - lines.push(entry.unwrap()); - } - } - let mut staged_objs = vec![]; - for line in lines { - let obj = Blob::from_path(line).get_local_obj(); - if obj.state != State::Default { - staged_objs.push(obj); + if let Ok(entries) = index::read_line() { + for line in entries { + + let obj = Obj::from_path(line.unwrap()).get_local_obj(); + if obj.state != State::Default { + staged_objs.push(obj); + } } } @@ -237,11 +233,11 @@ fn get_diff() -> (HashMap, HashMap, Vec = vec![]; let root = path::repo_root(); - + let current_p = path::current().unwrap(); // todo use repo_root instead of current let dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf(); - + read_tree_to_hashmap(&mut Tree::from_head(), &mut hashes, dist_path.clone()); //if let Ok(lines) = read_lines(head::path()) { // add_to_hashmap(lines, &mut hashes, dist_path.clone()); @@ -264,7 +260,7 @@ fn get_diff() -> (HashMap, HashMap, Vec (HashMap, HashMap, Vec { eprintln!("fatal: incorrect request"); @@ -199,7 +200,16 @@ impl ApiBuilder { } }, } - }).map_err(ApiError::RequestError)?; + }); + + // handle request error + let res = match res_req { + Err(err) => { + eprintln!("fatal: {}", err.source().unwrap()); + std::process::exit(1); + }, + Ok(res) => res, + }; if res.status().is_success() { if need_text { @@ -215,7 +225,7 @@ impl ApiBuilder { } } - pub async fn old_send(&mut self) -> Result { + pub async fn old_send(&mut self) -> Result { let mut request_manager = get_request_manager().lock().unwrap(); let request_manager = request_manager.as_mut().unwrap(); if !self.host.is_none() @@ -237,9 +247,9 @@ impl ApiBuilder { Some(req) => { if let Some(headers) = &self.headers { req.headers(headers.clone()) - .send().await.map_err(Error::from) + .send().await.map_err(reqwest::Error::from) } else { - req.send().await.map_err(Error::from) + req.send().await.map_err(reqwest::Error::from) } }, } diff --git a/src/store/object/object.rs b/src/store/object/object.rs index 1d37a93..c6e5391 100644 --- a/src/store/object/object.rs +++ b/src/store/object/object.rs @@ -6,6 +6,7 @@ use crate::store::head; use crate::store::object::{add_node, rm_node}; use crypto::sha1::Sha1; use crypto::digest::Digest; +use crate::utils::into::IntoPathBuf; use crate::store::object::{blob::Blob, tree::Tree}; use crate::commands::status::{State, LocalObj}; @@ -257,7 +258,8 @@ impl Obj { } } - pub fn from_path(path: PathBuf) -> Self { + pub fn from_path(path: S) -> Obj where S: IntoPathBuf { + let path = path.into(); let mut hasher = Sha1::new(); hasher.input_str(path.to_str().unwrap()); let hash = hasher.result_str(); @@ -287,6 +289,8 @@ impl Obj { hash_path: hash, } } + + /// load from the information line stored in the object pub fn from_line(line: String, base_dir: Option) -> Box { let mut split = line.rsplit(' '); if split.clone().count() != 3 {