mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-28 03:55:02 +03:00
move repo related commands out of the project controller
This commit is contained in:
parent
7c7143a570
commit
f9f8addb72
@ -5,12 +5,10 @@ use std::{
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use bstr::BString;
|
||||
|
||||
use super::{storage, storage::UpdateRequest, Project, ProjectId};
|
||||
use crate::error;
|
||||
use crate::projects::AuthKey;
|
||||
use crate::{error, project_repository};
|
||||
use crate::{git::RepositoryExt, project_repository::Config};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Watchers {
|
||||
@ -213,31 +211,4 @@ impl Controller {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_local_config(&self, id: ProjectId, key: &str) -> Result<Option<String>> {
|
||||
let project = self.projects_storage.get(id)?;
|
||||
|
||||
let project_repo = project_repository::ProjectRepo::open(&project)?;
|
||||
let config: Config = project_repo.repo().into();
|
||||
config.get_local(key)
|
||||
}
|
||||
|
||||
pub fn set_local_config(&self, id: ProjectId, key: &str, value: &str) -> Result<()> {
|
||||
let project = self.projects_storage.get(id)?;
|
||||
|
||||
let project_repo = project_repository::ProjectRepo::open(&project)?;
|
||||
let config: Config = project_repo.repo().into();
|
||||
config.set_local(key, value)
|
||||
}
|
||||
|
||||
pub fn check_signing_settings(&self, id: ProjectId) -> Result<bool> {
|
||||
let project = self.projects_storage.get(id)?;
|
||||
|
||||
let repo = project_repository::ProjectRepo::open(&project)?;
|
||||
let signed = repo.repo().sign_buffer(&BString::new("test".into()).into());
|
||||
match signed {
|
||||
Ok(_) => Ok(true),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
crates/gitbutler-repo/src/commands.rs
Normal file
36
crates/gitbutler-repo/src/commands.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use anyhow::Result;
|
||||
use bstr::BString;
|
||||
use gitbutler_core::{
|
||||
git::RepositoryExt,
|
||||
project_repository::{self, Config},
|
||||
projects::Project,
|
||||
};
|
||||
|
||||
pub trait RepoCommands {
|
||||
fn get_local_config(&self, key: &str) -> Result<Option<String>>;
|
||||
fn set_local_config(&self, key: &str, value: &str) -> Result<()>;
|
||||
fn check_signing_settings(&self) -> Result<bool>;
|
||||
}
|
||||
|
||||
impl RepoCommands for Project {
|
||||
fn get_local_config(&self, key: &str) -> Result<Option<String>> {
|
||||
let project_repo = project_repository::ProjectRepo::open(self)?;
|
||||
let config: Config = project_repo.repo().into();
|
||||
config.get_local(key)
|
||||
}
|
||||
|
||||
fn set_local_config(&self, key: &str, value: &str) -> Result<()> {
|
||||
let project_repo = project_repository::ProjectRepo::open(self)?;
|
||||
let config: Config = project_repo.repo().into();
|
||||
config.set_local(key, value)
|
||||
}
|
||||
|
||||
fn check_signing_settings(&self) -> Result<bool> {
|
||||
let repo = project_repository::ProjectRepo::open(self)?;
|
||||
let signed = repo.repo().sign_buffer(&BString::new("test".into()).into());
|
||||
match signed {
|
||||
Ok(_) => Ok(true),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
@ -2,3 +2,6 @@ pub mod rebase;
|
||||
|
||||
mod repository;
|
||||
pub use repository::{LogUntil, RepoActions};
|
||||
|
||||
mod commands;
|
||||
pub use commands::RepoCommands;
|
||||
|
@ -1,6 +1,7 @@
|
||||
pub mod commands {
|
||||
use crate::error::Error;
|
||||
use gitbutler_core::projects::{controller::Controller, ProjectId};
|
||||
use gitbutler_core::projects::{self, ProjectId};
|
||||
use gitbutler_repo::RepoCommands;
|
||||
use tauri::Manager;
|
||||
use tracing::instrument;
|
||||
|
||||
@ -11,7 +12,8 @@ pub mod commands {
|
||||
id: ProjectId,
|
||||
key: &str,
|
||||
) -> Result<Option<String>, Error> {
|
||||
Ok(handle.state::<Controller>().get_local_config(id, key)?)
|
||||
let project = handle.state::<projects::Controller>().get(id)?;
|
||||
Ok(project.get_local_config(key)?)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -22,10 +24,8 @@ pub mod commands {
|
||||
key: &str,
|
||||
value: &str,
|
||||
) -> Result<(), Error> {
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.set_local_config(id, key, value)
|
||||
.map_err(Into::into)
|
||||
let project = handle.state::<projects::Controller>().get(id)?;
|
||||
project.set_local_config(key, value).map_err(Into::into)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -34,9 +34,7 @@ pub mod commands {
|
||||
handle: tauri::AppHandle,
|
||||
id: ProjectId,
|
||||
) -> Result<bool, Error> {
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.check_signing_settings(id)
|
||||
.map_err(Into::into)
|
||||
let project = handle.state::<projects::Controller>().get(id)?;
|
||||
project.check_signing_settings().map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user