Compare commits
No commits in common. "d5891a1a93bd689d396e42fc548cbdec579142b7" and "fa65b6b071242cb33938413e341e11997f33ce5f" have entirely different histories.
d5891a1a93
...
fa65b6b071
@ -15,6 +15,7 @@ pub mod moved;
|
||||
pub mod copied;
|
||||
|
||||
pub fn push() {
|
||||
// todo err when pushing new folder
|
||||
let _remote = match config::get_remote("origin") {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
|
@ -31,6 +31,7 @@ impl PushChange for NewDir {
|
||||
}
|
||||
|
||||
fn push(&self) -> io::Result<()> {
|
||||
dbg!("pushing new dir");
|
||||
let obj = &self.obj;
|
||||
let res = CreateFolder::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
|
@ -361,7 +361,7 @@ fn print_status(staged_objs: Vec<LocalObj>, objs: Vec<LocalObj>) {
|
||||
// not staged files
|
||||
if objs.len() != 0 {
|
||||
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 {
|
||||
print_object(object);
|
||||
|
@ -265,7 +265,7 @@ impl Blob {
|
||||
pub fn create(&mut self, ts_remote: &str, up_parent: bool) -> io::Result<()> {
|
||||
|
||||
// add blob reference to parent
|
||||
let _ = self.add_ref_to_parent();
|
||||
self.add_ref_to_parent();
|
||||
|
||||
if let Err(err) = self.create_blob_ref(ts_remote.clone()) {
|
||||
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};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum ObjType {
|
||||
enum ObjType {
|
||||
TREE,
|
||||
BLOB,
|
||||
DEFAULT
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::utils::into::IntoPathBuf;
|
||||
use crate::store::object::object::Obj;
|
||||
use std::path::PathBuf;
|
||||
use crate::store::object::update_dates;
|
||||
use crate::store::object::object::ObjMethods;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{self, BufRead, BufReader, Write, Lines};
|
||||
@ -81,32 +80,18 @@ impl Tree {
|
||||
|
||||
pub fn create(&self, date: &str, up_parent: bool) -> io::Result<()> {
|
||||
// add tree reference to parent
|
||||
let _ = self.add_ref_to_parent();
|
||||
self.add_ref_to_parent();
|
||||
|
||||
// create tree object
|
||||
let content = format!("{} {}", self.get_name(), date);
|
||||
|
||||
// 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())?;
|
||||
let mut content = format!("{} {}", self.get_name(), date);
|
||||
//create_obj(self.get_hash_path(), &content)?;
|
||||
// todo!();
|
||||
|
||||
// update date for all parent
|
||||
if up_parent {
|
||||
if let Err(err) = update_dates(self.get_relative_file_path(), date) {
|
||||
eprintln!("err: updating parent date of {}: {}", self.get_relative_file_path().display(), err);
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(file, "{}", content)?;
|
||||
//todo!();
|
||||
//if up_parent {
|
||||
// update_dates(path, date)?;
|
||||
//}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
||||
}
|
||||
assert!(line.find(str).is_none());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
mod utils;
|
||||
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||
use utils::{utils::*, server::ServerTest, client::ClientTest};
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
@ -19,9 +19,6 @@ mod push_tests {
|
||||
|
||||
// tests
|
||||
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();
|
||||
server.clean();
|
||||
@ -41,10 +38,6 @@ mod push_tests {
|
||||
// tests
|
||||
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
|
||||
let _ = client.add_file("file1", "bar");
|
||||
client.run_cmd_ok("add file1");
|
||||
@ -52,10 +45,6 @@ mod push_tests {
|
||||
|
||||
// tests
|
||||
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();
|
||||
server.clean();
|
||||
@ -76,11 +65,6 @@ mod push_tests {
|
||||
|
||||
// tests
|
||||
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();
|
||||
server.clean();
|
||||
@ -101,11 +85,6 @@ mod push_tests {
|
||||
|
||||
// tests
|
||||
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();
|
||||
server.clean();
|
||||
@ -128,9 +107,6 @@ mod push_tests {
|
||||
// tests
|
||||
assert!(server.has_file("file1", "foo"));
|
||||
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();
|
||||
server.clean();
|
||||
|
@ -6,6 +6,3 @@ pub mod client;
|
||||
|
||||
#[path = "utils/utils.rs"]
|
||||
pub mod utils;
|
||||
|
||||
#[path = "utils/status_utils.rs"]
|
||||
pub mod status_utils;
|
||||
|
@ -1,4 +1,3 @@
|
||||
use std::str;
|
||||
use std::process::{Command, Output};
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
@ -91,46 +90,4 @@ impl ClientTest {
|
||||
file.write_all(content.as_bytes())?;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
|
||||
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