fix: allow to push explicit directory

This commit is contained in:
grimhilt 2024-03-10 16:19:23 +01:00
parent 06bb51476b
commit fdcd4633e5
6 changed files with 29 additions and 9 deletions

View File

@ -47,10 +47,10 @@ pub fn add(args: AddArgs) {
let path = repo_root().join(Path::new(&f)); let path = repo_root().join(Path::new(&f));
match path.exists() { match path.exists() {
true => { true => {
added_files.push(f);
if path.is_dir() { if path.is_dir() {
add_folder_content(path.to_path_buf(), &mut added_files); add_folder_content(path.to_path_buf(), &mut added_files);
} }
added_files.push(f);
}, },
false => { false => {
if Object::new(path.to_str().unwrap()).exists() { if Object::new(path.to_str().unwrap()).exists() {
@ -64,10 +64,10 @@ pub fn add(args: AddArgs) {
if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) { if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) {
continue; continue;
} }
added_files.push(path_buf_to_string(entry.strip_prefix(repo_root()).unwrap().to_path_buf()));
if entry.is_dir() { if entry.is_dir() {
add_folder_content(entry.to_path_buf(), &mut added_files); add_folder_content(entry.to_path_buf(), &mut added_files);
} }
added_files.push(path_buf_to_string(entry.strip_prefix(repo_root()).unwrap().to_path_buf()));
} }
} }
} }

View File

@ -32,6 +32,7 @@ impl PushChange for New {
match res { match res {
Err(ApiError::IncorrectRequest(err)) => { Err(ApiError::IncorrectRequest(err)) => {
dbg!(&err);
eprintln!("fatal: error pushing file '{}': {}", obj.name, err.status()); eprintln!("fatal: error pushing file '{}': {}", obj.name, err.status());
std::process::exit(1); std::process::exit(1);
}, },

View File

@ -31,6 +31,7 @@ impl PushChange for NewDir {
} }
fn push(&self) -> io::Result<()> { fn push(&self) -> io::Result<()> {
dbg!("pushing new dir");
let obj = &self.obj; let obj = &self.obj;
let res = CreateFolder::new() let res = CreateFolder::new()
.set_url(obj.path.to_str().unwrap()) .set_url(obj.path.to_str().unwrap())

View File

@ -148,7 +148,7 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> {
root.push(dir); root.push(dir);
if !root.exists() { if !root.exists() {
todo!(); //todo!();
} }
root.push(rest); root.push(rest);

View File

@ -22,6 +22,7 @@ pub trait ObjMethods {
fn get_obj_path(&self) -> PathBuf; fn get_obj_path(&self) -> PathBuf;
fn get_file_path(&self) -> PathBuf; fn get_file_path(&self) -> PathBuf;
fn get_relative_file_path(&self) -> PathBuf; fn get_relative_file_path(&self) -> PathBuf;
fn get_repo_file_path(&self) -> PathBuf;
fn get_name(&self) -> String; fn get_name(&self) -> String;
fn get_hash_path(&self) -> String; fn get_hash_path(&self) -> String;
fn get_local_obj(&self) -> LocalObj; fn get_local_obj(&self) -> LocalObj;
@ -38,6 +39,7 @@ pub struct Obj {
obj_type: ObjType, obj_type: ObjType,
file_path: PathBuf, // file here is used as both file and directory file_path: PathBuf, // file here is used as both file and directory
relative_file_path: PathBuf, relative_file_path: PathBuf,
repo_file_path: PathBuf,
hash_path: String, // hash of the relative path of the file hash_path: String, // hash of the relative path of the file
} }
@ -59,6 +61,10 @@ impl ObjMethods for Obj {
self.relative_file_path.clone() self.relative_file_path.clone()
} }
fn get_repo_file_path(&self) -> PathBuf {
self.repo_file_path.clone()
}
fn get_local_obj(&self) -> LocalObj { fn get_local_obj(&self) -> LocalObj {
LocalObj { LocalObj {
otype: match self.obj_type { otype: match self.obj_type {
@ -67,7 +73,7 @@ impl ObjMethods for Obj {
ObjType::DEFAULT => String::from("default"), ObjType::DEFAULT => String::from("default"),
}, },
name: self.get_name(), name: self.get_name(),
path: self.get_file_path(), path: self.get_repo_file_path(),
path_from: None, path_from: None,
state: State::New state: State::New
} }
@ -139,6 +145,10 @@ impl ObjMethods for Blob {
self.obj.get_relative_file_path() self.obj.get_relative_file_path()
} }
fn get_repo_file_path(&self) -> PathBuf {
self.obj.get_repo_file_path()
}
fn get_local_obj(&self) -> LocalObj { fn get_local_obj(&self) -> LocalObj {
self.obj.get_local_obj() self.obj.get_local_obj()
} }
@ -196,6 +206,10 @@ impl ObjMethods for Tree {
self.obj.get_relative_file_path() self.obj.get_relative_file_path()
} }
fn get_repo_file_path(&self) -> PathBuf {
self.obj.get_repo_file_path()
}
fn get_local_obj(&self) -> LocalObj { fn get_local_obj(&self) -> LocalObj {
self.obj.get_local_obj() self.obj.get_local_obj()
} }
@ -254,7 +268,8 @@ impl Obj {
file_path: PathBuf::new(), file_path: PathBuf::new(),
obj_type: ObjType::DEFAULT, obj_type: ObjType::DEFAULT,
hash_path: String::new(), hash_path: String::new(),
relative_file_path: PathBuf::new() relative_file_path: PathBuf::new(),
repo_file_path: PathBuf::new()
} }
} }
@ -285,7 +300,8 @@ impl Obj {
false => ObjType::DEFAULT false => ObjType::DEFAULT
}, },
file_path: abs_path, file_path: abs_path,
relative_file_path: path, relative_file_path: path.clone(),
repo_file_path: path,
hash_path: hash, hash_path: hash,
} }
} }
@ -324,7 +340,8 @@ impl Obj {
_ => ObjType::DEFAULT _ => ObjType::DEFAULT
}, },
file_path: abs_path, file_path: abs_path,
relative_file_path: path, relative_file_path: path.clone(),
repo_file_path: path,
hash_path: String::from(hash_path), hash_path: String::from(hash_path),
}; };
@ -342,6 +359,7 @@ impl Obj {
obj_type: ObjType::TREE, obj_type: ObjType::TREE,
file_path: PathBuf::new(), file_path: PathBuf::new(),
relative_file_path: PathBuf::new(), relative_file_path: PathBuf::new(),
repo_file_path: PathBuf::new(),
hash_path: String::new(), hash_path: String::new(),
} }
} }

View File

@ -85,10 +85,10 @@ impl Tree {
// create tree object // create tree object
let mut content = format!("{} {}", self.get_name(), date); let mut content = format!("{} {}", self.get_name(), date);
//create_obj(self.get_hash_path(), &content)?; //create_obj(self.get_hash_path(), &content)?;
todo!(); // todo!();
// update date for all parent // update date for all parent
todo!(); //todo!();
//if up_parent { //if up_parent {
// update_dates(path, date)?; // update_dates(path, date)?;
//} //}