From 171e9dc0bedca2cfbbc7ef21b78c22b4802f411d Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Tue, 1 Feb 2022 14:31:56 +0100 Subject: [PATCH] Added force push --- .../kotlin/app/git/RemoteOperationsManager.kt | 3 ++- src/main/kotlin/app/ui/Menu.kt | 8 +++++++- .../kotlin/app/ui/context_menu/PushContextMenu.kt | 15 +++++++++++++++ src/main/kotlin/app/viewmodels/MenuViewModel.kt | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/app/ui/context_menu/PushContextMenu.kt diff --git a/src/main/kotlin/app/git/RemoteOperationsManager.kt b/src/main/kotlin/app/git/RemoteOperationsManager.kt index e31c4dd..91c7236 100644 --- a/src/main/kotlin/app/git/RemoteOperationsManager.kt +++ b/src/main/kotlin/app/git/RemoteOperationsManager.kt @@ -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) { diff --git a/src/main/kotlin/app/ui/Menu.kt b/src/main/kotlin/app/ui/Menu.kt index fb1909b..c7a6417 100644 --- a/src/main/kotlin/app/ui/Menu.kt +++ b/src/main/kotlin/app/ui/Menu.kt @@ -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)) diff --git a/src/main/kotlin/app/ui/context_menu/PushContextMenu.kt b/src/main/kotlin/app/ui/context_menu/PushContextMenu.kt new file mode 100644 index 0000000..4d8b809 --- /dev/null +++ b/src/main/kotlin/app/ui/context_menu/PushContextMenu.kt @@ -0,0 +1,15 @@ +package app.ui.context_menu + +import androidx.compose.foundation.ExperimentalFoundationApi + +@OptIn(ExperimentalFoundationApi::class) +fun pushContextMenuItems( + onForcePush: () -> Unit, +): List { + return mutableListOf( + DropDownContentData( + label = "Force push", + onClick = onForcePush, + ), + ) +} diff --git a/src/main/kotlin/app/viewmodels/MenuViewModel.kt b/src/main/kotlin/app/viewmodels/MenuViewModel.kt index 782a53d..70db874 100644 --- a/src/main/kotlin/app/viewmodels/MenuViewModel.kt +++ b/src/main/kotlin/app/viewmodels/MenuViewModel.kt @@ -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 }