diff --git a/src/main/kotlin/app/git/GitManager.kt b/src/main/kotlin/app/git/GitManager.kt index 57a1195..e6c2bc1 100644 --- a/src/main/kotlin/app/git/GitManager.kt +++ b/src/main/kotlin/app/git/GitManager.kt @@ -247,6 +247,13 @@ class GitManager @Inject constructor( } } + fun revertCommit(revCommit: RevCommit) = managerScope.launch { + safeProcessing { + logManager.revertCommit(safeGit, revCommit) + refreshRepositoryInfo() + } + } + fun createBranchOnCommit(branch: String, revCommit: RevCommit) = managerScope.launch { safeProcessing { branchesManager.createBranchOnCommit(safeGit, branch, revCommit) diff --git a/src/main/kotlin/app/git/LogManager.kt b/src/main/kotlin/app/git/LogManager.kt index 25448ae..d2d186c 100644 --- a/src/main/kotlin/app/git/LogManager.kt +++ b/src/main/kotlin/app/git/LogManager.kt @@ -63,6 +63,13 @@ class LogManager @Inject constructor( .setName(ref.name) .call() } + + suspend fun revertCommit(git: Git, revCommit: RevCommit) = withContext(Dispatchers.IO) { + git + .revert() + .include(revCommit) + .call() + } } diff --git a/src/main/kotlin/app/ui/Log.kt b/src/main/kotlin/app/ui/Log.kt index 27fb46a..ab1d8f8 100644 --- a/src/main/kotlin/app/ui/Log.kt +++ b/src/main/kotlin/app/ui/Log.kt @@ -65,6 +65,7 @@ fun Log( onRevCommitSelected: (RevCommit) -> Unit, onUncommitedChangesSelected: () -> Unit, onCheckoutCommit: (graphNode: GraphNode) -> Unit, + onRevertCommit: (graphNode: GraphNode) -> Unit, onCreateBranchOnCommit: (branchName: String, graphNode: GraphNode) -> Unit, onCreateTagOnCommit: (tagName: String, graphNode: GraphNode) -> Unit, onCheckoutRef: (ref: Ref) -> Unit, @@ -239,6 +240,12 @@ fun Log( } } ), + ContextMenuItem( + label = "Revert commit", + onClick = { + onRevertCommit(item) + } + ) ) }, ) { diff --git a/src/main/kotlin/app/ui/RepositoryOpen.kt b/src/main/kotlin/app/ui/RepositoryOpen.kt index 73e080e..f8a7b27 100644 --- a/src/main/kotlin/app/ui/RepositoryOpen.kt +++ b/src/main/kotlin/app/ui/RepositoryOpen.kt @@ -96,6 +96,9 @@ fun RepositoryOpenPage(gitManager: GitManager, dialogManager: DialogManager) { onCheckoutCommit = { graphNode -> gitManager.checkoutCommit(graphNode) }, + onRevertCommit = { graphNode -> + gitManager.revertCommit(graphNode) + }, onCreateBranchOnCommit = { branch, graphNode -> gitManager.createBranchOnCommit(branch, graphNode) },