Skip to content

Commit 47b4049

Browse files
Merge pull request #5650 from gitbutlerapp/upstream-integration-refactor
Upstream integration refactor
2 parents 7d63d99 + 60b29e9 commit 47b4049

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

apps/desktop/src/lib/components/IntegrateUpstreamModal.svelte

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import { pxToRem } from '@gitbutler/ui/utils/pxToRem';
3030
import { tick } from 'svelte';
3131
import { SvelteMap } from 'svelte/reactivity';
32-
import type { Readable } from 'svelte/store';
3332
3433
type OperationState = 'inert' | 'loading' | 'completed';
3534
@@ -41,7 +40,7 @@
4140
4241
const forge = getForge();
4342
const upstreamIntegrationService = getContext(UpstreamIntegrationService);
44-
let branchStatuses = $state<Readable<StackStatusesWithBranches | undefined>>();
43+
let branchStatuses = $state<StackStatusesWithBranches | undefined>();
4544
const baseBranchService = getContext(BaseBranchService);
4645
const base = baseBranchService.base;
4746
@@ -55,12 +54,12 @@
5554
let isDivergedResolved = $derived($base?.diverged && !baseResolutionApproach);
5655
5756
$effect(() => {
58-
if ($branchStatuses?.type !== 'updatesRequired') {
57+
if (branchStatuses?.type !== 'updatesRequired') {
5958
statuses = [];
6059
return;
6160
}
6261
63-
const statusesTmp = [...$branchStatuses.subject];
62+
const statusesTmp = [...branchStatuses.subject];
6463
statusesTmp.sort(sortStatusInfo);
6564
6665
// Side effect, refresh results
@@ -85,7 +84,9 @@
8584
// Re-fetch upstream statuses if the target commit oid changes
8685
$effect(() => {
8786
if (targetCommitOid) {
88-
branchStatuses = upstreamIntegrationService.upstreamStatuses(targetCommitOid);
87+
upstreamIntegrationService.upstreamStatuses(targetCommitOid).then((statuses) => {
88+
branchStatuses = statuses;
89+
});
8990
}
9091
});
9192
@@ -122,9 +123,9 @@
122123
123124
export async function show() {
124125
integratingUpstream = 'inert';
125-
branchStatuses = upstreamIntegrationService.upstreamStatuses();
126-
await tick();
126+
branchStatuses = undefined;
127127
modal?.show();
128+
branchStatuses = await upstreamIntegrationService.upstreamStatuses();
128129
}
129130
130131
export const imports = {
@@ -286,8 +287,8 @@
286287
type="submit"
287288
style="pop"
288289
kind="solid"
289-
disabled={isDivergedResolved}
290-
loading={integratingUpstream === 'loading'}>Update workspace</Button
290+
disabled={isDivergedResolved || !branchStatuses}
291+
loading={integratingUpstream === 'loading' || !branchStatuses}>Update workspace</Button
291292
>
292293
</div>
293294
{/snippet}

apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { invoke } from '$lib/backend/ipc';
22
import { VirtualBranchService } from '$lib/vbranches/virtualBranch';
33
import { isDefined } from '@gitbutler/ui/utils/typeguards';
4-
import { derived, readable, type Readable } from 'svelte/store';
4+
import { get } from 'svelte/store';
55
import type { Project } from '$lib/backend/projects';
66
import type { VirtualBranch } from '$lib/vbranches/types';
77

@@ -119,39 +119,34 @@ export class UpstreamIntegrationService {
119119
private virtualBranchService: VirtualBranchService
120120
) {}
121121

122-
upstreamStatuses(targetCommitOid?: string): Readable<StackStatusesWithBranches | undefined> {
123-
const branchStatuses = readable<BranchStatusesResponse | undefined>(undefined, (set) => {
124-
invoke<BranchStatusesResponse>('upstream_integration_statuses', {
125-
projectId: this.project.id,
126-
targetCommitOid
127-
}).then(set);
122+
async upstreamStatuses(targetCommitOid?: string): Promise<StackStatusesWithBranches | undefined> {
123+
const branchStatuses = await invoke<BranchStatusesResponse>('upstream_integration_statuses', {
124+
projectId: this.project.id,
125+
targetCommitOid
128126
});
129127

130-
const branchStatusesWithBranches = derived(
131-
[branchStatuses, this.virtualBranchService.branches],
132-
([branchStatuses, branches]): StackStatusesWithBranches | undefined => {
133-
if (!branchStatuses || !branches) return;
134-
if (branchStatuses.type === 'upToDate') return branchStatuses;
135-
136-
return {
137-
type: 'updatesRequired',
138-
subject: branchStatuses.subject
139-
.map((status) => {
140-
const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]);
141-
142-
if (!stack) return;
143-
144-
return {
145-
stack,
146-
status: status[1]
147-
};
148-
})
149-
.filter(isDefined)
150-
};
151-
}
152-
);
153-
154-
return branchStatusesWithBranches;
128+
const branches = get(this.virtualBranchService.branches);
129+
130+
if (!branchStatuses || !branches) return;
131+
if (branchStatuses.type === 'upToDate') return branchStatuses;
132+
133+
const stackStatusesWithBranches: StackStatusesWithBranches = {
134+
type: 'updatesRequired',
135+
subject: branchStatuses.subject
136+
.map((status) => {
137+
const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]);
138+
139+
if (!stack) return;
140+
141+
return {
142+
stack,
143+
status: status[1]
144+
};
145+
})
146+
.filter(isDefined)
147+
};
148+
149+
return stackStatusesWithBranches;
155150
}
156151

157152
async integrateUpstream(resolutions: Resolution[], baseBranchResolution?: BaseBranchResolution) {

0 commit comments

Comments
 (0)