Skip to content

Commit

Permalink
add git merge
Browse files Browse the repository at this point in the history
  • Loading branch information
diffitask committed Jan 5, 2024
1 parent c28f5e0 commit aeee12d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jetbrains.research.ideFormerPlugin.api.models.gitRelated

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import git4idea.commands.GitCommand

class GitMerge(
project: Project,
projectGitRoot: VirtualFile,
mergingBranchName: String
) : GitApiMethod(project, projectGitRoot) {
// Invariant: you're staying on the right branch that you want to merge changes to. Git checkout was made recently.
override var gitCommand: GitCommand? = GitCommand.MERGE
override var gitCommandParameters: List<String>? = listOf(mergingBranchName)

override var gitReverseCommand: GitCommand? = GitCommand.RESET
// --merge as opposed to the --hard doesn't reset uncommited/ unstashed files.
// ORIG_HEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it by yourself.
override var gitReverseCommandParameters: List<String>? = listOf("--merge", "ORIG_HEAD")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fun executeGitCommand(
projectGitRoot: VirtualFile,
gitCommand: GitCommand,
gitCommandParameters: List<String>?
) : String {
): String {
val git = Git.getInstance()

val gitCommandHandler = GitLineHandler(project, projectGitRoot, gitCommand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun Application.configureRouting(ideStateKeeper: IdeStateKeeper, logger: Logger)
getGitReset(logger, ideStateKeeper)
getGitBranch(logger, ideStateKeeper)
getGitCheckout(logger, ideStateKeeper)
getGitMerge(logger, ideStateKeeper)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jetbrains.research.ideFormerPlugin.server.requests.gitRelated

import io.ktor.server.application.*
import io.ktor.server.routing.*
import org.jetbrains.research.ideFormerPlugin.api.models.gitRelated.GitMerge
import org.jetbrains.research.ideFormerPlugin.server.*
import org.jetbrains.research.ideFormerPlugin.stateKeeper.IdeStateKeeper
import org.slf4j.Logger

fun Routing.getGitMerge(logger: Logger, ideStateKeeper: IdeStateKeeper) {
get("/git-merge/{${IdeServerConstants.BRANCH_NAME_REQUEST_PARAM}?}") {
val mergingBranchName = call.processRequestParameter(IdeServerConstants.BRANCH_NAME_REQUEST_PARAM, logger)
?: return@get
logger.info("Server GET git merge $mergingBranchName into current branch is called")

val gitMerge = GitMerge(ideStateKeeper.userProject, ideStateKeeper.projectGitRoot, mergingBranchName)
if (!executeAndRespondError(gitMerge, logger)) return@get

ideStateKeeper.saveReversibleApiMethod(gitMerge)
logger.info("Git merge api method was saved on the api methods stack")

call.respondJson("Git merge $mergingBranchName into current branch was processed successfully")
logger.info("Server GET git merge $mergingBranchName into current branch is processed")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@
],
"optional_parameters": []
},
{
"name": "git_merge",
"url": "/git-merge",
"description": "Merge commits from the given branch to the current branch of a Git repository.",
"method": "GET",
"required_parameters": [
{
"name": "branchName",
"type": "STRING",
"regex": "[A-Za-z]*",
"description": "The name of a branch that should be merged to the current branch of a Git repository."
}
],
"optional_parameters": []
},
{
"name": "reverse_last_api_methods",
"url": "/reverse-api-methods",
Expand Down

0 comments on commit aeee12d

Please sign in to comment.