Show the push button when there are differences after undoing commits and the branch requires force pushing

This commit is contained in:
Caleb Owens 2024-02-16 14:31:36 +00:00 committed by Kiril Videlov
parent f708c1568e
commit 5740c16ee8
3 changed files with 80 additions and 58 deletions

View File

@ -25,10 +25,13 @@
$: headCommit = branch.commits[0]; $: headCommit = branch.commits[0];
$: commits = type == 'upstream' ? [] : branch.commits.filter((c) => c.status == type); $: commits = type == 'upstream' ? [] : branch.commits.filter((c) => c.status == type);
$: hasCommits = commits && commits.length > 0;
$: remoteRequiresForcePush = type === 'remote' && branch.requiresForce;
let expanded = true; let expanded = true;
</script> </script>
{#if commits && commits.length > 0} {#if hasCommits || remoteRequiresForcePush }
<div <div
class="commit-list card" class="commit-list card"
class:upstream={type == 'upstream'} class:upstream={type == 'upstream'}

View File

@ -75,7 +75,9 @@
<PushButton <PushButton
wide wide
isLoading={isPushing || $githubServiceState$?.busy} isLoading={isPushing || $githubServiceState$?.busy}
isPushed={type == 'remote'} isPushed={type == 'remote' && !branch.requiresForce}
requiresForcePush={branch.requiresForce}
isPr={$pr$}
{projectId} {projectId}
githubEnabled={$githubEnabled$} githubEnabled={$githubEnabled$}
on:trigger={async (e) => { on:trigger={async (e) => {

View File

@ -7,6 +7,7 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import Button from '$lib/components/Button.svelte';
import DropDownButton from '$lib/components/DropDownButton.svelte'; import DropDownButton from '$lib/components/DropDownButton.svelte';
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte'; import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte'; import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte';
@ -20,6 +21,8 @@
export let isLoading = false; export let isLoading = false;
export let githubEnabled: boolean; export let githubEnabled: boolean;
export let wide = false; export let wide = false;
export let requiresForcePush = false;
export let isPr = false;
function defaultAction(projectId: string): Persisted<BranchAction> { function defaultAction(projectId: string): Persisted<BranchAction> {
const key = 'projectDefaultAction_'; const key = 'projectDefaultAction_';
@ -49,8 +52,21 @@
} }
return preferredAction; return preferredAction;
} }
$: pushLabel = requiresForcePush ? 'Force push to remote' : 'Push to remote'
</script> </script>
{#if isPr && requiresForcePush }
<Button
color="primary"
kind="outlined"
{wide}
disabled={isPushed}
on:click={() => {
dispatch('trigger', { action: BranchAction.Push });
}}>{pushLabel}</Button
>
{:else if !isPr }
<DropDownButton <DropDownButton
color="primary" color="primary"
kind="outlined" kind="outlined"
@ -88,7 +104,7 @@
<ContextMenuSection> <ContextMenuSection>
<ContextMenuItem <ContextMenuItem
id="push" id="push"
label="Push to remote" label={pushLabel}
selected={action == BranchAction.Push} selected={action == BranchAction.Push}
disabled={isPushed} disabled={isPushed}
/> />
@ -107,3 +123,4 @@
</ContextMenuSection> </ContextMenuSection>
</ContextMenu> </ContextMenu>
</DropDownButton> </DropDownButton>
{/if}