Implemented cherry-pick

This commit is contained in:
Abdelilah El Aissaoui 2022-02-05 19:19:49 +01:00
parent cb609c44cc
commit 72e77f41fd
3 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.MergeCommand import org.eclipse.jgit.api.MergeCommand
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 javax.inject.Inject import javax.inject.Inject
class MergeManager @Inject constructor() { class MergeManager @Inject constructor() {
@ -28,4 +29,10 @@ class MergeManager @Inject constructor() {
git.reset().setMode(ResetCommand.ResetType.HARD).call() git.reset().setMode(ResetCommand.ResetType.HARD).call()
} }
suspend fun cherryPickCommit(git: Git, revCommit: RevCommit) = withContext(Dispatchers.IO) {
git.cherryPick()
.include(revCommit)
.call()
}
} }

View File

@ -370,6 +370,10 @@ fun CommitLine(
label = "Revert commit", label = "Revert commit",
onClick = { logViewModel.revertCommit(graphNode) } onClick = { logViewModel.revertCommit(graphNode) }
), ),
ContextMenuItem(
label = "Cherry-pick commit",
onClick = { logViewModel.cherrypickCommit(graphNode) }
),
ContextMenuItem( ContextMenuItem(
label = "Reset current branch to this commit", label = "Reset current branch to this commit",

View File

@ -56,6 +56,11 @@ class LogViewModel @Inject constructor(
branchesManager.checkoutRef(git, ref) branchesManager.checkoutRef(git, ref)
} }
fun cherrypickCommit(revCommit: RevCommit) = tabState.safeProcessing (
refreshType = RefreshType.ONLY_LOG,
) { git ->
mergeManager.cherryPickCommit(git, revCommit)
}
fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing( fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA, refreshType = RefreshType.ALL_DATA,