Skip to content

Commit 75c891b

Browse files
committed
Show split branch option only when branch not conflicted
Enhance the split branches experience: - Only show the option to split the branch if the branch is not conflicted, by evaluating the isBranchConflicted status with ReduxResult. - Add isBranchConflicted method to stackService to query branch conflict state easily from context menu components. This makes the split branch menu option conditional on the branch's conflict status, improving clarity and preventing unsupported actions.
1 parent a8c9849 commit 75c891b

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

apps/desktop/src/components/v3/FileContextMenu.svelte

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!-- This is a V3 replacement for `FileContextMenu.svelte` -->
22
<script lang="ts">
3+
import ReduxResult from '$components/ReduxResult.svelte';
34
import { ActionService } from '$lib/actions/actionService.svelte';
45
import { AIService } from '$lib/ai/service';
56
import { writeClipboard } from '$lib/backend/clipboard';
@@ -75,6 +76,10 @@
7576
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
7677
const isUncommitted = $derived(selectionId.type === 'worktree');
7778
const isBranchFiles = $derived(selectionId.type === 'branch');
79+
const selectionBranchName = $derived(
80+
selectionId.type === 'branch' ? selectionId.branchName : undefined
81+
);
82+
7883
const user = getContextStore(User);
7984
const isAdmin = $derived($user.role === 'admin');
8085
@@ -380,21 +385,33 @@
380385
}
381386
}}
382387
/>
383-
{#if isBranchFiles && isAdmin}
384-
<ContextMenuItem
385-
label="Split off changes"
386-
onclick={() => {
387-
split(changes);
388-
contextMenu.close();
389-
}}
390-
/>
391-
<ContextMenuItem
392-
label="Split into dependent branch"
393-
onclick={() => {
394-
splitIntoDependentBranch(changes);
395-
contextMenu.close();
396-
}}
397-
/>
388+
389+
{#if isBranchFiles && stackId && selectionBranchName && isAdmin}
390+
{@const branchIsConflicted = stackService.isBranchConflicted(
391+
projectId,
392+
stackId,
393+
selectionBranchName
394+
)}
395+
<ReduxResult {projectId} result={branchIsConflicted?.current}>
396+
{#snippet children(isConflicted)}
397+
{#if isConflicted === false}
398+
<ContextMenuItem
399+
label="Split off changes"
400+
onclick={() => {
401+
split(changes);
402+
contextMenu.close();
403+
}}
404+
/>
405+
<ContextMenuItem
406+
label="Split into dependent branch"
407+
onclick={() => {
408+
splitIntoDependentBranch(changes);
409+
contextMenu.close();
410+
}}
411+
/>
412+
{/if}
413+
{/snippet}
414+
</ReduxResult>
398415
{/if}
399416
{/if}
400417
</ContextMenuSection>

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,18 @@ export class StackService {
747747
return await this.api.endpoints.newBranchName.fetch({ projectId }, { forceRefetch: true });
748748
}
749749

750+
isBranchConflicted(projectId: string, stackId: string, branchName: string) {
751+
return this.api.endpoints.stackDetails.useQuery(
752+
{ projectId, stackId },
753+
{
754+
transform: ({ branchDetails }) => {
755+
const branch = branchDetailsSelectors.selectById(branchDetails, branchName);
756+
return branch?.isConflicted ?? false;
757+
}
758+
}
759+
);
760+
}
761+
750762
async normalizeBranchName(name: string) {
751763
return await this.api.endpoints.normalizeBranchName.fetch({ name }, { forceRefetch: true });
752764
}

0 commit comments

Comments
 (0)