diff --git a/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts b/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts index 485d81c47d..002d00a6fc 100644 --- a/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts +++ b/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts @@ -1,5 +1,6 @@ import { invoke } from '$lib/backend/ipc'; import { VirtualBranchService } from '$lib/vbranches/virtualBranch'; +import { isDefined } from '@gitbutler/ui/utils/typeguards'; import { derived, readable, type Readable } from 'svelte/store'; import type { Project } from '$lib/backend/projects'; import type { VirtualBranch } from '$lib/vbranches/types'; @@ -134,20 +135,18 @@ export class UpstreamIntegrationService { return { type: 'updatesRequired', - subject: branchStatuses.subject.map((status) => { - const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]); - - if (!stack) { - throw new Error( - `Could not find stack with id ${status[0]}. Please report this issue and try restarting the app and trying again.` - ); - } - - return { - stack, - status: status[1] - }; - }) + subject: branchStatuses.subject + .map((status) => { + const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]); + + if (!stack) return; + + return { + stack, + status: status[1] + }; + }) + .filter(isDefined) }; } ); diff --git a/crates/gitbutler-branch-actions/src/upstream_integration.rs b/crates/gitbutler-branch-actions/src/upstream_integration.rs index 04cd833e7e..0b7e4dd609 100644 --- a/crates/gitbutler-branch-actions/src/upstream_integration.rs +++ b/crates/gitbutler-branch-actions/src/upstream_integration.rs @@ -148,7 +148,7 @@ enum IntegrationResult { pub struct UpstreamIntegrationContext<'a> { _permission: Option<&'a mut WorktreeWritePermission>, repository: &'a git2::Repository, - virtual_branches_in_workspace: Vec, + stacks_in_workspace: Vec, new_target: git2::Commit<'a>, target: Target, } @@ -178,7 +178,7 @@ impl<'a> UpstreamIntegrationContext<'a> { repository, new_target, target: target.clone(), - virtual_branches_in_workspace: stacks_in_workspace, + stacks_in_workspace, }) } } @@ -325,7 +325,7 @@ pub fn upstream_integration_statuses( repository, new_target, target, - virtual_branches_in_workspace: stacks_in_workspace, + stacks_in_workspace, .. } = context; let old_target = repository.find_commit(target.sha)?; @@ -378,14 +378,18 @@ pub(crate) fn integrate_upstream( bail!("Branches are all up to date") }; - if resolutions.len() != context.virtual_branches_in_workspace.len() { - bail!("Chosen resolutions do not match quantity of applied virtual branches") + if resolutions.len() != context.stacks_in_workspace.len() { + bail!( + "Chosen resolutions do not match quantity of applied virtual branches. {:?} {:?}", + resolutions, + context.stacks_in_workspace + ) } let all_resolutions_are_up_to_date = resolutions.iter().all(|resolution| { // This is O(n^2), in reality, n is unlikly to be more than 3 or 4 let Some(branch) = context - .virtual_branches_in_workspace + .stacks_in_workspace .iter() .find(|branch| branch.id == resolution.branch_id) else { @@ -530,14 +534,14 @@ fn compute_resolutions( repository, new_target, target, - virtual_branches_in_workspace, + stacks_in_workspace, .. } = context; let results = resolutions .iter() .map(|resolution| { - let Some(virtual_branch) = virtual_branches_in_workspace + let Some(virtual_branch) = stacks_in_workspace .iter() .find(|branch| branch.id == resolution.branch_id) else {