Added support for local branch deletion

This commit is contained in:
Abdelilah El Aissaoui 2021-11-27 20:22:05 +01:00
parent fc0fc8c448
commit 4abd9e331d
4 changed files with 34 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import org.eclipse.jgit.lib.Ref
val Ref.simpleName: String val Ref.simpleName: String
get() { get() {
return if (this.name.startsWith("refs/remotes/")) return if (this.isRemote)
name.replace("refs/remotes/", "") name.replace("refs/remotes/", "")
else else
this.name.split("/").last() // TODO Do not take the last one, just remove the prefixes this.name.split("/").last() // TODO Do not take the last one, just remove the prefixes
@ -18,3 +18,9 @@ val Ref.isBranch: Boolean
val Ref.isTag: Boolean val Ref.isTag: Boolean
get() = this is ObjectIdRef.PeeledTag get() = this is ObjectIdRef.PeeledTag
val Ref.isLocal: Boolean
get() = !this.isRemote
val Ref.isRemote: Boolean
get() = this.name.startsWith("refs/remotes/")

View File

@ -75,6 +75,7 @@ class BranchesManager @Inject constructor() {
git git
.branchDelete() .branchDelete()
.setBranchNames(branch.name) .setBranchNames(branch.name)
.setForce(true) // TODO Should it be forced?
.call() .call()
} }
} }

View File

@ -209,7 +209,10 @@ class GitManager @Inject constructor(
} }
fun deleteBranch(branch: Ref) = managerScope.launch { fun deleteBranch(branch: Ref) = managerScope.launch {
safeProcessing {
branchesManager.deleteBranch(safeGit, branch) branchesManager.deleteBranch(safeGit, branch)
coLoadLog()
}
} }
fun resetStaged(diffEntry: DiffEntry) = managerScope.launch { fun resetStaged(diffEntry: DiffEntry) = managerScope.launch {

View File

@ -10,7 +10,9 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.* import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
@ -18,8 +20,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawStyle
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.input.pointer.PointerIconDefaults import androidx.compose.ui.input.pointer.PointerIconDefaults
import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.input.pointer.pointerHoverIcon
@ -33,7 +33,6 @@ import app.DialogManager
import app.extensions.* import app.extensions.*
import app.git.GitManager import app.git.GitManager
import app.git.LogStatus import app.git.LogStatus
import app.git.ResetType
import app.git.graph.GraphNode import app.git.graph.GraphNode
import app.theme.headerBackground import app.theme.headerBackground
import app.theme.headerText import app.theme.headerText
@ -44,7 +43,6 @@ import app.ui.dialogs.MergeDialog
import app.ui.dialogs.NewBranchDialog import app.ui.dialogs.NewBranchDialog
import app.ui.dialogs.NewTagDialog import app.ui.dialogs.NewTagDialog
import app.ui.dialogs.ResetBranchDialog import app.ui.dialogs.ResetBranchDialog
import org.eclipse.jgit.lib.ObjectIdRef
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
@ -296,9 +294,7 @@ fun Log(
commit = graphNode, commit = graphNode,
selected = selectedIndex.value == index, selected = selectedIndex.value == index,
refs = commitRefs, refs = commitRefs,
onCheckoutRef = { ref -> onCheckoutRef = { ref -> gitManager.checkoutRef(ref) },
gitManager.checkoutRef(ref)
},
onMergeBranch = { ref -> onMergeBranch = { ref ->
dialogManager.show { dialogManager.show {
MergeDialog( MergeDialog(
@ -314,6 +310,7 @@ fun Log(
) )
} }
}, },
onDeleteBranch = { ref -> gitManager.deleteBranch(ref) }
) )
} }
} }
@ -332,6 +329,7 @@ fun CommitMessage(
refs: List<Ref>, refs: List<Ref>,
onCheckoutRef: (ref: Ref) -> Unit, onCheckoutRef: (ref: Ref) -> Unit,
onMergeBranch: (ref: Ref) -> Unit, onMergeBranch: (ref: Ref) -> Unit,
onDeleteBranch: (ref: Ref) -> Unit,
) { ) {
val textColor = if (selected) { val textColor = if (selected) {
MaterialTheme.colors.primary MaterialTheme.colors.primary
@ -363,12 +361,9 @@ fun CommitMessage(
} else if (ref.isBranch) } else if (ref.isBranch)
BranchChip( BranchChip(
ref = ref, ref = ref,
onCheckoutBranch = { onCheckoutBranch = { onCheckoutRef(ref) },
onCheckoutRef(ref) onMergeBranch = { onMergeBranch(ref) },
}, onDeleteBranch = { onDeleteBranch(ref) }
onMergeBranch = {
onMergeBranch(ref)
}
) )
} }
@ -545,6 +540,7 @@ fun BranchChip(
ref: Ref, ref: Ref,
onCheckoutBranch: () -> Unit, onCheckoutBranch: () -> Unit,
onMergeBranch: () -> Unit, onMergeBranch: () -> Unit,
onDeleteBranch: () -> Unit,
) { ) {
val contextMenuItemsList = { val contextMenuItemsList = {
mutableListOf( mutableListOf(
@ -554,7 +550,7 @@ fun BranchChip(
), ),
).apply { ).apply {
if (!isCurrentBranch) if (!isCurrentBranch) {
add( add(
ContextMenuItem( ContextMenuItem(
label = "Merge branch", label = "Merge branch",
@ -562,6 +558,15 @@ fun BranchChip(
) )
) )
} }
if (ref.isLocal && !isCurrentBranch) {
add(
ContextMenuItem(
label = "Delete branch",
onClick = onDeleteBranch
)
)
}
}
} }
RefChip( RefChip(