diff --git a/src/commands/add.rs b/src/commands/add.rs index bae3a4c..0ab935b 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -39,35 +39,19 @@ pub fn add(args: AddArgs) { } }; - // check if the file must be ignored - if !args.force && ignore_file(&f, rules.clone(), &mut ignored_f) { - continue; - } - let path = repo_root().join(Path::new(&f)); match path.exists() { true => { - added_files.push(f); - if path.is_dir() { - add_folder_content(path.to_path_buf(), &mut added_files); - } + add_entry(path, args.force, &mut added_files, rules.clone(), &mut ignored_f); }, false => { if Object::new(path.to_str().unwrap()).exists() { - // object is deleted so not a present file but can still be added + // object is deleted so not present but can still be added for deletion added_files.push(String::from(f)); } else { + // try globbing if nothing has been found for entry in try_globbing(path) { - if path::is_nextsync_config(entry.clone()) { - continue; - } - if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) { - continue; - } - added_files.push(path_buf_to_string(entry.strip_prefix(repo_root()).unwrap().to_path_buf())); - if entry.is_dir() { - add_folder_content(entry.to_path_buf(), &mut added_files); - } + add_entry(entry, args.force, &mut added_files, rules.clone(), &mut ignored_f); } } } @@ -78,6 +62,24 @@ pub fn add(args: AddArgs) { write_added_files(added_files); } +fn add_entry(entry: PathBuf, force: bool, added_files: &mut Vec, rules: Vec, ignored_f: &mut Vec) { + // ignore nextsync config files + if path::is_nextsync_config(entry.clone()) { + return; + } + + // check if the file must be ignored + if !force && ignore_file(&path_buf_to_string(entry.clone()), rules, ignored_f) { + return; + } + + added_files.push(path_buf_to_string(entry.strip_prefix(repo_root()).unwrap().to_path_buf())); + if entry.is_dir() { + add_folder_content(entry.to_path_buf(), added_files); + } + +} + fn print_ignored_files(ignored_files: Vec) { if ignored_files.len() > 0 { // todo multiple nextsyncignore