mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
Tries to fix the last issue of repo sync
Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
parent
940bcffcc0
commit
f6d0bfbc46
3 changed files with 41 additions and 17 deletions
|
|
@ -148,7 +148,7 @@ pub fn main(uri: String, yes_flag: bool, branch: &Option<String>) -> Result<()>
|
|||
&to.clone().to_str().unwrap()
|
||||
);
|
||||
|
||||
eprintln!("=> {}", &complete_local_path);
|
||||
debug!("=> {}", &complete_local_path);
|
||||
|
||||
fs::create_dir_all(&local_to_folder).unwrap_or(());
|
||||
fs::copy(&from, &complete_local_path).with_context(|| {
|
||||
|
|
|
|||
|
|
@ -49,15 +49,19 @@ fn synchronize(cheat_repo: String) -> Result<()> {
|
|||
let git_files = all_git_files(&cheat_path);
|
||||
let mut cheat_dirs: Vec<String> = Vec::new();
|
||||
|
||||
// Now that the folder has been cleaned, we need to fetch the latest HEAD available.
|
||||
git::fetch_origin(&cheat_repo)?;
|
||||
// git::pull(&cheat_repo)?;
|
||||
let status = git::diff(&cheat_repo)?;
|
||||
|
||||
eprintln!("Status: {:?}", status.code());
|
||||
return Ok(());
|
||||
|
||||
// We delete them since they are now out of tree
|
||||
for file in cheat_files.iter() {
|
||||
fs::remove_file(&file)?;
|
||||
}
|
||||
|
||||
// Now that the folder has been cleaned, we need to fetch the latest HEAD available.
|
||||
git::fetch_origin(&cheat_repo)?;
|
||||
git::pull(&cheat_repo)?;
|
||||
|
||||
// Now that we've checkout the repository to the latest commit,
|
||||
// we might have a surplus of "illegal" files (i.e. files that should not be present in a cheatsheet repository).
|
||||
//
|
||||
|
|
@ -119,16 +123,26 @@ fn synchronize(cheat_repo: String) -> Result<()> {
|
|||
fs::copy(cheat_file, format!("{}/{}", cheat_repo, filename))?;
|
||||
}
|
||||
|
||||
let mut last_path: String = "".to_string();
|
||||
|
||||
for _dir in cheat_dirs {
|
||||
eprintln!("DIR: {}", &_dir);
|
||||
eprintln!("DIR: {}, {}", &_dir, &_dir.contains(&last_path));
|
||||
|
||||
// TODO: Fix this loop trying to delete an already deleted path (i.e. the parent has been deleted)
|
||||
match fs::exists(&_dir) {
|
||||
Ok(_) => {
|
||||
fs::remove_dir_all(&_dir)?;
|
||||
}
|
||||
Err(_) => {
|
||||
if _dir.contains(&last_path) {
|
||||
eprintln!("Found: {}", &_dir);
|
||||
|
||||
continue
|
||||
} else {
|
||||
// TODO: Fix this loop trying to delete an already deleted path (i.e. the parent has been deleted)
|
||||
match fs::exists(&_dir) {
|
||||
Ok(_) => {
|
||||
fs::remove_dir_all(&_dir)?;
|
||||
|
||||
last_path = _dir.to_owned();
|
||||
}
|
||||
Err(_) => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::common::shell::ShellSpawnError;
|
||||
use crate::prelude::*;
|
||||
use std::process::Command;
|
||||
use std::process::{Command, ExitStatus};
|
||||
|
||||
pub fn shallow_clone(uri: &str, target: &str, branch: &Option<String>) -> Result<()> {
|
||||
// If we target a specific ref, we add the parameter inside the arguments to call
|
||||
|
|
@ -87,22 +87,32 @@ pub fn fetch_origin(uri: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
/// Restores/Discards any local changes then pulls from the origin.
|
||||
pub fn pull(uri: &str) -> Result<()> {
|
||||
pub fn pull(uri: &str) -> Result<ExitStatus> {
|
||||
Command::new("git")
|
||||
.current_dir(&uri)
|
||||
.args(["restore", "./"])
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Command::new("git")
|
||||
Ok(Command::new("git")
|
||||
.current_dir(uri)
|
||||
.args(["pull", "origin"])
|
||||
.spawn()?
|
||||
.wait()
|
||||
.expect("Unable to git pull");
|
||||
Ok(())
|
||||
.expect("Unable to git pull"))
|
||||
}
|
||||
|
||||
pub fn diff(uri: &str) -> Result<ExitStatus> {
|
||||
eprintln!("git --git-dir=\"{}\" diff --quiet", &uri);
|
||||
|
||||
Ok(Command::new("git")
|
||||
.current_dir(&uri)
|
||||
.args(["diff", "--quiet"])
|
||||
.spawn()?
|
||||
.wait()?)
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue