remove deps towards repository actions from remotes controller

This commit is contained in:
Kiril Videlov 2024-07-07 22:38:33 +02:00
parent ca2ffaac68
commit 0924b506d7
No known key found for this signature in database
GPG Key ID: A4C733025427C471
3 changed files with 15 additions and 9 deletions

View File

@ -20,6 +20,7 @@ use std::os::windows::process::CommandExt;
///
/// For now, it collects useful methods from `gitbutler-core::git::Repository`
pub trait RepositoryExt {
fn remotes_as_string(&self) -> Result<Vec<String>>;
/// Open a new in-memory repository and executes the provided closure using it.
/// This is useful when temporary objects are created for the purpose of comparing or getting a diff.
/// Note that it's the odb that is in-memory, not the working directory.
@ -354,6 +355,15 @@ impl RepositoryExt for Repository {
}
Err(anyhow::anyhow!("No signing key found"))
}
fn remotes_as_string(&self) -> Result<Vec<String>> {
Ok(self.remotes().map(|string_array| {
string_array
.iter()
.filter_map(|s| s.map(String::from))
.collect()
})?)
}
}
/// Signs the buffer with the configured gpg key, returning the signature.

View File

@ -89,7 +89,6 @@ impl ProjectRepo {
}
pub trait RepoActions {
fn add_remote(&self, name: &str, url: &str) -> Result<()>;
fn remotes(&self) -> Result<Vec<String>>;
fn fetch(
&self,
@ -684,11 +683,6 @@ impl RepoActions for ProjectRepo {
.collect()
})?)
}
fn add_remote(&self, name: &str, url: &str) -> Result<()> {
self.git_repository.remote(name, url)?;
Ok(())
}
}
fn signatures(project_repo: &ProjectRepo) -> Result<(git2::Signature, git2::Signature)> {

View File

@ -1,7 +1,8 @@
use anyhow::Result;
use crate::{
project_repository::{self, RepoActions},
git::RepositoryExt,
project_repository,
projects::{self, ProjectId},
};
@ -19,13 +20,14 @@ impl Controller {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::ProjectRepo::open(&project)?;
project_repository.remotes()
project_repository.repo().remotes_as_string()
}
pub async fn add_remote(&self, project_id: ProjectId, name: &str, url: &str) -> Result<()> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::ProjectRepo::open(&project)?;
project_repository.add_remote(name, url)
project_repository.repo().remote(name, url)?;
Ok(())
}
}