Compare commits
2 Commits
fa65b6b071
...
d5891a1a93
Author | SHA1 | Date | |
---|---|---|---|
|
d5891a1a93 | ||
|
3207391fdb |
@ -15,7 +15,6 @@ pub mod moved;
|
|||||||
pub mod copied;
|
pub mod copied;
|
||||||
|
|
||||||
pub fn push() {
|
pub fn push() {
|
||||||
// todo err when pushing new folder
|
|
||||||
let _remote = match config::get_remote("origin") {
|
let _remote = match config::get_remote("origin") {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
|
@ -31,7 +31,6 @@ impl PushChange for NewDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn push(&self) -> io::Result<()> {
|
fn push(&self) -> io::Result<()> {
|
||||||
dbg!("pushing new dir");
|
|
||||||
let obj = &self.obj;
|
let obj = &self.obj;
|
||||||
let res = CreateFolder::new()
|
let res = CreateFolder::new()
|
||||||
.set_url(obj.path.to_str().unwrap())
|
.set_url(obj.path.to_str().unwrap())
|
||||||
|
@ -361,7 +361,7 @@ fn print_status(staged_objs: Vec<LocalObj>, objs: Vec<LocalObj>) {
|
|||||||
// not staged files
|
// not staged files
|
||||||
if objs.len() != 0 {
|
if objs.len() != 0 {
|
||||||
println!("Changes not staged for push:");
|
println!("Changes not staged for push:");
|
||||||
println!(" (Use\"nextsync add <file>...\" to update what will be pushed)");
|
println!(" (Use \"nextsync add <file>...\" to update what will be pushed)");
|
||||||
|
|
||||||
for object in objs {
|
for object in objs {
|
||||||
print_object(object);
|
print_object(object);
|
||||||
|
@ -265,7 +265,7 @@ impl Blob {
|
|||||||
pub fn create(&mut self, ts_remote: &str, up_parent: bool) -> io::Result<()> {
|
pub fn create(&mut self, ts_remote: &str, up_parent: bool) -> io::Result<()> {
|
||||||
|
|
||||||
// add blob reference to parent
|
// add blob reference to parent
|
||||||
self.add_ref_to_parent();
|
let _ = self.add_ref_to_parent();
|
||||||
|
|
||||||
if let Err(err) = self.create_blob_ref(ts_remote.clone()) {
|
if let Err(err) = self.create_blob_ref(ts_remote.clone()) {
|
||||||
eprintln!("err: saving blob ref of {}: {}", self.get_relative_file_path().display(), err);
|
eprintln!("err: saving blob ref of {}: {}", self.get_relative_file_path().display(), err);
|
||||||
|
@ -11,7 +11,7 @@ use crate::store::object::{blob::Blob, tree::Tree};
|
|||||||
use crate::commands::status::{State, LocalObj};
|
use crate::commands::status::{State, LocalObj};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
enum ObjType {
|
pub enum ObjType {
|
||||||
TREE,
|
TREE,
|
||||||
BLOB,
|
BLOB,
|
||||||
DEFAULT
|
DEFAULT
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::utils::into::IntoPathBuf;
|
use crate::utils::into::IntoPathBuf;
|
||||||
use crate::store::object::object::Obj;
|
use crate::store::object::object::Obj;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use crate::store::object::update_dates;
|
||||||
use crate::store::object::object::ObjMethods;
|
use crate::store::object::object::ObjMethods;
|
||||||
use std::fs::{self, File, OpenOptions};
|
use std::fs::{self, File, OpenOptions};
|
||||||
use std::io::{self, BufRead, BufReader, Write, Lines};
|
use std::io::{self, BufRead, BufReader, Write, Lines};
|
||||||
@ -80,18 +81,32 @@ impl Tree {
|
|||||||
|
|
||||||
pub fn create(&self, date: &str, up_parent: bool) -> io::Result<()> {
|
pub fn create(&self, date: &str, up_parent: bool) -> io::Result<()> {
|
||||||
// add tree reference to parent
|
// add tree reference to parent
|
||||||
self.add_ref_to_parent();
|
let _ = self.add_ref_to_parent();
|
||||||
|
|
||||||
// create tree object
|
// create tree object
|
||||||
let mut content = format!("{} {}", self.get_name(), date);
|
let content = format!("{} {}", self.get_name(), date);
|
||||||
//create_obj(self.get_hash_path(), &content)?;
|
|
||||||
// todo!();
|
// create parent dir if needed
|
||||||
|
let mut obj_path = self.get_obj_path();
|
||||||
|
obj_path.pop();
|
||||||
|
if !obj_path.exists() {
|
||||||
|
fs::create_dir_all(obj_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open ref file
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.create_new(true)
|
||||||
|
.write(true)
|
||||||
|
.open(self.get_obj_path())?;
|
||||||
|
|
||||||
// update date for all parent
|
// update date for all parent
|
||||||
//todo!();
|
if up_parent {
|
||||||
//if up_parent {
|
if let Err(err) = update_dates(self.get_relative_file_path(), date) {
|
||||||
// update_dates(path, date)?;
|
eprintln!("err: updating parent date of {}: {}", self.get_relative_file_path().display(), err);
|
||||||
//}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(file, "{}", content)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
|||||||
}
|
}
|
||||||
assert!(line.find(str).is_none());
|
assert!(line.find(str).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
use utils::{utils::*, server::ServerTest, client::ClientTest};
|
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -19,6 +19,9 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "foo"));
|
assert!(server.has_file("file1", "foo"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -38,6 +41,10 @@ mod push_tests {
|
|||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "foo"));
|
assert!(server.has_file("file1", "foo"));
|
||||||
|
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
// change content of file1
|
// change content of file1
|
||||||
let _ = client.add_file("file1", "bar");
|
let _ = client.add_file("file1", "bar");
|
||||||
client.run_cmd_ok("add file1");
|
client.run_cmd_ok("add file1");
|
||||||
@ -45,6 +52,10 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "bar"));
|
assert!(server.has_file("file1", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -65,6 +76,11 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("dir/file2", "bar"));
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(staged, "foo");
|
||||||
|
lines_should_not_contains(not_staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(not_staged, "foo");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -85,6 +101,11 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("dir/file2", "bar"));
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(staged, "foo");
|
||||||
|
lines_should_not_contains(not_staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(not_staged, "foo");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -107,6 +128,9 @@ mod push_tests {
|
|||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "foo"));
|
assert!(server.has_file("file1", "foo"));
|
||||||
assert!(server.has_file("dir/file2", "bar"));
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
assert!(staged.len() == 0);
|
||||||
|
assert!(not_staged.len() == 0);
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
|
@ -6,3 +6,6 @@ pub mod client;
|
|||||||
|
|
||||||
#[path = "utils/utils.rs"]
|
#[path = "utils/utils.rs"]
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
#[path = "utils/status_utils.rs"]
|
||||||
|
pub mod status_utils;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::str;
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@ -90,4 +91,46 @@ impl ClientTest {
|
|||||||
file.write_all(content.as_bytes())?;
|
file.write_all(content.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get the files given by the status command in two vector (staged and not staged)
|
||||||
|
pub fn get_status(&mut self) -> (Vec<String>, Vec<String>) {
|
||||||
|
let out = self.run_cmd("status");
|
||||||
|
|
||||||
|
let lines: Vec<String> = str::from_utf8(&out.stdout)
|
||||||
|
.unwrap()
|
||||||
|
.split("\n")
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut staged = vec![];
|
||||||
|
let mut not_staged = vec![];
|
||||||
|
let mut in_staged = true;
|
||||||
|
let mut counter = 0;
|
||||||
|
for line in lines {
|
||||||
|
if line.find("not staged").is_some() {
|
||||||
|
in_staged = false;
|
||||||
|
counter = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip two first line as there are not files
|
||||||
|
if counter < 2 {
|
||||||
|
counter += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if line == String::from("") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if in_staged {
|
||||||
|
staged.push(line);
|
||||||
|
} else {
|
||||||
|
not_staged.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (staged, not_staged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
9
tests/utils/status_utils.rs
Normal file
9
tests/utils/status_utils.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
pub fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
||||||
|
for line in lines {
|
||||||
|
if line.find(str).is_some() {
|
||||||
|
eprintln!("'{}' found in '{}'", str, line);
|
||||||
|
}
|
||||||
|
assert!(line.find(str).is_none());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user