fix(add): add deleted file

This commit is contained in:
grimhilt 2024-04-16 17:54:25 +02:00
parent 3420634bea
commit e8c8ab9dfe
6 changed files with 34 additions and 19 deletions

View File

@ -45,7 +45,7 @@ pub fn add(args: AddArgs) {
add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f);
},
false => {
if Object::new(path.to_str().unwrap()).exists() {
if Obj::from_path(file.clone()).exists_on_remote() {
// object is deleted so not present but can still be added for deletion
added_files.push(String::from(f));
} else {

View File

@ -28,7 +28,7 @@ pub fn init() {
path.push(".nextsync");
match builder.create(path.clone()) {
Ok(()) => (),
Err(_) => println!("Error: cannot create .nextsync"),
Err(err) => println!("Error: cannot create .nextsync ({})", err),
};
path.push("objects");
@ -59,12 +59,12 @@ pub fn init() {
}
// todo
path.pop();
path.pop();
path.push(".nextsyncignore");
match File::create(path) {
Ok(_) => (),
Err(_) => println!("Error: cannot create .nextsyncignore"),
}
// path.pop();
// path.pop();
// path.push(".nextsyncignore");
//
// match File::create(path) {
// Ok(_) => (),
// Err(_) => println!("Error: cannot create .nextsyncignore"),
// }
}

View File

@ -129,7 +129,7 @@ impl ObjMethods for Obj {
}
fn exists_on_remote(&mut self) -> bool {
PathBuf::from(self.get_hash_path()).exists()
self.obj_path.exists()
}
}
@ -287,6 +287,7 @@ impl Obj {
}
pub fn from_path<S>(path: S) -> Obj where S: IntoPathBuf {
let path = path.into();
let mut hasher = Sha1::new();
hasher.input_str(path.to_str().unwrap());
@ -297,8 +298,13 @@ impl Obj {
obj_path.push(dir);
obj_path.push(res);
// set to absolute path if not already
let root = path::repo_root();
let abs_path = root.join(path.clone());
let abs_path = match path.clone().starts_with(root.clone()) {
true => path.clone(),
false => root.join(path.clone())
};
Obj {
name: match abs_path.file_name() {
None => String::new(),
@ -321,7 +327,7 @@ impl Obj {
/// load from the information line stored in the object
pub fn from_line(line: String, base_dir: Option<PathBuf>) -> Box<dyn ObjMethods> {
let mut split = line.rsplit(' ');
let mut split = line.trim().rsplit(' ');
if split.clone().count() != 3 {
eprintln!("fatal: invalid object(s)");
std::process::exit(1);

View File

@ -1,4 +1,4 @@
use clap::{Arg, ArgMatches, Command};
use clap::{Arg, ArgMatches, Command, ArgAction};
use crate::commands;
use crate::commands::add::AddArgs;
@ -7,7 +7,7 @@ pub fn create() -> Command {
Command::new("add")
.arg(
Arg::new("files")
.required(true)
.required_unless_present("all")
.conflicts_with("all")
.num_args(1..)
.value_name("FILE")
@ -17,12 +17,14 @@ pub fn create() -> Command {
Arg::new("force")
.short('f')
.long("force")
.action(ArgAction::SetTrue)
.help("Allow adding otherwise ignored files."),
)
.arg(
Arg::new("all")
.short('A')
.long("all")
.action(ArgAction::SetTrue)
.help("This adds, modifies, and removes index entries to match the working tree"),
)
.about("Add changes to the index")
@ -34,7 +36,7 @@ pub fn handler(args: &ArgMatches) {
None => vec![],
Some(vals) => vals.map(|s| s.to_string()).collect(),
},
force: args.contains_id("force"),
all: args.contains_id("all"),
force: *args.get_one::<bool>("force").unwrap(),
all: *args.get_one::<bool>("all").unwrap(),
});
}

View File

@ -1,4 +1,4 @@
use clap::{Arg, Command, ArgMatches};
use clap::{Arg, Command, ArgMatches, ArgAction};
use crate::commands;
use crate::commands::remote::RemoteArgs;
@ -26,6 +26,7 @@ pub fn create() -> Command {
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::SetTrue)
.help("Be a little more verbose and show remote url after name.")
)
}
@ -39,7 +40,7 @@ pub fn handler(args: &ArgMatches) {
});
}
_ => {
commands::remote::remote_list(args.contains_id("verbose"));
commands::remote::remote_list(*args.get_one::<bool>("verbose").unwrap());
}
}
}

View File

@ -22,3 +22,9 @@ impl IntoPathBuf for String {
}
}
impl IntoPathBuf for &str {
fn into(self) -> PathBuf {
PathBuf::from(self)
}
}