From 3f9a0541d333c572ccaddb787da3edde22a86d5d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 13 Sep 2024 19:39:17 +0100 Subject: [PATCH] feat: should fetch repo on startup when not cloning We already have a copy of the repo, so we don't clone, but we should perform a `git fetch` to make sure it is up-to-date. --- crates/core/src/git/repository/mod.rs | 8 +++++++- crates/core/src/git/repository/open/oreal.rs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/core/src/git/repository/mod.rs b/crates/core/src/git/repository/mod.rs index fd038f2..c93ab81 100644 --- a/crates/core/src/git/repository/mod.rs +++ b/crates/core/src/git/repository/mod.rs @@ -1,6 +1,7 @@ // use crate::{ git::{ + self, repository::{ open::{OpenRepository, OpenRepositoryLike}, test::TestRepository, @@ -47,7 +48,9 @@ pub fn open( ) -> Result> { let open_repository = if repo_details.gitdir.exists() { info!("Local copy found - opening..."); - repository_factory.open(repo_details)? + let repo = repository_factory.open(repo_details)?; + repo.fetch()?; + repo } else { info!("Local copy not found - cloning..."); repository_factory.git_clone(repo_details)? @@ -117,6 +120,9 @@ pub enum Error { #[error("git clone: {0}")] Clone(String), + #[error("git fetch: {0}")] + FetchError(#[from] git::fetch::Error), + #[error("open: {0}")] Open(String), diff --git a/crates/core/src/git/repository/open/oreal.rs b/crates/core/src/git/repository/open/oreal.rs index dd8e584..136da28 100644 --- a/crates/core/src/git/repository/open/oreal.rs +++ b/crates/core/src/git/repository/open/oreal.rs @@ -67,6 +67,7 @@ impl super::OpenRepositoryLike for RealOpenRepository { #[tracing::instrument(skip_all)] #[cfg(not(tarpaulin_include))] // would require writing to external service fn fetch(&self) -> Result<(), git::fetch::Error> { + info!("Fetching"); gix::command::prepare("/usr/bin/git fetch --prune") .with_context(gix::diff::command::Context { git_dir: Some(