Skip to content

Commit 1870425

Browse files
committed
feat(exec): add CommitInsCommand for executing commits #101
Add a new class `CommitInsCommand` to the `cc.unitmesh.devti.language.compiler.exec` package. This class is responsible for executing commits to the local Git repository. It takes a `Project` object and a commit message as parameters. The `execute()` method iterates over all the change lists in the project, creates a `ChangeListCommitState` object for each change list with the list of changes and the commit message, and then runs the commit using a `LocalChangesCommitter` object. Finally, it returns "Committing..." as the result of the execution.
1 parent 14e9439 commit 1870425

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

docs/devins/devins-language.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ code_contents ::= (NEWLINE | CODE_CONTENT)*
4848
- `/rev`: read git change by git revision
4949
- `/run`: run code
5050
- `/patch`: apply patches to file
51+
- `/commit`: commit changes to git
5152

5253
### File Command
5354

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ import cc.unitmesh.devti.language.psi.DevInUsed
99
import com.intellij.openapi.diagnostic.logger
1010
import com.intellij.openapi.editor.Editor
1111
import com.intellij.openapi.project.Project
12-
import com.intellij.openapi.vcs.changes.ChangeListManager
13-
import com.intellij.openapi.vcs.changes.CommitContext
14-
import com.intellij.openapi.vcs.changes.LocalChangeList
1512
import com.intellij.psi.PsiElement
1613
import com.intellij.psi.util.elementType
17-
import com.intellij.vcs.commit.ChangeListCommitState
18-
import com.intellij.vcs.commit.LocalChangesCommitter
1914

2015
data class CompileResult(
2116
var output: String = "",
@@ -148,7 +143,7 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
148143
if (devInCode == null) {
149144
PrintInsCommand("/" + commandNode.agentName + ":" + prop)
150145
} else {
151-
CommitInsCommand(myProject, prop, devInCode.text)
146+
CommitInsCommand(myProject, devInCode.text)
152147
}
153148
}
154149

@@ -198,16 +193,3 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
198193
}
199194

200195

201-
class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String) : InsCommand {
202-
override fun execute(): String? {
203-
val changeListManager = ChangeListManager.getInstance(myProject)
204-
changeListManager.changeLists.forEach {
205-
val list: LocalChangeList = changeListManager.getChangeList(it.id) ?: return@forEach
206-
val commitState = ChangeListCommitState(it, list.changes.toList(), commitMsg)
207-
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
208-
committer.runCommit("Commit", false)
209-
}
210-
211-
return "Committing..."
212-
}
213-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cc.unitmesh.devti.language.compiler.exec
2+
3+
import com.intellij.openapi.project.Project
4+
import com.intellij.openapi.vcs.changes.ChangeListManager
5+
import com.intellij.openapi.vcs.changes.CommitContext
6+
import com.intellij.openapi.vcs.changes.LocalChangeList
7+
import com.intellij.vcs.commit.ChangeListCommitState
8+
import com.intellij.vcs.commit.LocalChangesCommitter
9+
10+
class CommitInsCommand(val myProject: Project, val commitMsg: String) : InsCommand {
11+
override fun execute(): String {
12+
val changeListManager = ChangeListManager.getInstance(myProject)
13+
changeListManager.changeLists.forEach {
14+
val list: LocalChangeList = changeListManager.getChangeList(it.id) ?: return@forEach
15+
val commitState = ChangeListCommitState(it, list.changes.toList(), commitMsg)
16+
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
17+
committer.runCommit("Commit", false)
18+
}
19+
20+
return "Committing..."
21+
}
22+
}

0 commit comments

Comments
 (0)