Fixed repo state not refreshing if branch checkout has failed after creation

This commit is contained in:
Abdelilah El Aissaoui 2022-11-05 01:55:50 +01:00
parent dcf9ceb6a3
commit 69089c9910
3 changed files with 9 additions and 2 deletions

View File

@ -55,10 +55,12 @@ class TabState @Inject constructor(
showError: Boolean = true, showError: Boolean = true,
refreshType: RefreshType, refreshType: RefreshType,
refreshEvenIfCrashes: Boolean = false, refreshEvenIfCrashes: Boolean = false,
refreshEvenIfCrashesInteractive: ((Exception) -> Boolean)? = null,
callback: suspend (git: Git) -> Unit callback: suspend (git: Git) -> Unit
) = ) =
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
var hasProcessFailed = false var hasProcessFailed = false
var refreshEvenIfCrashesInteractiveResult = false
operationRunning = true operationRunning = true
try { try {
@ -74,13 +76,15 @@ class TabState @Inject constructor(
hasProcessFailed = true hasProcessFailed = true
ex.printStackTrace() ex.printStackTrace()
refreshEvenIfCrashesInteractiveResult = refreshEvenIfCrashesInteractive?.invoke(ex) ?: false
if (showError) if (showError)
errorsManager.addError(newErrorNow(ex, ex.message.orEmpty())) errorsManager.addError(newErrorNow(ex, ex.message.orEmpty()))
} finally { } finally {
_processing.value = false _processing.value = false
operationRunning = false operationRunning = false
if (refreshType != RefreshType.NONE && (!hasProcessFailed || refreshEvenIfCrashes)) { if (refreshType != RefreshType.NONE && (!hasProcessFailed || refreshEvenIfCrashes || refreshEvenIfCrashesInteractiveResult)) {
_refreshData.emit(refreshType) _refreshData.emit(refreshType)
} }
} }

View File

@ -26,6 +26,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.errors.CheckoutConflictException
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
import javax.inject.Inject import javax.inject.Inject
@ -213,6 +214,7 @@ class LogViewModel @Inject constructor(
fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing( fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA, refreshType = RefreshType.ALL_DATA,
refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
) { git -> ) { git ->
createBranchOnCommitUseCase(git, branch, revCommit) createBranchOnCommitUseCase(git, branch, revCommit)
} }

View File

@ -22,6 +22,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.errors.CheckoutConflictException
import org.eclipse.jgit.blame.BlameResult import org.eclipse.jgit.blame.BlameResult
import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryState import org.eclipse.jgit.lib.RepositoryState
@ -415,7 +416,7 @@ class TabViewModel @Inject constructor(
fun createBranch(branchName: String) = tabState.safeProcessing( fun createBranch(branchName: String) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA, refreshType = RefreshType.ALL_DATA,
refreshEvenIfCrashes = true, refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
) { git -> ) { git ->
createBranchUseCase(git, branchName) createBranchUseCase(git, branchName)
} }