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::{
|
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),
|
||||||
|
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue