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.
This commit is contained in:
parent
a9d17f710b
commit
3f9a0541d3
2 changed files with 8 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
//
|
||||
use crate::{
|
||||
git::{
|
||||
self,
|
||||
repository::{
|
||||
open::{OpenRepository, OpenRepositoryLike},
|
||||
test::TestRepository,
|
||||
|
@ -47,7 +48,9 @@ pub fn open(
|
|||
) -> Result<Box<dyn OpenRepositoryLike>> {
|
||||
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),
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue