fix(status): get status in obj and fix tests env dir
This commit is contained in:
@@ -191,12 +191,11 @@ fn print_object(obj: &Obj, root_path: &PathBuf, color: impl Fn(&str) -> ColoredS
|
||||
println!(
|
||||
" {}{}",
|
||||
match obj.get_status() {
|
||||
ObjStatus::Created =>
|
||||
if obj.get_obj_type() == &ObjType::Blob {
|
||||
color("new file: ")
|
||||
} else {
|
||||
color("new: ")
|
||||
},
|
||||
ObjStatus::Created => match *obj.get_obj_type() {
|
||||
ObjType::Blob => color("new file: "),
|
||||
ObjType::Tree => color("new dir: "),
|
||||
ObjType::Obj => color("new: "),
|
||||
},
|
||||
ObjStatus::Modified => color("modified: "),
|
||||
ObjStatus::Deleted => color("deleted: "),
|
||||
_ => "unknown".red(),
|
||||
|
||||
@@ -47,6 +47,7 @@ impl TryFrom<u8> for ObjType {
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub enum ObjStatus {
|
||||
Undefined,
|
||||
Unchanged,
|
||||
Created,
|
||||
Modified,
|
||||
Moved,
|
||||
@@ -84,9 +85,17 @@ impl Obj {
|
||||
|
||||
pub fn get_status(&self) -> &ObjStatus {
|
||||
self.status.get_or_init(|| {
|
||||
// todo!();
|
||||
// TODO read path
|
||||
ObjStatus::Created
|
||||
let nsobj = self.get_nsobj();
|
||||
if !nsobj.exists() {
|
||||
return ObjStatus::Created;
|
||||
}
|
||||
if !self.obj_path.exists() {
|
||||
return ObjStatus::Deleted;
|
||||
}
|
||||
if *self != nsobj {
|
||||
return ObjStatus::Modified;
|
||||
}
|
||||
todo!("Read status");
|
||||
})
|
||||
}
|
||||
|
||||
@@ -119,7 +128,13 @@ impl Obj {
|
||||
|
||||
if let Ok(root_diff) = binding.strip_prefix(repo_root) {
|
||||
match self.obj_path.strip_prefix(&root_diff) {
|
||||
Ok(path) => path.to_path_buf(),
|
||||
Ok(path) => {
|
||||
if path == PathBuf::from("") {
|
||||
PathBuf::from("./")
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// if cannot strip prefix then we need to go up to the root
|
||||
let mut res_path = PathBuf::new();
|
||||
@@ -140,6 +155,10 @@ impl Obj {
|
||||
path::to_string(&self.obj_path)
|
||||
}
|
||||
|
||||
fn get_nsobj(&self) -> NsObject {
|
||||
NsObject::from_local_path(&self.obj_path)
|
||||
}
|
||||
|
||||
fn get_nsobj_path(&self) -> NsObjPath {
|
||||
NsObjPath::from(&self.obj_path)
|
||||
}
|
||||
@@ -153,7 +172,7 @@ impl Obj {
|
||||
let mut nsobj_dir = nsobj_path.clone();
|
||||
nsobj_dir.pop();
|
||||
if !nsobj_dir.exists() {
|
||||
std::fs::create_dir_all(nsobj_dir)?;
|
||||
std::fs::create_dir_all(nsobj_dir)?;
|
||||
}
|
||||
File::create(&nsobj_path)?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user