Added revert commit feature

This commit is contained in:
Abdelilah El Aissaoui 2021-10-27 03:57:15 +02:00
parent a7d89aabaf
commit d60b1a14a2
4 changed files with 24 additions and 0 deletions

View file

@ -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)

View file

@ -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()
}
}

View file

@ -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)
}
)
)
},
) {

View file

@ -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)
},