diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/ConflictsException.kt b/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/ConflictsException.kt deleted file mode 100644 index 1d4b58b9..00000000 --- a/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/ConflictsException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.jetpackduba.gitnuro.exceptions - -class ConflictsException(message: String) : GitnuroException(message) \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt index e0897e35..9264596c 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt @@ -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 diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt index bcf349a6..6e205eb6 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt @@ -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 } } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SharedBranchesViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SharedBranchesViewModel.kt index e36d0800..e618effc 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SharedBranchesViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SharedBranchesViewModel.kt @@ -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") + } } }