diff --git a/src/main/kotlin/app/git/MergeManager.kt b/src/main/kotlin/app/git/MergeManager.kt index 41a3b23..b0b90f2 100644 --- a/src/main/kotlin/app/git/MergeManager.kt +++ b/src/main/kotlin/app/git/MergeManager.kt @@ -6,6 +6,7 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.MergeCommand import org.eclipse.jgit.api.ResetCommand import org.eclipse.jgit.lib.Ref +import org.eclipse.jgit.revwalk.RevCommit import javax.inject.Inject class MergeManager @Inject constructor() { @@ -28,4 +29,10 @@ class MergeManager @Inject constructor() { git.reset().setMode(ResetCommand.ResetType.HARD).call() } + + suspend fun cherryPickCommit(git: Git, revCommit: RevCommit) = withContext(Dispatchers.IO) { + git.cherryPick() + .include(revCommit) + .call() + } } \ No newline at end of file diff --git a/src/main/kotlin/app/ui/log/Log.kt b/src/main/kotlin/app/ui/log/Log.kt index 8ad0d8e..7715b9a 100644 --- a/src/main/kotlin/app/ui/log/Log.kt +++ b/src/main/kotlin/app/ui/log/Log.kt @@ -370,6 +370,10 @@ fun CommitLine( label = "Revert commit", onClick = { logViewModel.revertCommit(graphNode) } ), + ContextMenuItem( + label = "Cherry-pick commit", + onClick = { logViewModel.cherrypickCommit(graphNode) } + ), ContextMenuItem( label = "Reset current branch to this commit", diff --git a/src/main/kotlin/app/viewmodels/LogViewModel.kt b/src/main/kotlin/app/viewmodels/LogViewModel.kt index c6d044b..6f6a304 100644 --- a/src/main/kotlin/app/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/app/viewmodels/LogViewModel.kt @@ -56,6 +56,11 @@ class LogViewModel @Inject constructor( 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( refreshType = RefreshType.ALL_DATA,