fix(jetbrains): use selected files for commit message generation #3943
+114
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
This PR fixes a bug where the commit message generator in the JetBrains extension was not correctly using the files selected by the user in the commit dialog. Instead, it would either use all changes in the repository or fail with a "No changes found" error. This was frustrating for users who wanted to generate a message for a specific, partial set of changes.
Implementation
The root cause was in the
CommitMessageOrchestrator. The original logic would first query Git for all staged or unstaged changes and then attempt to filter that list based on the user's selection. This approach was flawed because the initial query could return no results, causing a failure, even when the user had explicitly selected files.This PR inverts that logic. If a list of
selectedFilesis provided by the plugin, we now bypass the general Git query entirely and construct the necessaryGitChangeobjects directly from the file paths. This ensures that the user's explicit choice is always respected. The original logic is kept as a fallback for cases where no files are pre-selected.Key changes:
src/services/commit-message/CommitMessageOrchestrator.ts:resolveCommitChangesto check forselectedFilesfirst.GitChangeobjects, assuming a 'Modified' and 'unstaged' status, which is a safe default for commit dialog selections.jetbrains/plugin/src/main/kotlin/ai/kilocode/jetbrains/git/FileDiscoveryService.kt:How to Test
fileA.ts,fileB.ts, andfileC.ts).Ctrl+KorCmd+K).fileA.tsandfileC.ts), leavingfileB.tsunselected.fileA.tsandfileC.ts.Related issue
#3431