Skip to content

Commit

Permalink
Merge pull request #5649 from gitbutlerapp/upstream-integration-logging
Browse files Browse the repository at this point in the history
Upstream integration logging
  • Loading branch information
krlvi authored Nov 22, 2024
2 parents 637133c + d7f2314 commit 42a4f5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
27 changes: 13 additions & 14 deletions apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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)
};
}
);
Expand Down
20 changes: 12 additions & 8 deletions crates/gitbutler-branch-actions/src/upstream_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ enum IntegrationResult {
pub struct UpstreamIntegrationContext<'a> {
_permission: Option<&'a mut WorktreeWritePermission>,
repository: &'a git2::Repository,
virtual_branches_in_workspace: Vec<Stack>,
stacks_in_workspace: Vec<Stack>,
new_target: git2::Commit<'a>,
target: Target,
}
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<'a> UpstreamIntegrationContext<'a> {
repository,
new_target,
target: target.clone(),
virtual_branches_in_workspace: stacks_in_workspace,
stacks_in_workspace,
})
}
}
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 42a4f5d

Please sign in to comment.