From 1dca2dfd51c0d915b0220a28bfd9f0883c70ff09 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Wed, 2 Feb 2022 10:33:08 +0100 Subject: [PATCH] Added fetch all & after pull all the repository is reloaded --- .../kotlin/app/git/RemoteOperationsManager.kt | 20 +++++++++++++++++++ src/main/kotlin/app/ui/Menu.kt | 3 +++ .../app/ui/context_menu/PullContextMenu.kt | 5 +++++ .../kotlin/app/viewmodels/MenuViewModel.kt | 8 +++++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/git/RemoteOperationsManager.kt b/src/main/kotlin/app/git/RemoteOperationsManager.kt index 91c7236..a5c96e3 100644 --- a/src/main/kotlin/app/git/RemoteOperationsManager.kt +++ b/src/main/kotlin/app/git/RemoteOperationsManager.kt @@ -13,6 +13,7 @@ import org.eclipse.jgit.transport.* import java.io.File import javax.inject.Inject + class RemoteOperationsManager @Inject constructor( private val sessionManager: GSessionManager ) { @@ -35,6 +36,25 @@ class RemoteOperationsManager @Inject constructor( .call() } + suspend fun fetchAll(git: Git) = withContext(Dispatchers.IO) { + val remotes = git.remoteList().call() + + for (remote in remotes) { + git.fetch() + .setRemote(remote.name) + .setRefSpecs(remote.fetchRefSpecs) + .setTransportConfigCallback { + if (it is SshTransport) { + it.sshSessionFactory = sessionManager.generateSshSessionFactory() + } else if (it is HttpTransport) { + it.credentialsProvider = HttpCredentialsProvider() + } + } + .setCredentialsProvider(CredentialsProvider.getDefault()) + .call() + } + } + suspend fun push(git: Git, force: Boolean) = withContext(Dispatchers.IO) { val currentBranchRefSpec = git.repository.fullBranch diff --git a/src/main/kotlin/app/ui/Menu.kt b/src/main/kotlin/app/ui/Menu.kt index 94ebe39..d73b91e 100644 --- a/src/main/kotlin/app/ui/Menu.kt +++ b/src/main/kotlin/app/ui/Menu.kt @@ -58,6 +58,9 @@ fun Menu( extendedListItems = pullContextMenuItems( onPullRebase = { menuViewModel.pull(true) + }, + onFetchAll = { + menuViewModel.fetchAll() } ) ) diff --git a/src/main/kotlin/app/ui/context_menu/PullContextMenu.kt b/src/main/kotlin/app/ui/context_menu/PullContextMenu.kt index d992900..424836b 100644 --- a/src/main/kotlin/app/ui/context_menu/PullContextMenu.kt +++ b/src/main/kotlin/app/ui/context_menu/PullContextMenu.kt @@ -5,11 +5,16 @@ import androidx.compose.foundation.ExperimentalFoundationApi @OptIn(ExperimentalFoundationApi::class) fun pullContextMenuItems( onPullRebase: () -> Unit, + onFetchAll: () -> Unit, ): List { return mutableListOf( DropDownContentData( label = "Pull with rebase", onClick = onPullRebase, ), + DropDownContentData( + label = "Fetch all", + onClick = onFetchAll, + ), ) } diff --git a/src/main/kotlin/app/viewmodels/MenuViewModel.kt b/src/main/kotlin/app/viewmodels/MenuViewModel.kt index c6d883b..e1379bf 100644 --- a/src/main/kotlin/app/viewmodels/MenuViewModel.kt +++ b/src/main/kotlin/app/viewmodels/MenuViewModel.kt @@ -15,7 +15,13 @@ class MenuViewModel @Inject constructor( fun pull(rebase: Boolean = false) = tabState.safeProcessing { git -> remoteOperationsManager.pull(git, rebase) - return@safeProcessing RefreshType.ONLY_LOG + return@safeProcessing RefreshType.ALL_DATA + } + + fun fetchAll() = tabState.safeProcessing { git -> + remoteOperationsManager.fetchAll(git) + + return@safeProcessing RefreshType.ALL_DATA } fun push(force: Boolean = false) = tabState.safeProcessing { git ->