Skip to content

Commit

Permalink
fix(git): fix 222 & 233 version GitUtil class for committing local ch…
Browse files Browse the repository at this point in the history
…anges #101

This commit adds a new class `GitUtil` in the `cc.unitmesh.devti.language.git` package, which provides a `doCommit` function. This function takes a project, a local change list, and a commit message as parameters, and commits the changes using the IntelliJ VCS API. This new class will be used to commit local changes in the `CommitInsCommand` class. Additionally, the `CommitInsCommand` class is modified to use the `GitUtil` class for performing commits. The commit also includes minor changes to the `README.md` file.

Refs #233
  • Loading branch information
phodal committed Mar 17, 2024
1 parent e186129 commit 71c3d69
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -25,7 +25,7 @@
[Quick Start →](https://ide.unitmesh.cc/quick-start)

[DevIns - a language for Auto Development](https://ide.unitmesh.cc/devins)
[DevIns — AI Agent language for AutoDevelopment](https://ide.unitmesh.cc/devins)

AutoDev Overview:

Expand Down
@@ -0,0 +1,15 @@
package cc.unitmesh.devti.language.git

import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.CommitContext
import com.intellij.openapi.vcs.changes.LocalChangeList
import com.intellij.vcs.commit.ChangeListCommitState
import com.intellij.vcs.commit.SingleChangeListCommitter

object GitUtil {
fun doCommit(myProject: Project, list: LocalChangeList, commitMsg: String) {
val commitState = ChangeListCommitState(list, list.changes.toList(), commitMsg)
val committer = SingleChangeListCommitter(myProject, commitState, CommitContext(), commitMsg, false)
committer.runCommit("Commit", false)
}
}
@@ -0,0 +1,15 @@
package cc.unitmesh.devti.language.git

import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.CommitContext
import com.intellij.openapi.vcs.changes.LocalChangeList
import com.intellij.vcs.commit.ChangeListCommitState
import com.intellij.vcs.commit.LocalChangesCommitter

object GitUtil {
fun doCommit(myProject: Project, list: LocalChangeList, commitMsg: String) {
val commitState = ChangeListCommitState(list, list.changes.toList(), commitMsg)
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
committer.runCommit("Commit", false)
}
}
@@ -1,22 +1,18 @@
package cc.unitmesh.devti.language.compiler.exec

import cc.unitmesh.devti.language.git.GitUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vcs.changes.CommitContext
import com.intellij.openapi.vcs.changes.LocalChangeList
import com.intellij.vcs.commit.ChangeListCommitState
import com.intellij.vcs.commit.LocalChangesCommitter

class CommitInsCommand(val myProject: Project, val commitMsg: String) : InsCommand {
override fun execute(): String {
val changeListManager = ChangeListManager.getInstance(myProject)
changeListManager.changeLists.forEach {
val list: LocalChangeList = changeListManager.getChangeList(it.id) ?: return@forEach
val commitState = ChangeListCommitState(it, list.changes.toList(), commitMsg)
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
committer.runCommit("Commit", false)
GitUtil.doCommit(myProject, list, commitMsg)
}

return "Committing..."
}
}
}

0 comments on commit 71c3d69

Please sign in to comment.