diff --git a/src/commands/push.rs b/src/commands/push.rs index 1a489af..dc60572 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -15,7 +15,6 @@ pub mod moved; pub mod copied; pub fn push() { - // todo err when pushing new folder let _remote = match config::get_remote("origin") { Some(r) => r, None => { diff --git a/src/commands/push/new_dir.rs b/src/commands/push/new_dir.rs index 16cf637..39d156b 100644 --- a/src/commands/push/new_dir.rs +++ b/src/commands/push/new_dir.rs @@ -31,7 +31,6 @@ impl PushChange for NewDir { } fn push(&self) -> io::Result<()> { - dbg!("pushing new dir"); let obj = &self.obj; let res = CreateFolder::new() .set_url(obj.path.to_str().unwrap()) diff --git a/src/commands/status.rs b/src/commands/status.rs index 243d9c9..d9cae49 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -361,7 +361,7 @@ fn print_status(staged_objs: Vec, objs: Vec) { // not staged files if objs.len() != 0 { println!("Changes not staged for push:"); - println!(" (Use\"nextsync add ...\" to update what will be pushed)"); + println!(" (Use \"nextsync add ...\" to update what will be pushed)"); for object in objs { print_object(object); diff --git a/src/store/object/blob.rs b/src/store/object/blob.rs index ecd84ae..9593fb9 100644 --- a/src/store/object/blob.rs +++ b/src/store/object/blob.rs @@ -265,7 +265,7 @@ impl Blob { pub fn create(&mut self, ts_remote: &str, up_parent: bool) -> io::Result<()> { // add blob reference to parent - self.add_ref_to_parent(); + let _ = self.add_ref_to_parent(); if let Err(err) = self.create_blob_ref(ts_remote.clone()) { eprintln!("err: saving blob ref of {}: {}", self.get_relative_file_path().display(), err); diff --git a/src/store/object/object.rs b/src/store/object/object.rs index c7b20eb..e2c0012 100644 --- a/src/store/object/object.rs +++ b/src/store/object/object.rs @@ -11,7 +11,7 @@ use crate::store::object::{blob::Blob, tree::Tree}; use crate::commands::status::{State, LocalObj}; #[derive(Clone, Copy)] -enum ObjType { +pub enum ObjType { TREE, BLOB, DEFAULT diff --git a/src/store/object/tree.rs b/src/store/object/tree.rs index 5cb5782..db36f78 100644 --- a/src/store/object/tree.rs +++ b/src/store/object/tree.rs @@ -1,6 +1,7 @@ use crate::utils::into::IntoPathBuf; use crate::store::object::object::Obj; use std::path::PathBuf; +use crate::store::object::update_dates; use crate::store::object::object::ObjMethods; use std::fs::{self, File, OpenOptions}; use std::io::{self, BufRead, BufReader, Write, Lines}; @@ -80,18 +81,32 @@ impl Tree { pub fn create(&self, date: &str, up_parent: bool) -> io::Result<()> { // add tree reference to parent - self.add_ref_to_parent(); + let _ = self.add_ref_to_parent(); // create tree object - let mut content = format!("{} {}", self.get_name(), date); - //create_obj(self.get_hash_path(), &content)?; - // todo!(); + let content = format!("{} {}", self.get_name(), date); + + // create parent dir if needed + let mut obj_path = self.get_obj_path(); + obj_path.pop(); + if !obj_path.exists() { + fs::create_dir_all(obj_path)?; + } + + // open ref file + let mut file = OpenOptions::new() + .create_new(true) + .write(true) + .open(self.get_obj_path())?; // update date for all parent - //todo!(); - //if up_parent { - // update_dates(path, date)?; - //} + if up_parent { + if let Err(err) = update_dates(self.get_relative_file_path(), date) { + eprintln!("err: updating parent date of {}: {}", self.get_relative_file_path().display(), err); + } + } + + writeln!(file, "{}", content)?; Ok(()) } diff --git a/tests/push.rs b/tests/push.rs index 926bc71..16536c5 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -128,6 +128,9 @@ mod push_tests { // tests assert!(server.has_file("file1", "foo")); assert!(server.has_file("dir/file2", "bar")); + let (staged, not_staged) = client.get_status(); + assert!(staged.len() == 0); + assert!(not_staged.len() == 0); client.clean(); server.clean();