From d79095533df35b56637a48f2874179cd69d06c6a Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sat, 11 Jun 2022 23:54:43 +0200 Subject: [PATCH] Added option to delete remote branch from log --- .../kotlin/app/ui/context_menu/BranchContextMenu.kt | 11 ++++++++++- src/main/kotlin/app/ui/log/Log.kt | 5 +++++ src/main/kotlin/app/viewmodels/LogViewModel.kt | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/ui/context_menu/BranchContextMenu.kt b/src/main/kotlin/app/ui/context_menu/BranchContextMenu.kt index e346460..24b9f48 100644 --- a/src/main/kotlin/app/ui/context_menu/BranchContextMenu.kt +++ b/src/main/kotlin/app/ui/context_menu/BranchContextMenu.kt @@ -16,6 +16,7 @@ fun branchContextMenuItems( onMergeBranch: () -> Unit, onRebaseBranch: () -> Unit, onDeleteBranch: () -> Unit, + onDeleteRemoteBranch: () -> Unit = {}, onPushToRemoteBranch: () -> Unit, onPullFromRemoteBranch: () -> Unit, ): List { @@ -27,7 +28,7 @@ fun branchContextMenuItems( onClick = onCheckoutBranch ) ) - if(currentBranch != null && !currentBranch.isHead) { + if (currentBranch != null && !currentBranch.isHead) { add( ContextMenuItem( label = "Merge branch", @@ -64,5 +65,13 @@ fun branchContextMenuItems( ) ) } + if (!isLocal) { + add( + ContextMenuItem( + label = "Delete remote branch", + onClick = onDeleteRemoteBranch + ), + ) + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/ui/log/Log.kt b/src/main/kotlin/app/ui/log/Log.kt index 2a462a6..7aac413 100644 --- a/src/main/kotlin/app/ui/log/Log.kt +++ b/src/main/kotlin/app/ui/log/Log.kt @@ -742,6 +742,7 @@ fun CommitLine( onCheckoutRef = { ref -> logViewModel.checkoutRef(ref) }, onMergeBranch = { ref -> onMergeBranch(ref) }, onDeleteBranch = { ref -> logViewModel.deleteBranch(ref) }, + onDeleteRemoteBranch = { ref -> logViewModel.deleteRemoteBranch(ref) }, onDeleteTag = { ref -> logViewModel.deleteTag(ref) }, onRebaseBranch = { ref -> onRebaseBranch(ref) }, onPushRemoteBranch = { ref -> logViewModel.pushToRemoteBranch(ref) }, @@ -762,6 +763,7 @@ fun CommitMessage( onCheckoutRef: (ref: Ref) -> Unit, onMergeBranch: (ref: Ref) -> Unit, onDeleteBranch: (ref: Ref) -> Unit, + onDeleteRemoteBranch: (ref: Ref) -> Unit, onRebaseBranch: (ref: Ref) -> Unit, onDeleteTag: (ref: Ref) -> Unit, onPushRemoteBranch: (ref: Ref) -> Unit, @@ -797,6 +799,7 @@ fun CommitMessage( onCheckoutBranch = { onCheckoutRef(ref) }, onMergeBranch = { onMergeBranch(ref) }, onDeleteBranch = { onDeleteBranch(ref) }, + onDeleteRemoteBranch = { onDeleteRemoteBranch(ref) }, onRebaseBranch = { onRebaseBranch(ref) }, onPullRemoteBranch = { onPullRemoteBranch(ref) }, onPushRemoteBranch = { onPushRemoteBranch(ref) }, @@ -991,6 +994,7 @@ fun BranchChip( onCheckoutBranch: () -> Unit, onMergeBranch: () -> Unit, onDeleteBranch: () -> Unit, + onDeleteRemoteBranch: () -> Unit, onRebaseBranch: () -> Unit, onPushRemoteBranch: () -> Unit, onPullRemoteBranch: () -> Unit, @@ -1005,6 +1009,7 @@ fun BranchChip( onCheckoutBranch = onCheckoutBranch, onMergeBranch = onMergeBranch, onDeleteBranch = onDeleteBranch, + onDeleteRemoteBranch = onDeleteRemoteBranch, onRebaseBranch = onRebaseBranch, onPushToRemoteBranch = onPushRemoteBranch, onPullFromRemoteBranch = onPullRemoteBranch, diff --git a/src/main/kotlin/app/viewmodels/LogViewModel.kt b/src/main/kotlin/app/viewmodels/LogViewModel.kt index 75918c8..65a8251 100644 --- a/src/main/kotlin/app/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/app/viewmodels/LogViewModel.kt @@ -355,6 +355,12 @@ class LogViewModel @Inject constructor( ) { tabState.emitNewTaskEvent(TaskEvent.RebaseInteractive(revCommit)) } + + fun deleteRemoteBranch(branch: Ref) = tabState.safeProcessing( + refreshType = RefreshType.ALL_DATA, + ) { git -> + remoteOperationsManager.deleteBranch(git, branch) + } } sealed class LogStatus {