Added warning when rebase has conflicts or has stopped
This commit is contained in:
parent
712e513c2e
commit
169ed5af3f
@ -1,3 +0,0 @@
|
|||||||
package com.jetpackduba.gitnuro.exceptions
|
|
||||||
|
|
||||||
class ConflictsException(message: String) : GitnuroException(message)
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.jetpackduba.gitnuro.git.branches
|
package com.jetpackduba.gitnuro.git.branches
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.ConflictsException
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
|
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package com.jetpackduba.gitnuro.git.rebase
|
package com.jetpackduba.gitnuro.git.rebase
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.ConflictsException
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
|
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
|
||||||
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.api.RebaseCommand
|
import org.eclipse.jgit.api.RebaseCommand
|
||||||
import org.eclipse.jgit.api.RebaseResult
|
import org.eclipse.jgit.api.RebaseResult
|
||||||
import org.eclipse.jgit.lib.Ref
|
import org.eclipse.jgit.lib.Ref
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
typealias IsMultiStep = Boolean
|
||||||
|
|
||||||
class RebaseBranchUseCase @Inject constructor() {
|
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()
|
val rebaseResult = git.rebase()
|
||||||
.setOperation(RebaseCommand.Operation.BEGIN)
|
.setOperation(RebaseCommand.Operation.BEGIN)
|
||||||
.setUpstream(ref.objectId)
|
.setUpstream(ref.objectId)
|
||||||
@ -22,10 +22,10 @@ class RebaseBranchUseCase @Inject constructor() {
|
|||||||
throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.")
|
throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
when (rebaseResult.status) {
|
if (rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) {
|
||||||
RebaseResult.Status.UNCOMMITTED_CHANGES -> throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain 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 -> {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return@withContext rebaseResult.status == RebaseResult.Status.STOPPED || rebaseResult.status == RebaseResult.Status.CONFLICTS
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -74,8 +74,10 @@ class SharedBranchesViewModel @Inject constructor(
|
|||||||
taskType = TaskType.REBASE_BRANCH,
|
taskType = TaskType.REBASE_BRANCH,
|
||||||
refreshEvenIfCrashes = true,
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
rebaseBranchUseCase(git, ref)
|
if (rebaseBranchUseCase(git, ref)) {
|
||||||
|
warningNotification("Rebase produced conflicts, please fix them to continue.")
|
||||||
|
} else {
|
||||||
positiveNotification("\"${ref.simpleName}\" rebased")
|
positiveNotification("\"${ref.simpleName}\" rebased")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user