Skip to content

Commit 169ed5a

Browse files
committed
Added warning when rebase has conflicts or has stopped
1 parent 712e513 commit 169ed5a

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/main/kotlin/com/jetpackduba/gitnuro/exceptions/ConflictsException.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.jetpackduba.gitnuro.git.branches
22

3-
import com.jetpackduba.gitnuro.exceptions.ConflictsException
43
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
54
import kotlinx.coroutines.Dispatchers
65
import kotlinx.coroutines.withContext
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package com.jetpackduba.gitnuro.git.rebase
22

3-
import com.jetpackduba.gitnuro.exceptions.ConflictsException
43
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
54
import kotlinx.coroutines.Dispatchers
65
import kotlinx.coroutines.withContext
76
import org.eclipse.jgit.api.Git
8-
import org.eclipse.jgit.api.MergeResult
97
import org.eclipse.jgit.api.RebaseCommand
108
import org.eclipse.jgit.api.RebaseResult
119
import org.eclipse.jgit.lib.Ref
1210
import javax.inject.Inject
1311

12+
typealias IsMultiStep = Boolean
13+
1414
class RebaseBranchUseCase @Inject constructor() {
15-
suspend operator fun invoke(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
15+
suspend operator fun invoke(git: Git, ref: Ref): IsMultiStep = withContext(Dispatchers.IO) {
1616
val rebaseResult = git.rebase()
1717
.setOperation(RebaseCommand.Operation.BEGIN)
1818
.setUpstream(ref.objectId)
@@ -22,10 +22,10 @@ class RebaseBranchUseCase @Inject constructor() {
2222
throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.")
2323
}
2424

25-
when (rebaseResult.status) {
26-
RebaseResult.Status.UNCOMMITTED_CHANGES -> throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.")
27-
RebaseResult.Status.CONFLICTS -> throw ConflictsException("Rebase produced conflicts, please fix them to continue.")
28-
else -> {}
25+
if (rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) {
26+
throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.")
2927
}
28+
29+
return@withContext rebaseResult.status == RebaseResult.Status.STOPPED || rebaseResult.status == RebaseResult.Status.CONFLICTS
3030
}
3131
}

src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SharedBranchesViewModel.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ class SharedBranchesViewModel @Inject constructor(
7474
taskType = TaskType.REBASE_BRANCH,
7575
refreshEvenIfCrashes = true,
7676
) { git ->
77-
rebaseBranchUseCase(git, ref)
78-
79-
positiveNotification("\"${ref.simpleName}\" rebased")
77+
if (rebaseBranchUseCase(git, ref)) {
78+
warningNotification("Rebase produced conflicts, please fix them to continue.")
79+
} else {
80+
positiveNotification("\"${ref.simpleName}\" rebased")
81+
}
8082
}
8183
}

0 commit comments

Comments
 (0)