Skip to content

Commit

Permalink
Added warning when rebase has conflicts or has stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
JetpackDuba committed Sep 17, 2024
1 parent 712e513 commit 169ed5a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jetpackduba.gitnuro.git.branches

import com.jetpackduba.gitnuro.exceptions.ConflictsException
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.jetpackduba.gitnuro.git.rebase

import com.jetpackduba.gitnuro.exceptions.ConflictsException
import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.MergeResult
import org.eclipse.jgit.api.RebaseCommand
import org.eclipse.jgit.api.RebaseResult
import org.eclipse.jgit.lib.Ref
import javax.inject.Inject

typealias IsMultiStep = Boolean

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()
.setOperation(RebaseCommand.Operation.BEGIN)
.setUpstream(ref.objectId)
Expand All @@ -22,10 +22,10 @@ class RebaseBranchUseCase @Inject constructor() {
throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.")
}

when (rebaseResult.status) {
RebaseResult.Status.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 -> {}
if (rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) {
throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.")
}

return@withContext rebaseResult.status == RebaseResult.Status.STOPPED || rebaseResult.status == RebaseResult.Status.CONFLICTS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ class SharedBranchesViewModel @Inject constructor(
taskType = TaskType.REBASE_BRANCH,
refreshEvenIfCrashes = true,
) { git ->
rebaseBranchUseCase(git, ref)

positiveNotification("\"${ref.simpleName}\" rebased")
if (rebaseBranchUseCase(git, ref)) {
warningNotification("Rebase produced conflicts, please fix them to continue.")
} else {
positiveNotification("\"${ref.simpleName}\" rebased")
}
}
}

0 comments on commit 169ed5a

Please sign in to comment.