Added error message when revert commit or start rebase interactive have failed
This commit is contained in:
parent
b4c304371c
commit
315387fafc
4 changed files with 23 additions and 6 deletions
|
@ -1,4 +1,3 @@
|
|||
package com.jetpackduba.gitnuro.exceptions
|
||||
|
||||
class RevertCommitException {
|
||||
}
|
||||
class RevertCommitException(msg: String) : GitnuroException(msg)
|
|
@ -1,16 +1,28 @@
|
|||
package com.jetpackduba.gitnuro.git.log
|
||||
|
||||
import com.jetpackduba.gitnuro.exceptions.RevertCommitException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.api.MergeResult
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
import javax.inject.Inject
|
||||
|
||||
class RevertCommitUseCase @Inject constructor() {
|
||||
suspend operator fun invoke(git: Git, revCommit: RevCommit): Unit = withContext(Dispatchers.IO) {
|
||||
git
|
||||
val revertCommand = git
|
||||
.revert()
|
||||
.include(revCommit)
|
||||
.call()
|
||||
|
||||
revertCommand.call()
|
||||
|
||||
val failingResult: MergeResult? = revertCommand.failingResult
|
||||
|
||||
when (failingResult?.mergeStatus) {
|
||||
MergeResult.MergeStatus.FAILED -> throw RevertCommitException("Revert failed. Clear your workspace from uncommited changes.")
|
||||
MergeResult.MergeStatus.CONFLICTING -> throw RevertCommitException("Revert failed. Fix the conflicts and commit the desired changes.")
|
||||
MergeResult.MergeStatus.ABORTED -> throw RevertCommitException("Revert aborted.")
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,8 +18,13 @@ class StartRebaseInteractiveUseCase @Inject constructor() {
|
|||
.setUpstream(commit)
|
||||
.call()
|
||||
|
||||
if (rebaseResult.status == RebaseResult.Status.FAILED) {
|
||||
throw UncommitedChangesDetectedException("Rebase interactive failed.")
|
||||
when (rebaseResult.status) {
|
||||
RebaseResult.Status.FAILED -> throw UncommitedChangesDetectedException("Rebase interactive failed.")
|
||||
RebaseResult.Status.UNCOMMITTED_CHANGES, RebaseResult.Status.CONFLICTS -> throw UncommitedChangesDetectedException(
|
||||
"You can't have uncommited changes before starting a rebase interactive"
|
||||
)
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -188,6 +188,7 @@ class LogViewModel @Inject constructor(
|
|||
|
||||
fun revertCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
||||
refreshType = RefreshType.ALL_DATA,
|
||||
refreshEvenIfCrashes = true,
|
||||
) { git ->
|
||||
revertCommitUseCase(git, revCommit)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue