fix(add): add deleted file
This commit is contained in:
parent
3420634bea
commit
e8c8ab9dfe
@ -45,7 +45,7 @@ pub fn add(args: AddArgs) {
|
|||||||
add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f);
|
add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f);
|
||||||
},
|
},
|
||||||
false => {
|
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
|
// object is deleted so not present but can still be added for deletion
|
||||||
added_files.push(String::from(f));
|
added_files.push(String::from(f));
|
||||||
} else {
|
} else {
|
||||||
|
@ -28,7 +28,7 @@ pub fn init() {
|
|||||||
path.push(".nextsync");
|
path.push(".nextsync");
|
||||||
match builder.create(path.clone()) {
|
match builder.create(path.clone()) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(_) => println!("Error: cannot create .nextsync"),
|
Err(err) => println!("Error: cannot create .nextsync ({})", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
path.push("objects");
|
path.push("objects");
|
||||||
@ -59,12 +59,12 @@ pub fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
path.pop();
|
// path.pop();
|
||||||
path.pop();
|
// path.pop();
|
||||||
path.push(".nextsyncignore");
|
// path.push(".nextsyncignore");
|
||||||
|
//
|
||||||
match File::create(path) {
|
// match File::create(path) {
|
||||||
Ok(_) => (),
|
// Ok(_) => (),
|
||||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
// Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ impl ObjMethods for Obj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exists_on_remote(&mut self) -> bool {
|
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 {
|
pub fn from_path<S>(path: S) -> Obj where S: IntoPathBuf {
|
||||||
|
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let mut hasher = Sha1::new();
|
let mut hasher = Sha1::new();
|
||||||
hasher.input_str(path.to_str().unwrap());
|
hasher.input_str(path.to_str().unwrap());
|
||||||
@ -297,8 +298,13 @@ impl Obj {
|
|||||||
obj_path.push(dir);
|
obj_path.push(dir);
|
||||||
obj_path.push(res);
|
obj_path.push(res);
|
||||||
|
|
||||||
|
// set to absolute path if not already
|
||||||
let root = path::repo_root();
|
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 {
|
Obj {
|
||||||
name: match abs_path.file_name() {
|
name: match abs_path.file_name() {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
@ -321,7 +327,7 @@ impl Obj {
|
|||||||
|
|
||||||
/// load from the information line stored in the object
|
/// load from the information line stored in the object
|
||||||
pub fn from_line(line: String, base_dir: Option<PathBuf>) -> Box<dyn ObjMethods> {
|
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 {
|
if split.clone().count() != 3 {
|
||||||
eprintln!("fatal: invalid object(s)");
|
eprintln!("fatal: invalid object(s)");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use clap::{Arg, ArgMatches, Command};
|
use clap::{Arg, ArgMatches, Command, ArgAction};
|
||||||
|
|
||||||
use crate::commands;
|
use crate::commands;
|
||||||
use crate::commands::add::AddArgs;
|
use crate::commands::add::AddArgs;
|
||||||
@ -7,7 +7,7 @@ pub fn create() -> Command {
|
|||||||
Command::new("add")
|
Command::new("add")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("files")
|
Arg::new("files")
|
||||||
.required(true)
|
.required_unless_present("all")
|
||||||
.conflicts_with("all")
|
.conflicts_with("all")
|
||||||
.num_args(1..)
|
.num_args(1..)
|
||||||
.value_name("FILE")
|
.value_name("FILE")
|
||||||
@ -17,12 +17,14 @@ pub fn create() -> Command {
|
|||||||
Arg::new("force")
|
Arg::new("force")
|
||||||
.short('f')
|
.short('f')
|
||||||
.long("force")
|
.long("force")
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
.help("Allow adding otherwise ignored files."),
|
.help("Allow adding otherwise ignored files."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("all")
|
Arg::new("all")
|
||||||
.short('A')
|
.short('A')
|
||||||
.long("all")
|
.long("all")
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
.help("This adds, modifies, and removes index entries to match the working tree"),
|
.help("This adds, modifies, and removes index entries to match the working tree"),
|
||||||
)
|
)
|
||||||
.about("Add changes to the index")
|
.about("Add changes to the index")
|
||||||
@ -34,7 +36,7 @@ pub fn handler(args: &ArgMatches) {
|
|||||||
None => vec![],
|
None => vec![],
|
||||||
Some(vals) => vals.map(|s| s.to_string()).collect(),
|
Some(vals) => vals.map(|s| s.to_string()).collect(),
|
||||||
},
|
},
|
||||||
force: args.contains_id("force"),
|
force: *args.get_one::<bool>("force").unwrap(),
|
||||||
all: args.contains_id("all"),
|
all: *args.get_one::<bool>("all").unwrap(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use clap::{Arg, Command, ArgMatches};
|
use clap::{Arg, Command, ArgMatches, ArgAction};
|
||||||
|
|
||||||
use crate::commands;
|
use crate::commands;
|
||||||
use crate::commands::remote::RemoteArgs;
|
use crate::commands::remote::RemoteArgs;
|
||||||
@ -26,6 +26,7 @@ pub fn create() -> Command {
|
|||||||
Arg::new("verbose")
|
Arg::new("verbose")
|
||||||
.short('v')
|
.short('v')
|
||||||
.long("verbose")
|
.long("verbose")
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
.help("Be a little more verbose and show remote url after name.")
|
.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,3 +22,9 @@ impl IntoPathBuf for String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoPathBuf for &str {
|
||||||
|
fn into(self) -> PathBuf {
|
||||||
|
PathBuf::from(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user