Added error message when revert commit or start rebase interactive have failed
This commit is contained in:
parent
b4c304371c
commit
315387fafc
@ -1,4 +1,3 @@
|
|||||||
package com.jetpackduba.gitnuro.exceptions
|
package com.jetpackduba.gitnuro.exceptions
|
||||||
|
|
||||||
class RevertCommitException {
|
class RevertCommitException(msg: String) : GitnuroException(msg)
|
||||||
}
|
|
@ -1,16 +1,28 @@
|
|||||||
package com.jetpackduba.gitnuro.git.log
|
package com.jetpackduba.gitnuro.git.log
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.exceptions.RevertCommitException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.api.MergeResult
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RevertCommitUseCase @Inject constructor() {
|
class RevertCommitUseCase @Inject constructor() {
|
||||||
suspend operator fun invoke(git: Git, revCommit: RevCommit): Unit = withContext(Dispatchers.IO) {
|
suspend operator fun invoke(git: Git, revCommit: RevCommit): Unit = withContext(Dispatchers.IO) {
|
||||||
git
|
val revertCommand = git
|
||||||
.revert()
|
.revert()
|
||||||
.include(revCommit)
|
.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)
|
.setUpstream(commit)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
if (rebaseResult.status == RebaseResult.Status.FAILED) {
|
when (rebaseResult.status) {
|
||||||
throw UncommitedChangesDetectedException("Rebase interactive failed.")
|
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(
|
fun revertCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
revertCommitUseCase(git, revCommit)
|
revertCommitUseCase(git, revCommit)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user