Compare commits
No commits in common. "81c24b5e3c64d8c50d242bb8000f6f26183a60d6" and "56234eaa3d3dd63de53e2ee0a326f4f2978c34cc" have entirely different histories.
81c24b5e3c
...
56234eaa3d
@ -2,7 +2,6 @@ use std::io::Write;
|
|||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use clap::Values;
|
use clap::Values;
|
||||||
use glob::glob;
|
|
||||||
use crate::store::index;
|
use crate::store::index;
|
||||||
use crate::store::{self, object::Object};
|
use crate::store::{self, object::Object};
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
@ -18,6 +17,7 @@ pub struct AddArgs<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo match deleted files
|
// todo match deleted files
|
||||||
|
// todo match weird reg expression
|
||||||
pub fn add(args: AddArgs) {
|
pub fn add(args: AddArgs) {
|
||||||
// write all modification in the index
|
// write all modification in the index
|
||||||
if args.all {
|
if args.all {
|
||||||
@ -25,12 +25,18 @@ pub fn add(args: AddArgs) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut index_file = store::index::open();
|
||||||
let mut added_files: Vec<String> = vec![];
|
let mut added_files: Vec<String> = vec![];
|
||||||
let mut ignored_f = vec![];
|
|
||||||
let rules = nextsyncignore::get_rules();
|
|
||||||
|
|
||||||
|
let rules = match nextsyncignore::read_lines() {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(_) => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut ignored_f = vec![];
|
||||||
let file_vec: Vec<&str> = args.files.unwrap().collect();
|
let file_vec: Vec<&str> = args.files.unwrap().collect();
|
||||||
for file in file_vec {
|
for file in file_vec {
|
||||||
|
|
||||||
let f = match normalize_relative(file) {
|
let f = match normalize_relative(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -39,12 +45,12 @@ pub fn add(args: AddArgs) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if the file must be ignored
|
|
||||||
if !args.force && ignore_file(&f, rules.clone(), &mut ignored_f) {
|
if !args.force && ignore_file(&f, rules.clone(), &mut ignored_f) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = repo_root().join(Path::new(&f));
|
let path = repo_root().join(Path::new(&f));
|
||||||
|
|
||||||
match path.exists() {
|
match path.exists() {
|
||||||
true => {
|
true => {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
@ -54,43 +60,26 @@ pub fn add(args: AddArgs) {
|
|||||||
},
|
},
|
||||||
false => {
|
false => {
|
||||||
if Object::new(path.to_str().unwrap()).exists() {
|
if Object::new(path.to_str().unwrap()).exists() {
|
||||||
// object is deleted so not a present file but can still be added
|
|
||||||
added_files.push(String::from(f));
|
added_files.push(String::from(f));
|
||||||
} else {
|
} else {
|
||||||
for entry in try_globbing(path) {
|
// todo applies regex
|
||||||
if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) {
|
eprintln!("err: {} is not something you can add.", path.to_str().unwrap());
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if entry.is_dir() {
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_ignored_files(ignored_f);
|
if ignored_f.len() > 0 {
|
||||||
write_added_files(added_files);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_ignored_files(ignored_files: Vec<String>) {
|
|
||||||
if ignored_files.len() > 0 {
|
|
||||||
// todo multiple nextsyncignore
|
// todo multiple nextsyncignore
|
||||||
println!("The following paths are ignored by your .nextsyncignore file:");
|
println!("The following paths are ignored by your .nextsyncignore file:");
|
||||||
for file in ignored_files {
|
for file in ignored_f {
|
||||||
println!("{}", file);
|
println!("{}", file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn write_added_files(added_files: Vec<String>) {
|
// save all added_files in index
|
||||||
let mut index_file = store::index::open();
|
// todo avoid duplication
|
||||||
for file in added_files {
|
for file in added_files {
|
||||||
if store::index::alread_added(file.clone()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
match writeln!(index_file, "{}", file) {
|
match writeln!(index_file, "{}", file) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => eprintln!("{}", err),
|
Err(err) => eprintln!("{}", err),
|
||||||
@ -99,23 +88,6 @@ fn write_added_files(added_files: Vec<String>) {
|
|||||||
drop(index_file);
|
drop(index_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_globbing(path: PathBuf) -> Vec<PathBuf> {
|
|
||||||
let mut paths: Vec<PathBuf> = vec![];
|
|
||||||
if let Ok(entries) = glob(path.to_str().unwrap()) {
|
|
||||||
for entry in entries {
|
|
||||||
match entry {
|
|
||||||
Ok(ppath) => paths.push(ppath),
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("err: {} incorrect pattern ({})", path.display(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eprintln!("err: {} is not something you can add.", path.to_str().unwrap());
|
|
||||||
}
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_folder_content(path: PathBuf, added_files: &mut Vec<String>) {
|
fn add_folder_content(path: PathBuf, added_files: &mut Vec<String>) {
|
||||||
// todo check for changes
|
// todo check for changes
|
||||||
let mut folders: Vec<PathBuf> = vec![];
|
let mut folders: Vec<PathBuf> = vec![];
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
use std::env;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use dotenv::dotenv;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use reqwest::RequestBuilder;
|
use reqwest::RequestBuilder;
|
||||||
use reqwest::multipart::Form;
|
use reqwest::multipart::Form;
|
||||||
|
@ -4,7 +4,7 @@ pub trait ApiCall {
|
|||||||
fn new() -> Self where Self: Sized {
|
fn new() -> Self where Self: Sized {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn set_url(&mut self, _url: &str) -> &mut Self {
|
fn set_url(&mut self, url: &str) -> &mut Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
fn send(&mut self) -> Result<Option<String>, ApiError> {
|
fn send(&mut self) -> Result<Option<String>, ApiError> {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod head;
|
pub mod head;
|
||||||
pub mod object;
|
pub mod object;
|
||||||
pub mod gconfig;
|
|
||||||
|
@ -32,16 +32,3 @@ pub fn rm_line(line: &str) -> io::Result<()> {
|
|||||||
read::rm_line(root, line)?;
|
read::rm_line(root, line)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alread_added(file: String) -> bool {
|
|
||||||
if let Ok(lines) = read_line() {
|
|
||||||
for line in lines {
|
|
||||||
if let Ok(l) = line {
|
|
||||||
if l == file {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
@ -27,9 +27,6 @@ pub struct Blob {
|
|||||||
impl Blob {
|
impl Blob {
|
||||||
pub fn new<S>(r_path: S) -> Blob where S: IntoPathBuf {
|
pub fn new<S>(r_path: S) -> Blob where S: IntoPathBuf {
|
||||||
let r_path = r_path.into();
|
let r_path = r_path.into();
|
||||||
if r_path.is_dir() {
|
|
||||||
eprintln!("{}: is a directory not a blob", r_path.display());
|
|
||||||
}
|
|
||||||
let mut hasher = Sha1::new();
|
let mut hasher = Sha1::new();
|
||||||
hasher.input_str(r_path.to_str().unwrap());
|
hasher.input_str(r_path.to_str().unwrap());
|
||||||
let hash = hasher.result_str();
|
let hash = hasher.result_str();
|
||||||
|
@ -23,13 +23,6 @@ pub fn read_lines() -> Result<Vec<String>, ()> {
|
|||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rules() -> Vec<String> {
|
|
||||||
match read_lines() {
|
|
||||||
Ok(r) => r,
|
|
||||||
Err(_) => vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn _ignore_files(files: &mut Vec<String>) -> (bool, Vec<String>) {
|
pub fn _ignore_files(files: &mut Vec<String>) -> (bool, Vec<String>) {
|
||||||
let mut ignored_f = vec![];
|
let mut ignored_f = vec![];
|
||||||
if let Ok(lines) = read_lines() {
|
if let Ok(lines) = read_lines() {
|
||||||
@ -87,7 +80,6 @@ pub fn ignore_file(path: &String, lines: Vec<String>, ignored_f: &mut Vec<String
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ignore_files() {
|
fn test_ignore_files() {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
nb_tests=0
|
|
||||||
TEST_SUITE_NAME="add/file/"
|
|
||||||
|
|
||||||
get_exe() {
|
get_exe() {
|
||||||
exe=$(pwd)
|
exe=$(pwd)
|
||||||
exe+="/../target/debug/nextsync"
|
exe+="/../target/debug/nextsync"
|
||||||
if [ ! -f $exe ]; then
|
if [ ! -f $exe ]; then
|
||||||
echo "No executable found, try to compile first" >&2
|
echo "No executable found, try to compile first"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -21,33 +18,26 @@ add_cmp() {
|
|||||||
res=$($exe status --nostyle)
|
res=$($exe status --nostyle)
|
||||||
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
|
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2
|
echo -e "$1: Output differ:"
|
||||||
diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2
|
diff <(echo -e "$2" ) <(echo -e "$res")
|
||||||
echo -e "\nMore in $path" >&2
|
echo $path
|
||||||
echo $nb_tests
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
add_test_no_env() {
|
add_test() {
|
||||||
|
setup_env
|
||||||
|
$exe init
|
||||||
touch $2
|
touch $2
|
||||||
$exe add $3
|
$exe add $3
|
||||||
add_cmp "$1" "$4"
|
add_cmp "$1" "$4"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_test() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
add_test_no_env "$1" "$2" "$3" "$4"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_basics() {
|
add_basics() {
|
||||||
add_test "basic" "toto" "toto" "new: toto"
|
add_test "basic" "toto" "toto" "new: toto"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_space() {
|
add_space() {
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
setup_env
|
||||||
$exe init
|
$exe init
|
||||||
touch 'to to'
|
touch 'to to'
|
||||||
@ -65,7 +55,6 @@ add_regex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_subdir() {
|
add_subdir() {
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
setup_env
|
||||||
$exe init
|
$exe init
|
||||||
mkdir dir
|
mkdir dir
|
||||||
@ -76,7 +65,6 @@ add_subdir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_subdir_regex() {
|
add_subdir_regex() {
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
setup_env
|
||||||
$exe init
|
$exe init
|
||||||
mkdir dir
|
mkdir dir
|
||||||
@ -86,44 +74,11 @@ add_subdir_regex() {
|
|||||||
add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
|
add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_duplication() {
|
|
||||||
add_test "duplication" "toto" "toto toto" "new: toto"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_duplication_subdir() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
mkdir dir
|
|
||||||
add_test_no_env "duplication_subdir" "dir/toto" "dir/toto dir/toto" "new: dir/toto"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_all() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
mkdir dir
|
|
||||||
touch dir/toto dir/roro lolo
|
|
||||||
$exe add -A
|
|
||||||
res=$($exe status --nostyle)
|
|
||||||
add/file/all: Output differ:
|
|
||||||
add_cmp "all" "new: dir/roro\nnew: dir/toto\nnew: lolo\nnew: .nextsyncignore"
|
|
||||||
}
|
|
||||||
|
|
||||||
#test nextsyncignore
|
|
||||||
#test inside folder
|
|
||||||
#test -A duplication
|
|
||||||
#test add file without changes
|
|
||||||
|
|
||||||
add_basics
|
add_basics
|
||||||
add_space
|
add_space
|
||||||
add_multiple
|
add_multiple
|
||||||
add_regex
|
add_regex
|
||||||
add_subdir
|
add_subdir
|
||||||
add_subdir_regex
|
#add_subdir_regex
|
||||||
add_duplication
|
|
||||||
add_duplication_subdir
|
|
||||||
add_all
|
|
||||||
|
|
||||||
echo $nb_tests
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -15,28 +15,18 @@ fi
|
|||||||
nb_tests=0
|
nb_tests=0
|
||||||
nb_success=0
|
nb_success=0
|
||||||
for test in $TESTS; do
|
for test in $TESTS; do
|
||||||
#nb_tests=$((nb_tests + 1))
|
nb_tests=$((nb_tests + 1))
|
||||||
|
|
||||||
# run file
|
# run file
|
||||||
tmp_stderr=$(mktemp)
|
$test
|
||||||
nb_tests_tmp=$($test 2>"$tmp_stderr")
|
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
capture_stderr=$(<"$tmp_stderr")
|
|
||||||
[ "$capture_stderr" != "" ] && echo -e "$capture_stderr"
|
|
||||||
rm $tmp_stderr
|
|
||||||
|
|
||||||
# add nb_tests from executed test_suite to global nb_test
|
|
||||||
[ "$nb_tests_tmp" != "" ] &&
|
|
||||||
[ $nb_tests_tmp -gt 0 ] &&
|
|
||||||
nb_tests=$((nb_tests + nb_tests_tmp))
|
|
||||||
|
|
||||||
if [ $exit_code -eq 0 ]; then
|
if [ $exit_code -eq 0 ]; then
|
||||||
nb_success=$((nb_success + nb_tests_tmp))
|
nb_success=$((nb_success + 1))
|
||||||
elif [ $exit_code -eq 4 ]; then
|
elif [ $exit_code -eq 4 ]; then
|
||||||
# not executable (nextsync) found, not need to try other tests
|
# not executable found, not need to try other tests
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
nb_success=$((nb_success + nb_tests_tmp - 1))
|
|
||||||
echo "$test failed with exit code $exit_code"
|
echo "$test failed with exit code $exit_code"
|
||||||
fi
|
fi
|
||||||
done;
|
done;
|
||||||
|
Loading…
Reference in New Issue
Block a user