mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-08-16 15:50:37 +03:00
remove deps towards repository actions from remotes controller
This commit is contained in:
parent
ca2ffaac68
commit
0924b506d7
@ -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.
|
||||
|
@ -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)> {
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user