Skip to content

Commit 1b8f006

Browse files
committed
fix(commit): can not generate commit message when updating submodule
Closes #303
1 parent 06274ff commit 1b8f006

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- Common branch is not detected when most files are unassociated with branches, despite at least one file belonging to a branch.
8+
- Cannot generate commit message when updating a submodule.
89

910
## [2.10.0] - 2025-04-08
1011

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/AICommitsExtensions.kt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.github.blarc.ai.commits.intellij.plugin
22

33
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
4+
import com.intellij.openapi.project.Project
45
import com.intellij.openapi.ui.ValidationInfo
56
import com.intellij.openapi.vcs.FilePath
67
import com.intellij.openapi.vcs.changes.Change
78
import com.intellij.ui.dsl.builder.Cell
89
import com.intellij.ui.layout.ValidationInfoBuilder
910
import com.intellij.util.ui.ColumnInfo
1011
import com.intellij.util.ui.ComponentWithEmptyText
12+
import git4idea.repo.GitRepository
13+
import git4idea.repo.GitRepositoryManager
1114
import javax.swing.JComponent
1215

13-
fun <T, O> createColumn(name: String, formatter: (T) -> O) : ColumnInfo<T, O> {
16+
fun <T, O> createColumn(name: String, formatter: (T) -> O): ColumnInfo<T, O> {
1417
return object : ColumnInfo<T, O>(name) {
1518
override fun valueOf(item: T): O {
1619
return formatter(item)
@@ -19,10 +22,10 @@ fun <T, O> createColumn(name: String, formatter: (T) -> O) : ColumnInfo<T, O> {
1922
}
2023

2124
fun ValidationInfoBuilder.notBlank(value: String): ValidationInfo? =
22-
if (value.isBlank()) error(message("validation.required")) else null
25+
if (value.isBlank()) error(message("validation.required")) else null
2326

2427

25-
fun ValidationInfoBuilder.temperatureValid(value: String): ValidationInfo? {
28+
fun ValidationInfoBuilder.temperatureValid(value: String): ValidationInfo? {
2629
if (value.isNotBlank()) {
2730
value.toFloatOrNull().let {
2831
if (it != null && it in 0.0..2.0) {
@@ -34,10 +37,10 @@ fun ValidationInfoBuilder.temperatureValid(value: String): ValidationInfo? {
3437
}
3538

3639
fun ValidationInfoBuilder.unique(value: String, existingValues: Set<String>): ValidationInfo? =
37-
if (existingValues.contains(value)) error(message("validation.unique")) else null
40+
if (existingValues.contains(value)) error(message("validation.unique")) else null
3841

3942
fun ValidationInfoBuilder.isInt(value: String): ValidationInfo? {
40-
if (value.isBlank()){
43+
if (value.isBlank()) {
4144
return null
4245
}
4346

@@ -51,7 +54,7 @@ fun ValidationInfoBuilder.isInt(value: String): ValidationInfo? {
5154
}
5255

5356
fun ValidationInfoBuilder.isFloat(value: String): ValidationInfo? {
54-
if (value.isBlank()){
57+
if (value.isBlank()) {
5558
return null
5659
}
5760

@@ -65,7 +68,7 @@ fun ValidationInfoBuilder.isFloat(value: String): ValidationInfo? {
6568
}
6669

6770
fun ValidationInfoBuilder.isDouble(value: String): ValidationInfo? {
68-
if (value.isBlank()){
71+
if (value.isBlank()) {
6972
return null
7073
}
7174

@@ -79,7 +82,7 @@ fun ValidationInfoBuilder.isDouble(value: String): ValidationInfo? {
7982
}
8083

8184
// Adds emptyText method to all cells that contain a component that implements ComponentWithEmptyText class
82-
fun <T>Cell<T>.emptyText(emptyText: String) : Cell<T> where T : JComponent, T : ComponentWithEmptyText {
85+
fun <T> Cell<T>.emptyText(emptyText: String): Cell<T> where T : JComponent, T : ComponentWithEmptyText {
8386
this.component.emptyText.text = emptyText
8487
return this
8588
}
@@ -105,3 +108,19 @@ fun String.wrap(length: Int): String {
105108
fun Change.filePath(): FilePath? {
106109
return afterRevision?.file ?: beforeRevision?.file
107110
}
111+
112+
fun Change.isSubmoduleChange(project: Project): Boolean {
113+
val repositoryManager = GitRepositoryManager.getInstance(project)
114+
115+
val virtualFile = this.virtualFile ?: return false
116+
val fileRepositoryUrl = repositoryManager.getRepositoryForFileQuick(virtualFile)
117+
?.remotes
118+
?.firstOrNull()
119+
?.firstUrl ?: return false
120+
121+
return repositoryManager.repositories
122+
.flatMap(GitRepository::getSubmodules)
123+
.map { it.url }
124+
.any { it == fileRepositoryUrl }
125+
}
126+

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/AICommitsUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ object AICommitsUtils {
122122
) to change
123123
}
124124
}
125+
.filter { !it.second.isSubmoduleChange(project) }
125126
.groupBy({ it.first }, { it.second })
126127

127128

0 commit comments

Comments
 (0)