Compare commits
No commits in common. "56234eaa3d3dd63de53e2ee0a326f4f2978c34cc" and "f4a905c57f7059b8e307f2c6a3b1437d7ac1e5c0" have entirely different histories.
56234eaa3d
...
f4a905c57f
@ -62,7 +62,6 @@ pub fn add(args: AddArgs) {
|
||||
if Object::new(path.to_str().unwrap()).exists() {
|
||||
added_files.push(String::from(f));
|
||||
} else {
|
||||
// todo applies regex
|
||||
eprintln!("err: {} is not something you can add.", path.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,6 @@ use crate::utils::read::{read_folder, read_lines};
|
||||
use crate::store::object::tree;
|
||||
use crate::store::index;
|
||||
|
||||
pub struct StatusArgs {
|
||||
pub nostyle: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum RemoveSide {
|
||||
Left,
|
||||
@ -35,7 +31,7 @@ pub enum State {
|
||||
|
||||
// todo: relative path, filename
|
||||
// todo: not catch added empty folder
|
||||
pub fn status(args: StatusArgs) {
|
||||
pub fn status() {
|
||||
let mut all_hashes = get_all_objs_hashes();
|
||||
let staged_objs = get_staged(&mut all_hashes);
|
||||
|
||||
@ -43,14 +39,8 @@ pub fn status(args: StatusArgs) {
|
||||
x.1.clone()
|
||||
}).collect();
|
||||
|
||||
if args.nostyle
|
||||
{
|
||||
print_status_nostyle(staged_objs, objs);
|
||||
}
|
||||
else
|
||||
{
|
||||
print_status(staged_objs, objs);
|
||||
}
|
||||
|
||||
print_status(staged_objs, objs);
|
||||
}
|
||||
|
||||
pub fn get_all_objs() -> Vec<LocalObj> {
|
||||
@ -92,11 +82,6 @@ fn get_all_objs_hashes() -> HashMap<String, LocalObj> {
|
||||
|
||||
fn should_retain(hasher: &mut Sha1, key: String, obj: LocalObj, move_copy_hashes: &mut HashMap<String, LocalObj>, del_objs_h: &mut HashMap<String, LocalObj>) -> bool {
|
||||
// todo prevent copied or moved if file empty
|
||||
// todo deal with directories
|
||||
if obj.path.is_dir()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let mut blob = Blob::new(obj.path.clone());
|
||||
let mut flag = true;
|
||||
let identical_blobs = blob.get_all_identical_blobs();
|
||||
@ -363,26 +348,6 @@ fn print_status(staged_objs: Vec<LocalObj>, objs: Vec<LocalObj>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_status_nostyle(staged_objs: Vec<LocalObj>, objs: Vec<LocalObj>) {
|
||||
// todo sort
|
||||
if staged_objs.len() == 0 && objs.len() == 0 {
|
||||
return;
|
||||
}
|
||||
for obj in staged_objs {
|
||||
if obj.state == State::Deleted {
|
||||
println!("deleted: {}", obj.name);
|
||||
} else if obj.state == State::New {
|
||||
println!("new: {}", obj.name);
|
||||
} else if obj.state == State::Modified {
|
||||
println!("modified: {}", obj.name);
|
||||
} else if obj.state == State::Moved {
|
||||
println!("moved: {} => {}", path_buf_to_string(obj.path_from.unwrap()), path_buf_to_string(obj.path));
|
||||
} else if obj.state == State::Copied {
|
||||
println!("copied: {} => {}", path_buf_to_string(obj.path_from.unwrap()), path_buf_to_string(obj.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_object(obj: LocalObj) {
|
||||
if obj.state == State::Deleted {
|
||||
println!(" {} {}", String::from("deleted:").red(), obj.name.red());
|
||||
@ -448,7 +413,7 @@ fn is_nextsync_config(path: PathBuf) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_remove_duplicate() {
|
||||
let mut hasher = Sha1::new();
|
||||
|
11
src/main.rs
11
src/main.rs
@ -2,7 +2,6 @@ use clap::{App, Arg, SubCommand};
|
||||
use textwrap::{fill, Options};
|
||||
|
||||
use crate::commands::add::AddArgs;
|
||||
use crate::commands::status::StatusArgs;
|
||||
use crate::commands::clone::{self, CloneArgs};
|
||||
|
||||
mod commands;
|
||||
@ -67,11 +66,6 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.value_name("DIRECTORY")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("nostyle")
|
||||
.long("nostyle")
|
||||
.help("Status with minium information and style"),
|
||||
)
|
||||
.about("Show the working tree status")
|
||||
)
|
||||
.subcommand(
|
||||
@ -147,9 +141,7 @@ fn main() {
|
||||
if let Some(val) = matches.values_of("directory") {
|
||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
||||
}
|
||||
commands::status::status(StatusArgs {
|
||||
nostyle: matches.is_present("nostyle"),
|
||||
});
|
||||
commands::status::status();
|
||||
} else if let Some(matches) = matches.subcommand_matches("add") {
|
||||
if let Some(files) = matches.values_of("files") {
|
||||
commands::add::add(AddArgs {
|
||||
@ -199,6 +191,7 @@ fn main() {
|
||||
}
|
||||
commands::pull::pull();
|
||||
} else if let Some(_) = matches.subcommand_matches("test") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ impl ApiCall for Login {
|
||||
};
|
||||
self.api_builder.set_url(Method::GET, &url);
|
||||
self.api_builder.set_header("OCS-APIRequest", HeaderValue::from_str("true").unwrap());
|
||||
self.api_builder.set_header("USER-AGENT", HeaderValue::from_str("nextsync").unwrap());
|
||||
self.api_builder.set_basic_auth(self.login.clone(), self.password.clone());
|
||||
self.api_builder.send(true)
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
get_exe() {
|
||||
exe=$(pwd)
|
||||
exe+="/../target/debug/nextsync"
|
||||
if [ ! -f $exe ]; then
|
||||
echo "No executable found, try to compile first"
|
||||
exit 4
|
||||
fi
|
||||
}
|
||||
setup_env() {
|
||||
[ ! -v exe ] && get_exe
|
||||
path=$(mktemp -d)
|
||||
cd $path
|
||||
}
|
||||
|
||||
add_cmp() {
|
||||
res=$($exe status --nostyle)
|
||||
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "$1: Output differ:"
|
||||
diff <(echo -e "$2" ) <(echo -e "$res")
|
||||
echo $path
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_test() {
|
||||
setup_env
|
||||
$exe init
|
||||
touch $2
|
||||
$exe add $3
|
||||
add_cmp "$1" "$4"
|
||||
}
|
||||
|
||||
add_basics() {
|
||||
add_test "basic" "toto" "toto" "new: toto"
|
||||
}
|
||||
|
||||
add_space() {
|
||||
setup_env
|
||||
$exe init
|
||||
touch 'to to'
|
||||
$exe add 'to to'
|
||||
res=$($exe status --nostyle)
|
||||
add_cmp "space" "new: to to"
|
||||
}
|
||||
|
||||
add_multiple() {
|
||||
add_test "multiple" "titi riri" "titi riri" "new: titi\nnew: riri"
|
||||
}
|
||||
|
||||
add_regex() {
|
||||
add_test "regex" "titi riri" "./*" "new: riri\nnew: titi"
|
||||
}
|
||||
|
||||
add_subdir() {
|
||||
setup_env
|
||||
$exe init
|
||||
mkdir dir
|
||||
touch dir/toto
|
||||
$exe add "./dir/toto"
|
||||
res=$($exe status --nostyle)
|
||||
add_cmp "subdir" "new: dir/toto"
|
||||
}
|
||||
|
||||
add_subdir_regex() {
|
||||
setup_env
|
||||
$exe init
|
||||
mkdir dir
|
||||
touch dir/toto dir/roro
|
||||
$exe add "./dir/*"
|
||||
res=$($exe status --nostyle)
|
||||
add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
|
||||
}
|
||||
|
||||
add_basics
|
||||
add_space
|
||||
add_multiple
|
||||
add_regex
|
||||
add_subdir
|
||||
#add_subdir_regex
|
||||
|
||||
exit 0
|
@ -1,34 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Getting all tests
|
||||
TESTS=$(find -name "*.sh" -not -name "main.sh")
|
||||
if [ $# -ne 0 ]; then
|
||||
TESTS=$(find -name "*$1*" -not -name "main.sh")
|
||||
tests=""
|
||||
for obj in $TESTS; do
|
||||
[ -d $obj ] && tests+=$(find -path "$obj/*.sh" -not -name "main.sh")
|
||||
done;
|
||||
TESTS=$tests
|
||||
fi
|
||||
|
||||
# Executing tests
|
||||
nb_tests=0
|
||||
nb_success=0
|
||||
for test in $TESTS; do
|
||||
nb_tests=$((nb_tests + 1))
|
||||
|
||||
# run file
|
||||
$test
|
||||
exit_code=$?
|
||||
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
nb_success=$((nb_success + 1))
|
||||
elif [ $exit_code -eq 4 ]; then
|
||||
# not executable found, not need to try other tests
|
||||
exit 1
|
||||
else
|
||||
echo "$test failed with exit code $exit_code"
|
||||
fi
|
||||
done;
|
||||
|
||||
echo -e "\nRan $nb_tests tests ($((nb_tests - nb_success)) Failed)"
|
Loading…
Reference in New Issue
Block a user