mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-09-11 12:25:42 +03:00
Merge pull request #4251 from gitbutlerapp/create-virtual-branch-changes
virtual branches controller - remove state dependency to credentials controller
This commit is contained in:
commit
66d0ba2ac2
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
git::BranchExt,
|
git::{credentials::Helper, BranchExt},
|
||||||
ops::entry::{OperationKind, SnapshotDetails},
|
ops::entry::{OperationKind, SnapshotDetails},
|
||||||
project_repository::Repository,
|
project_repository::Repository,
|
||||||
projects::FetchResult,
|
projects::FetchResult,
|
||||||
@ -21,20 +21,18 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
helper: git::credentials::Helper,
|
|
||||||
|
|
||||||
semaphore: Arc<Semaphore>,
|
semaphore: Arc<Semaphore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Controller {
|
impl Default for Controller {
|
||||||
pub fn new(helper: git::credentials::Helper) -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
semaphore: Arc::new(Semaphore::new(1)),
|
semaphore: Arc::new(Semaphore::new(1)),
|
||||||
|
|
||||||
helper,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Controller {
|
||||||
pub async fn create_commit(
|
pub async fn create_commit(
|
||||||
&self,
|
&self,
|
||||||
project: &Project,
|
project: &Project,
|
||||||
@ -369,7 +367,7 @@ impl Controller {
|
|||||||
askpass: Option<Option<BranchId>>,
|
askpass: Option<Option<BranchId>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
let helper = self.helper.clone();
|
let helper = Helper::default();
|
||||||
let project_repository = open_with_verify(project)?;
|
let project_repository = open_with_verify(project)?;
|
||||||
super::push(&project_repository, branch_id, with_force, &helper, askpass)
|
super::push(&project_repository, branch_id, with_force, &helper, askpass)
|
||||||
}
|
}
|
||||||
@ -426,10 +424,11 @@ impl Controller {
|
|||||||
) -> Result<FetchResult> {
|
) -> Result<FetchResult> {
|
||||||
let project_repository = Repository::open(project)?;
|
let project_repository = Repository::open(project)?;
|
||||||
|
|
||||||
|
let helper = Helper::default();
|
||||||
let remotes = project_repository.remotes()?;
|
let remotes = project_repository.remotes()?;
|
||||||
let fetch_results: Vec<Result<(), _>> = remotes
|
let fetch_results: Vec<Result<(), _>> = remotes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|remote| project_repository.fetch(remote, &self.helper, askpass.clone()))
|
.map(|remote| project_repository.fetch(remote, &helper, askpass.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let project_data_last_fetched = if fetch_results.iter().any(Result::is_err) {
|
let project_data_last_fetched = if fetch_results.iter().any(Result::is_err) {
|
||||||
@ -454,7 +453,7 @@ impl Controller {
|
|||||||
|
|
||||||
// if we have a push remote, let's fetch from this too
|
// if we have a push remote, let's fetch from this too
|
||||||
if let Some(push_remote) = &default_target.push_remote_name {
|
if let Some(push_remote) = &default_target.push_remote_name {
|
||||||
if let Err(err) = project_repository.fetch(push_remote, &self.helper, askpass.clone()) {
|
if let Err(err) = project_repository.fetch(push_remote, &helper, askpass.clone()) {
|
||||||
tracing::warn!(?err, "fetch from push-remote failed");
|
tracing::warn!(?err, "fetch from push-remote failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ use super::*;
|
|||||||
async fn twice() {
|
async fn twice() {
|
||||||
let data_dir = paths::data_dir();
|
let data_dir = paths::data_dir();
|
||||||
let projects = projects::Controller::from_path(data_dir.path());
|
let projects = projects::Controller::from_path(data_dir.path());
|
||||||
let helper = git::credentials::Helper::default();
|
|
||||||
|
|
||||||
let test_project = TestProject::default();
|
let test_project = TestProject::default();
|
||||||
|
|
||||||
let controller = Controller::new(helper);
|
let controller = Controller::default();
|
||||||
|
|
||||||
{
|
{
|
||||||
let project = projects
|
let project = projects
|
||||||
|
@ -32,7 +32,6 @@ impl Default for Test {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let data_dir = paths::data_dir();
|
let data_dir = paths::data_dir();
|
||||||
let projects = projects::Controller::from_path(data_dir.path());
|
let projects = projects::Controller::from_path(data_dir.path());
|
||||||
let helper = git::credentials::Helper::default();
|
|
||||||
|
|
||||||
let test_project = TestProject::default();
|
let test_project = TestProject::default();
|
||||||
let project = projects
|
let project = projects
|
||||||
@ -42,7 +41,7 @@ impl Default for Test {
|
|||||||
Self {
|
Self {
|
||||||
repository: test_project,
|
repository: test_project,
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
controller: Controller::new(helper),
|
controller: Controller::default(),
|
||||||
projects,
|
projects,
|
||||||
project,
|
project,
|
||||||
data_dir: Some(data_dir),
|
data_dir: Some(data_dir),
|
||||||
|
@ -135,9 +135,7 @@ fn main() {
|
|||||||
let git_credentials_controller = git::credentials::Helper::default();
|
let git_credentials_controller = git::credentials::Helper::default();
|
||||||
app_handle.manage(git_credentials_controller.clone());
|
app_handle.manage(git_credentials_controller.clone());
|
||||||
|
|
||||||
app_handle.manage(gitbutler_core::virtual_branches::controller::Controller::new(
|
app_handle.manage(gitbutler_core::virtual_branches::controller::Controller::default());
|
||||||
git_credentials_controller.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let remotes_controller = gitbutler_core::remotes::controller::Controller::new(
|
let remotes_controller = gitbutler_core::remotes::controller::Controller::new(
|
||||||
projects_controller.clone(),
|
projects_controller.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user