From 902626f04b344aba28bcc84b621d1631cfb097cd Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 17 Feb 2022 23:18:46 +0100 Subject: [PATCH] Added exception when pull has failed --- .../kotlin/app/git/RemoteOperationsManager.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/git/RemoteOperationsManager.kt b/src/main/kotlin/app/git/RemoteOperationsManager.kt index 91065eb..9f11700 100644 --- a/src/main/kotlin/app/git/RemoteOperationsManager.kt +++ b/src/main/kotlin/app/git/RemoteOperationsManager.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.isActive import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git +import org.eclipse.jgit.api.RebaseResult import org.eclipse.jgit.lib.ProgressMonitor import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.transport.* @@ -23,7 +24,7 @@ class RemoteOperationsManager @Inject constructor( get() = _cloneStatus suspend fun pull(git: Git, rebase: Boolean) = withContext(Dispatchers.IO) { - git + val pullResult = git .pull() .setTransportConfigCallback { handleTransportCredentials(it) @@ -31,6 +32,20 @@ class RemoteOperationsManager @Inject constructor( .setRebase(rebase) .setCredentialsProvider(CredentialsProvider.getDefault()) .call() + + if (!pullResult.isSuccessful) { + var message = "Pull failed" + + if(rebase) { + message = when(pullResult.rebaseResult.status) { + RebaseResult.Status.UNCOMMITTED_CHANGES -> "The pull with rebase has failed because you have got uncommited changes" + RebaseResult.Status.CONFLICTS -> "Pull with rebase has conflicts, fix them to continue" + else -> message + } + } + + throw Exception(message) + } } suspend fun fetchAll(git: Git) = withContext(Dispatchers.IO) {