From 70996a2712ededce4876e5714fbedf8e4482af18 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Sat, 20 Jan 2024 12:52:10 +0100 Subject: [PATCH] feat: add fetching with git --- src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c7ced96..201e439 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; use cli::CliArgs; -use tokio::time::sleep; +use tokio::{process::Command, time::sleep}; use walkdir::WalkDir; mod cli; @@ -19,8 +19,32 @@ async fn do_sync_task(args: CliArgs) { .into_iter() .filter_map(|err| err.ok()) { + // this is a proof of concept. // TODO: sync with git2 - println!("TODO: sync {:?}", dir); + let refs_tag = Command::new("git") + .arg("--git-dir") + .arg(dir.clone().into_path()) + .arg("config") + .arg("--get") + .arg("remote.origin.fetch") + .output() + .await + .expect("Failed to retrieve upstream URL") + .stdout; + + if !refs_tag.is_empty() { + let status = Command::new("git") + .arg("--git-dir") + .arg(dir.clone().into_path()) + .arg("fetch") + .arg("--all") + .status() + .await + .expect("Unable to fetch repository"); + if !status.success() { + println!("Succes") + } + } } println!("Sleeping until the next refresh."); -- libgit2 1.7.2