feat(add): prevent adding a file without changes
This commit is contained in:
@@ -42,7 +42,10 @@ pub fn add(args: AddArgs) {
|
||||
let path = repo_root().join(Path::new(&f));
|
||||
match path.exists() {
|
||||
true => {
|
||||
add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f);
|
||||
let mut obj = Obj::from_path(f.clone());
|
||||
if obj.has_changes() {
|
||||
add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f);
|
||||
}
|
||||
},
|
||||
false => {
|
||||
if Obj::from_path(file.clone()).exists_on_remote() {
|
||||
|
||||
@@ -32,6 +32,7 @@ pub trait ObjMethods {
|
||||
fn rm_node(&mut self) -> io::Result<()>;
|
||||
fn rm_node_down(&mut self) -> io::Result<()>;
|
||||
fn exists_on_remote(&mut self) -> bool;
|
||||
fn has_changes(&mut self) -> bool;
|
||||
}
|
||||
|
||||
pub struct Obj {
|
||||
@@ -133,6 +134,20 @@ impl ObjMethods for Obj {
|
||||
fn exists_on_remote(&mut self) -> bool {
|
||||
self.obj_path.exists()
|
||||
}
|
||||
|
||||
fn has_changes(&mut self) -> bool {
|
||||
if !self.obj_path.exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
match self.obj_type {
|
||||
ObjType::BLOB => Blob::from_path(self.relative_file_path.clone()).has_changes(),
|
||||
ObjType::TREE => Tree::from_path(self.relative_file_path.clone()).has_changes(),
|
||||
ObjType::DEFAULT => {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjMethods for Blob {
|
||||
@@ -200,6 +215,10 @@ impl ObjMethods for Blob {
|
||||
fn exists_on_remote(&mut self) -> bool {
|
||||
self.obj.exists_on_remote()
|
||||
}
|
||||
|
||||
fn has_changes(&mut self) -> bool {
|
||||
self.obj.has_changes()
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjMethods for Tree {
|
||||
@@ -277,6 +296,10 @@ impl ObjMethods for Tree {
|
||||
fn exists_on_remote(&mut self) -> bool {
|
||||
self.obj.exists_on_remote()
|
||||
}
|
||||
|
||||
fn has_changes(&mut self) -> bool {
|
||||
self.obj.has_changes()
|
||||
}
|
||||
}
|
||||
|
||||
impl Obj {
|
||||
|
||||
@@ -11,6 +11,7 @@ pub struct Tree {
|
||||
is_head: bool,
|
||||
}
|
||||
|
||||
|
||||
impl Tree {
|
||||
pub fn new(obj: Obj) -> Self {
|
||||
Tree {
|
||||
@@ -50,6 +51,11 @@ impl Tree {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_changes(&mut self) -> bool {
|
||||
todo!();
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn next(&mut self) -> Option<Box<dyn ObjMethods>> {
|
||||
self.read();
|
||||
//if let Some(ref mut file) = self.buf_reader {
|
||||
|
||||
Reference in New Issue
Block a user