Added force push

This commit is contained in:
Abdelilah El Aissaoui 2022-02-01 14:31:56 +01:00
parent c746f845ee
commit 171e9dc0be
4 changed files with 26 additions and 4 deletions

View file

@ -35,12 +35,13 @@ class RemoteOperationsManager @Inject constructor(
.call()
}
suspend fun push(git: Git) = withContext(Dispatchers.IO) {
suspend fun push(git: Git, force: Boolean) = withContext(Dispatchers.IO) {
val currentBranchRefSpec = git.repository.fullBranch
val pushResult = git
.push()
.setRefSpecs(RefSpec(currentBranchRefSpec))
.setForce(force)
.setPushTags()
.setTransportConfigCallback {
if (it is SshTransport) {

View file

@ -24,6 +24,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import app.ui.context_menu.DropDownContent
import app.ui.context_menu.DropDownContentData
import app.ui.context_menu.pushContextMenuItems
// TODO Add tooltips to all the buttons
@Composable
@ -60,10 +61,15 @@ fun Menu(
)
)
MenuButton(
ExtendedMenuButton(
title = "Push",
icon = painterResource("upload.svg"),
onClick = { menuViewModel.push() },
extendedListItems = pushContextMenuItems(
onForcePush = {
menuViewModel.push(true)
}
)
)
Spacer(modifier = Modifier.width(16.dp))

View file

@ -0,0 +1,15 @@
package app.ui.context_menu
import androidx.compose.foundation.ExperimentalFoundationApi
@OptIn(ExperimentalFoundationApi::class)
fun pushContextMenuItems(
onForcePush: () -> Unit,
): List<DropDownContentData> {
return mutableListOf(
DropDownContentData(
label = "Force push",
onClick = onForcePush,
),
)
}

View file

@ -18,8 +18,8 @@ class MenuViewModel @Inject constructor(
return@safeProcessing RefreshType.ONLY_LOG
}
fun push() = tabState.safeProcessing { git ->
remoteOperationsManager.push(git)
fun push(force: Boolean = false) = tabState.safeProcessing { git ->
remoteOperationsManager.push(git, force)
return@safeProcessing RefreshType.ONLY_LOG
}