From 00157968ed87fc5ce9e40474745ea9ce1967b971 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Wed, 21 Feb 2024 22:10:54 +0200 Subject: [PATCH] Show upstream commits if such exist - component was lost in a refactor, bringing it back - needs a new design, but landing to unblock users --- .../src/lib/components/BranchCard.svelte | 35 ++++++++- .../lib/components/RemoteBranchPreview.svelte | 2 +- .../src/lib/components/UpstreamCommits.svelte | 78 +++++++++++++++++++ gitbutler-ui/src/lib/stores/remoteBranches.ts | 21 +++-- 4 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 gitbutler-ui/src/lib/components/UpstreamCommits.svelte diff --git a/gitbutler-ui/src/lib/components/BranchCard.svelte b/gitbutler-ui/src/lib/components/BranchCard.svelte index 71c2e1b71..5fbce3cb3 100644 --- a/gitbutler-ui/src/lib/components/BranchCard.svelte +++ b/gitbutler-ui/src/lib/components/BranchCard.svelte @@ -4,6 +4,7 @@ import BranchHeader from './BranchHeader.svelte'; import CommitDialog from './CommitDialog.svelte'; import DropzoneOverlay from './DropzoneOverlay.svelte'; + import UpstreamCommits from './UpstreamCommits.svelte'; import ImgThemed from '$lib/components/ImgThemed.svelte'; import Resizer from '$lib/components/Resizer.svelte'; import { projectAiGenAutoBranchNamingEnabled } from '$lib/config/config'; @@ -21,6 +22,7 @@ import { dropzone } from '$lib/dragging/dropzone'; import { persisted } from '$lib/persisted/persisted'; import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/settings/userSettings'; + import { getRemoteBranchData } from '$lib/stores/remoteBranches'; import { computeAddedRemovedByFiles } from '$lib/utils/metrics'; import { filesToOwnership, type Ownership } from '$lib/vbranches/ownership'; import lscache from 'lscache'; @@ -32,7 +34,13 @@ import type { GitHubService } from '$lib/github/service'; import type { Persisted } from '$lib/persisted/persisted'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { BaseBranch, Branch, LocalFile } from '$lib/vbranches/types'; + import type { + BaseBranch, + Branch, + LocalFile, + RemoteBranchData, + RemoteCommit + } from '$lib/vbranches/types'; export let branch: Branch; export let isUnapplied = false; @@ -60,6 +68,20 @@ const laneWidthKey = 'laneWidth_'; let laneWidth: number; + let upstreamData: RemoteBranchData | undefined; + let unknownCommits: RemoteCommit[] | undefined; + + $: upstream = branch.upstream; + $: if (upstream) reloadUpstream(); + + async function reloadUpstream() { + if (upstream?.name) { + upstreamData = await getRemoteBranchData(project.id, upstream.name); + unknownCommits = upstreamData.commits.filter( + (remoteCommit) => !branch.commits.find((commit) => remoteCommit.id == commit.id) + ); + } + } $: if ($commitBoxOpen && branch.files.length === 0) { $commitBoxOpen = false; @@ -188,6 +210,17 @@ } }} /> + {#if unknownCommits && unknownCommits.length > 0 && !branch.conflicted} + + {/if} diff --git a/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte b/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte index 7e1ac6467..8441744c1 100644 --- a/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte +++ b/gitbutler-ui/src/lib/components/RemoteBranchPreview.svelte @@ -66,7 +66,7 @@ {/if} - {#await getRemoteBranchData({ projectId, refname: branch.name }) then branchData} + {#await getRemoteBranchData(projectId, branch.name) then branchData} {#if branchData.commits && branchData.commits.length > 0}
{#each branchData.commits as commit (commit.id)} diff --git a/gitbutler-ui/src/lib/components/UpstreamCommits.svelte b/gitbutler-ui/src/lib/components/UpstreamCommits.svelte new file mode 100644 index 000000000..6023042dc --- /dev/null +++ b/gitbutler-ui/src/lib/components/UpstreamCommits.svelte @@ -0,0 +1,78 @@ + + +{#if upstream} +
+
+
+ {upstream.commits.length} + upstream {upstream.commits.length > 1 ? 'commits' : 'commit'} +
+ +
+
+ {#if upstreamCommitsShown} +
+ {#each upstream.commits as commit (commit.id)} +
+ +
+ {/each} +
+ {#if branchCount > 1} +
+ You have {branchCount} active branches. To merge upstream work, we will unapply all other + branches. +
+ {/if} + +
+
+ {/if} +{/if} diff --git a/gitbutler-ui/src/lib/stores/remoteBranches.ts b/gitbutler-ui/src/lib/stores/remoteBranches.ts index 5c259e507..b254e6d1c 100644 --- a/gitbutler-ui/src/lib/stores/remoteBranches.ts +++ b/gitbutler-ui/src/lib/stores/remoteBranches.ts @@ -24,8 +24,7 @@ export class RemoteBranchService { baseBranch$: Observable ) { this.branches$ = combineLatest([baseBranch$, this.reload$, head$, fetches$]).pipe( - switchMap(() => listRemoteBranches({ projectId })), - // map((branches) => branches.filter((b) => b.ahead != 0)), + switchMap(() => listRemoteBranches(projectId)), shareReplay(1), catchError((e) => { console.log(e); @@ -41,23 +40,21 @@ export class RemoteBranchService { } } -async function listRemoteBranches(params: { projectId: string }): Promise { +async function listRemoteBranches(projectId: string): Promise { const branches = plainToInstance( RemoteBranch, - await invoke('list_remote_branches', params) + await invoke('list_remote_branches', { projectId }) ); return branches; } -export async function getRemoteBranchData(params: { - projectId: string; - refname: string; -}): Promise { - const branchData = plainToInstance( +export async function getRemoteBranchData( + projectId: string, + refname: string +): Promise { + return plainToInstance( RemoteBranchData, - await invoke('get_remote_branch_data', params) + await invoke('get_remote_branch_data', { projectId, refname }) ); - - return branchData; }