diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt index d5c91e0..de4e4b9 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt @@ -55,10 +55,12 @@ class TabState @Inject constructor( showError: Boolean = true, refreshType: RefreshType, refreshEvenIfCrashes: Boolean = false, + refreshEvenIfCrashesInteractive: ((Exception) -> Boolean)? = null, callback: suspend (git: Git) -> Unit ) = scope.launch(Dispatchers.IO) { var hasProcessFailed = false + var refreshEvenIfCrashesInteractiveResult = false operationRunning = true try { @@ -74,13 +76,15 @@ class TabState @Inject constructor( hasProcessFailed = true ex.printStackTrace() + refreshEvenIfCrashesInteractiveResult = refreshEvenIfCrashesInteractive?.invoke(ex) ?: false + if (showError) errorsManager.addError(newErrorNow(ex, ex.message.orEmpty())) } finally { _processing.value = false operationRunning = false - if (refreshType != RefreshType.NONE && (!hasProcessFailed || refreshEvenIfCrashes)) { + if (refreshType != RefreshType.NONE && (!hasProcessFailed || refreshEvenIfCrashes || refreshEvenIfCrashesInteractiveResult)) { _refreshData.emit(refreshType) } } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt index 78a7fad..8be0b74 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt @@ -26,6 +26,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import org.eclipse.jgit.api.Git +import org.eclipse.jgit.api.errors.CheckoutConflictException import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.revwalk.RevCommit import javax.inject.Inject @@ -213,6 +214,7 @@ class LogViewModel @Inject constructor( fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing( refreshType = RefreshType.ALL_DATA, + refreshEvenIfCrashesInteractive = { it is CheckoutConflictException }, ) { git -> createBranchOnCommitUseCase(git, branch, revCommit) } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt index 34225f1..7470ceb 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import org.eclipse.jgit.api.Git +import org.eclipse.jgit.api.errors.CheckoutConflictException import org.eclipse.jgit.blame.BlameResult import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.lib.RepositoryState @@ -415,7 +416,7 @@ class TabViewModel @Inject constructor( fun createBranch(branchName: String) = tabState.safeProcessing( refreshType = RefreshType.ALL_DATA, - refreshEvenIfCrashes = true, + refreshEvenIfCrashesInteractive = { it is CheckoutConflictException }, ) { git -> createBranchUseCase(git, branchName) }