feat: should fetch repo on startup when not cloning
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
Rust / build (push) Failing after 4m11s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

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.
This commit is contained in:
Paul Campbell 2024-09-13 19:39:17 +01:00
parent 048111202a
commit 39dbe580da
2 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,7 @@
// //
use crate::{ use crate::{
git::{ git::{
self,
repository::{ repository::{
open::{OpenRepository, OpenRepositoryLike}, open::{OpenRepository, OpenRepositoryLike},
test::TestRepository, test::TestRepository,
@ -47,7 +48,9 @@ pub fn open(
) -> Result<Box<dyn OpenRepositoryLike>> { ) -> Result<Box<dyn OpenRepositoryLike>> {
let open_repository = if repo_details.gitdir.exists() { let open_repository = if repo_details.gitdir.exists() {
info!("Local copy found - opening..."); info!("Local copy found - opening...");
repository_factory.open(repo_details)? let repo = repository_factory.open(repo_details)?;
repo.fetch()?;
repo
} else { } else {
info!("Local copy not found - cloning..."); info!("Local copy not found - cloning...");
repository_factory.git_clone(repo_details)? repository_factory.git_clone(repo_details)?
@ -117,6 +120,9 @@ pub enum Error {
#[error("git clone: {0}")] #[error("git clone: {0}")]
Clone(String), Clone(String),
#[error("git fetch: {0}")]
FetchError(#[from] git::fetch::Error),
#[error("open: {0}")] #[error("open: {0}")]
Open(String), Open(String),

View file

@ -67,6 +67,7 @@ impl super::OpenRepositoryLike for RealOpenRepository {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
#[cfg(not(tarpaulin_include))] // would require writing to external service #[cfg(not(tarpaulin_include))] // would require writing to external service
fn fetch(&self) -> Result<(), git::fetch::Error> { fn fetch(&self) -> Result<(), git::fetch::Error> {
info!("Fetching");
gix::command::prepare("/usr/bin/git fetch --prune") gix::command::prepare("/usr/bin/git fetch --prune")
.with_context(gix::diff::command::Context { .with_context(gix::diff::command::Context {
git_dir: Some( git_dir: Some(