Added exception when pull has failed

This commit is contained in:
Abdelilah El Aissaoui 2022-02-17 23:18:46 +01:00
parent 9dc5296a61
commit 902626f04b

View File

@ -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) {