Added exception throwing when rebase/merge failed due to uncommited changes
This commit is contained in:
parent
4f84c38fb4
commit
1f58114404
@ -0,0 +1,3 @@
|
|||||||
|
package app.exceptions
|
||||||
|
|
||||||
|
class UncommitedChangesDetectedException(msg: String) : GitnuroException(msg)
|
@ -1,9 +1,11 @@
|
|||||||
package app.git
|
package app.git
|
||||||
|
|
||||||
|
import app.exceptions.UncommitedChangesDetectedException
|
||||||
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.MergeCommand
|
import org.eclipse.jgit.api.MergeCommand
|
||||||
|
import org.eclipse.jgit.api.MergeResult
|
||||||
import org.eclipse.jgit.api.ResetCommand
|
import org.eclipse.jgit.api.ResetCommand
|
||||||
import org.eclipse.jgit.lib.Ref
|
import org.eclipse.jgit.lib.Ref
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
@ -16,11 +18,15 @@ class MergeManager @Inject constructor() {
|
|||||||
else
|
else
|
||||||
MergeCommand.FastForwardMode.NO_FF
|
MergeCommand.FastForwardMode.NO_FF
|
||||||
|
|
||||||
git
|
val mergeResult = git
|
||||||
.merge()
|
.merge()
|
||||||
.include(branch)
|
.include(branch)
|
||||||
.setFastForward(fastForwardMode)
|
.setFastForward(fastForwardMode)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
|
if(mergeResult.mergeStatus == MergeResult.MergeStatus.FAILED) {
|
||||||
|
throw UncommitedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommited changes.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun abortMerge(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun abortMerge(git: Git) = withContext(Dispatchers.IO) {
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
package app.git
|
package app.git
|
||||||
|
|
||||||
|
import app.exceptions.UncommitedChangesDetectedException
|
||||||
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.RebaseCommand
|
import org.eclipse.jgit.api.RebaseCommand
|
||||||
|
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
|
||||||
|
|
||||||
class RebaseManager @Inject constructor() {
|
class RebaseManager @Inject constructor() {
|
||||||
|
|
||||||
suspend fun rebaseBranch(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
|
suspend fun rebaseBranch(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
|
||||||
git.rebase()
|
val rebaseResult = git.rebase()
|
||||||
.setOperation(RebaseCommand.Operation.BEGIN)
|
.setOperation(RebaseCommand.Operation.BEGIN)
|
||||||
.setUpstream(ref.objectId)
|
.setUpstream(ref.objectId)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
|
if(rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) {
|
||||||
|
throw UncommitedChangesDetectedException("Rebase failed, the repository contains uncommited changes.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun continueRebase(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun continueRebase(git: Git) = withContext(Dispatchers.IO) {
|
||||||
|
Loading…
Reference in New Issue
Block a user