fix(push): push deletion
This commit is contained in:
parent
e8c8ab9dfe
commit
4504b98112
@ -71,9 +71,10 @@ pub fn push() {
|
||||
},
|
||||
PushState::Done => remove_obj_from_index(obj.clone()),
|
||||
PushState::Conflict => {
|
||||
eprintln!("conflict when pushing blob");
|
||||
// download file
|
||||
}
|
||||
PushState::Error => (),
|
||||
PushState::Error => (eprintln!("error when pushing changes blob")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl PushChange for Deleted {
|
||||
|
||||
// update tree
|
||||
// todo date
|
||||
Blob::from_path(obj.path.clone()).rm()?;
|
||||
Blob::from_path(obj.path.clone()).rm_node()?;
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap())?;
|
||||
|
@ -160,19 +160,8 @@ pub struct LocalObj {
|
||||
}
|
||||
|
||||
pub fn get_all_staged() -> Vec<LocalObj> {
|
||||
let mut staged_objs = vec![];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
staged_objs
|
||||
let mut all_hashes = get_all_objs_hashes();
|
||||
get_staged(&mut all_hashes)
|
||||
}
|
||||
|
||||
fn get_staged(hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
||||
|
@ -26,7 +26,7 @@ pub trait ObjMethods {
|
||||
fn get_name(&self) -> String;
|
||||
fn get_hash_path(&self) -> String;
|
||||
fn get_local_obj(&self) -> LocalObj;
|
||||
fn get_line(&self) -> String;
|
||||
fn get_line(&self, obj_type: ObjType) -> String;
|
||||
fn add_ref_to_parent(&self) -> io::Result<()>;
|
||||
fn rm(&mut self) -> io::Result<()>;
|
||||
fn rm_node(&mut self) -> io::Result<()>;
|
||||
@ -89,12 +89,17 @@ impl ObjMethods for Obj {
|
||||
}
|
||||
|
||||
// build line for parent reference
|
||||
fn get_line(&self) -> String {
|
||||
format!("tree {} {}", self.get_hash_path(), self.get_name())
|
||||
fn get_line(&self, obj_type: ObjType) -> String {
|
||||
let type_str = match obj_type {
|
||||
ObjType::BLOB => "blob",
|
||||
ObjType::TREE => "tree",
|
||||
ObjType::DEFAULT => "default",
|
||||
};
|
||||
format!("{} {} {}", type_str, self.get_hash_path(), self.get_name())
|
||||
}
|
||||
|
||||
fn add_ref_to_parent(&self) -> io::Result<()> {
|
||||
let line = self.get_line();
|
||||
let line = self.get_line(self.obj_type);
|
||||
if self.get_relative_file_path().iter().count() == 1 {
|
||||
head::add_line(line)?;
|
||||
} else {
|
||||
@ -104,11 +109,8 @@ impl ObjMethods for Obj {
|
||||
}
|
||||
|
||||
fn rm_node(&mut self) -> io::Result<()> {
|
||||
// remove self object and children object
|
||||
self.rm_node_down();
|
||||
|
||||
// remove parent reference to self
|
||||
let line = self.get_line();
|
||||
let line = self.get_line(self.obj_type);
|
||||
if self.get_relative_file_path().iter().count() == 1 {
|
||||
head::rm_line(&line)?;
|
||||
} else {
|
||||
@ -166,8 +168,8 @@ impl ObjMethods for Blob {
|
||||
self.obj.get_hash_path()
|
||||
}
|
||||
|
||||
fn get_line(&self) -> String {
|
||||
self.obj.get_line()
|
||||
fn get_line(&self, _: ObjType) -> String {
|
||||
self.obj.get_line(ObjType::BLOB)
|
||||
}
|
||||
|
||||
fn add_ref_to_parent(&self) -> io::Result<()> {
|
||||
@ -175,6 +177,9 @@ impl ObjMethods for Blob {
|
||||
}
|
||||
|
||||
fn rm_node(&mut self) -> io::Result<()> {
|
||||
// remove self object and children object
|
||||
self.rm_node_down();
|
||||
|
||||
self.obj.rm_node()
|
||||
}
|
||||
|
||||
@ -231,8 +236,8 @@ impl ObjMethods for Tree {
|
||||
self.obj.get_hash_path()
|
||||
}
|
||||
|
||||
fn get_line(&self) -> String {
|
||||
self.obj.get_line()
|
||||
fn get_line(&self, _: ObjType) -> String {
|
||||
self.obj.get_line(ObjType::TREE)
|
||||
}
|
||||
|
||||
fn add_ref_to_parent(&self) -> io::Result<()> {
|
||||
@ -240,6 +245,8 @@ impl ObjMethods for Tree {
|
||||
}
|
||||
|
||||
fn rm_node(&mut self) -> io::Result<()> {
|
||||
// remove self object and children object
|
||||
self.rm_node_down();
|
||||
self.obj.rm_node()
|
||||
}
|
||||
|
||||
|
11
tests/add.rs
11
tests/add.rs
@ -94,4 +94,15 @@ mod add_tests {
|
||||
client.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_no_change() {
|
||||
assert!(false);
|
||||
// add a file push it and add it again
|
||||
// let id = get_random_test_id();
|
||||
// let mut client = ClientTest::new(id).init();
|
||||
//
|
||||
//
|
||||
// client.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,8 +100,7 @@ impl ClientTest {
|
||||
let mut path = self.volume.clone();
|
||||
path.push_str("/");
|
||||
path.push_str(name);
|
||||
|
||||
fs::remove_file(name)?;
|
||||
fs::remove_file(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user