diff --git a/packages/tauri/src/virtual_branches/controller.rs b/packages/tauri/src/virtual_branches/controller.rs index f0217d02a..7bee5af6a 100644 --- a/packages/tauri/src/virtual_branches/controller.rs +++ b/packages/tauri/src/virtual_branches/controller.rs @@ -17,6 +17,7 @@ use super::{ RemoteBranchFile, }; +#[derive(Clone)] pub struct Controller { local_data_dir: DataDir, semaphores: Arc>>, @@ -530,4 +531,21 @@ impl Controller { let _permit = semaphore.acquire().await; action() } + + pub async fn flush_vbranches(&self, project_id: ProjectId) -> Result<(), Error> { + self.with_lock(&project_id, || { + self.with_verify_branch(&project_id, |gb_repository, project_repository, _| { + let vbranches = super::list_virtual_branches(gb_repository, project_repository) + .map_err(Error::Other)?; + + for b in &vbranches { + super::flush_vbranch_as_tree(gb_repository, project_repository, &b.id, true) + .map_err(Error::Other)?; + } + + Ok(()) + }) + }) + .await + } } diff --git a/packages/tauri/src/watcher/handlers/flush_session.rs b/packages/tauri/src/watcher/handlers/flush_session.rs index 79fef70b8..267774ffa 100644 --- a/packages/tauri/src/watcher/handlers/flush_session.rs +++ b/packages/tauri/src/watcher/handlers/flush_session.rs @@ -1,12 +1,12 @@ use anyhow::{Context, Result}; -use tauri::AppHandle; +use tauri::{AppHandle, Manager}; use crate::{ gb_repository, paths::DataDir, project_repository, projects::{self, ProjectId}, - sessions, users, + sessions, users, virtual_branches, }; use super::events; @@ -15,6 +15,7 @@ use super::events; pub struct Handler { local_data_dir: DataDir, project_store: projects::Controller, + vbrach_controller: virtual_branches::Controller, users: users::Controller, } @@ -25,6 +26,10 @@ impl TryFrom<&AppHandle> for Handler { Ok(Self { local_data_dir: DataDir::try_from(value)?, project_store: projects::Controller::try_from(value)?, + vbrach_controller: value + .state::() + .inner() + .clone(), users: users::Controller::from(value), }) } @@ -51,15 +56,11 @@ impl Handler { ) .context("failed to open repository")?; - // TODO: fixme - // if let Some(branch_id) = &session.meta.branch { - // virtual_branches::flush_vbranch_as_tree( - // &gb_repo, - // &project_repository, - // branch_id, - // true, - // )?; - // } + futures::executor::block_on(async { + self.vbrach_controller + .flush_vbranches(project_repository.project().id) + .await + })?; let session = gb_repo .flush_session(&project_repository, session, user.as_ref())