Added warning when rebase has conflicts or has stopped

This commit is contained in:
Abdelilah El Aissaoui 2024-09-17 23:40:13 +02:00
parent 712e513c2e
commit 169ed5af3f
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
4 changed files with 12 additions and 14 deletions

View File

@ -1,3 +0,0 @@
package com.jetpackduba.gitnuro.exceptions
class ConflictsException(message: String) : GitnuroException(message)

View File

@ -1,6 +1,5 @@
package com.jetpackduba.gitnuro.git.branches
import com.jetpackduba.gitnuro.exceptions.ConflictsException
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

View File

@ -1,18 +1,18 @@
package com.jetpackduba.gitnuro.git.rebase
import com.jetpackduba.gitnuro.exceptions.ConflictsException
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.MergeResult
import org.eclipse.jgit.api.RebaseCommand
import org.eclipse.jgit.api.RebaseResult
import org.eclipse.jgit.lib.Ref
import javax.inject.Inject
typealias IsMultiStep = Boolean
class RebaseBranchUseCase @Inject constructor() {
suspend operator fun invoke(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
suspend operator fun invoke(git: Git, ref: Ref): IsMultiStep = withContext(Dispatchers.IO) {
val rebaseResult = git.rebase()
.setOperation(RebaseCommand.Operation.BEGIN)
.setUpstream(ref.objectId)
@ -22,10 +22,10 @@ class RebaseBranchUseCase @Inject constructor() {
throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.")
}
when (rebaseResult.status) {
RebaseResult.Status.UNCOMMITTED_CHANGES -> throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.")
RebaseResult.Status.CONFLICTS -> throw ConflictsException("Rebase produced conflicts, please fix them to continue.")
else -> {}
if (rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) {
throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.")
}
return@withContext rebaseResult.status == RebaseResult.Status.STOPPED || rebaseResult.status == RebaseResult.Status.CONFLICTS
}
}

View File

@ -74,8 +74,10 @@ class SharedBranchesViewModel @Inject constructor(
taskType = TaskType.REBASE_BRANCH,
refreshEvenIfCrashes = true,
) { git ->
rebaseBranchUseCase(git, ref)
positiveNotification("\"${ref.simpleName}\" rebased")
if (rebaseBranchUseCase(git, ref)) {
warningNotification("Rebase produced conflicts, please fix them to continue.")
} else {
positiveNotification("\"${ref.simpleName}\" rebased")
}
}
}