mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-25 02:26:14 +03:00
UI: the branch preview now has a button to delete local branches
This commit is contained in:
parent
e295da03a1
commit
63b43b3f23
@ -8,6 +8,7 @@
|
||||
import { BranchController } from '$lib/vbranches/branchController';
|
||||
import Icon from '@gitbutler/ui/icon/Icon.svelte';
|
||||
import Button from '@gitbutler/ui/inputs/Button.svelte';
|
||||
import Modal from '@gitbutler/ui/modal/Modal.svelte';
|
||||
import { tooltip } from '@gitbutler/ui/utils/tooltip';
|
||||
import type { PullRequest } from '$lib/gitHost/interface/types';
|
||||
import type { Branch } from '$lib/vbranches/types';
|
||||
@ -26,6 +27,8 @@
|
||||
$: gitHostBranch = upstream ? $gitHost?.branch(upstream) : undefined;
|
||||
|
||||
let isApplying = false;
|
||||
let isDeleting = false;
|
||||
let deleteBranchModal: Modal;
|
||||
</script>
|
||||
|
||||
<div class="header__wrapper">
|
||||
@ -110,12 +113,56 @@
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
<Button
|
||||
style="ghost"
|
||||
outline
|
||||
help="Deletes the local branch. If this branch is also present on a remote, it will not be deleted there."
|
||||
icon="bin-small"
|
||||
loading={isDeleting}
|
||||
disabled={!localBranch}
|
||||
onclick={async () => {
|
||||
if (localBranch) {
|
||||
console.log(JSON.stringify(localBranch));
|
||||
deleteBranchModal.show(branch);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete locally
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header__top-overlay" data-tauri-drag-region></div>
|
||||
</div>
|
||||
|
||||
<Modal width="small" title="Delete branch" bind:this={deleteBranchModal}>
|
||||
{#snippet children(branch)}
|
||||
Are you sure you want to delete <code class="code-string">{branch.name}</code>?
|
||||
{/snippet}
|
||||
{#snippet controls(close)}
|
||||
<Button style="ghost" outline onclick={close}>Cancel</Button>
|
||||
<Button
|
||||
style="error"
|
||||
kind="solid"
|
||||
onclick={async () => {
|
||||
try {
|
||||
await branchController.deleteLocalBranch(branch.name);
|
||||
} catch (e) {
|
||||
const err = 'Failed to delete local branch';
|
||||
error(err);
|
||||
console.error(err, e);
|
||||
} finally {
|
||||
isDeleting = false;
|
||||
close();
|
||||
}
|
||||
goto(`/${project.id}/board`);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style lang="postcss">
|
||||
.header__wrapper {
|
||||
z-index: var(--z-lifted);
|
||||
|
@ -293,6 +293,24 @@ You can find them in the 'Branches' sidebar in order to resolve conflicts.`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a branch local reference and any associated virtual branch if applicable and updates the list of branches know to the UI.
|
||||
* @param branch The reference name of the branch to delete (including the `refs/heads/` prefix).
|
||||
*/
|
||||
async deleteLocalBranch(branch: string) {
|
||||
try {
|
||||
await invoke<void>('delete_local_branch', {
|
||||
projectId: this.projectId,
|
||||
refname: branch
|
||||
});
|
||||
} catch (err) {
|
||||
showError('Failed to delete local branch', err);
|
||||
} finally {
|
||||
this.remoteBranchService.refresh();
|
||||
this.baseBranchService.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
async markResolved(path: string) {
|
||||
try {
|
||||
await invoke<void>('mark_resolved', { projectId: this.projectId, path });
|
||||
|
Loading…
Reference in New Issue
Block a user