fix(jetbrains): use selected files for commit message generation
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 selectedFiles is provided by the plugin, we now bypass the general Git query entirely and construct the necessary GitChange objects 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:- Modified
resolveCommitChangesto check forselectedFilesfirst. - If present, it now maps the file paths directly to
GitChangeobjects, assuming a 'Modified' and 'unstaged' status, which is a safe default for commit dialog selections. - This change is more efficient and directly addresses the user's intent.
- Modified
-
jetbrains/plugin/src/main/kotlin/ai/kilocode/jetbrains/git/FileDiscoveryService.kt:- The core logic for discovering files was improved to be more explicit in its strategy order.
How to Test
- Make changes to multiple files in your project (e.g., modify
fileA.ts,fileB.ts, andfileC.ts). - Open the Git commit window (
Ctrl+KorCmd+K). - Select only one or two of the changed files (e.g.,
fileA.tsandfileC.ts), leavingfileB.tsunselected. - Trigger the Kilo Code commit message generation.
-
Expected Result: The generated commit message should only reference and be based on the changes in
fileA.tsandfileC.ts. - Incorrect Behavior (Before this fix): The message would have been based on all three files, or failed if no files were staged.
Related issue
Resolve: #3431
⚠️ No Changeset found
Latest commit: 5f8b844eda1af89f0ff5bd6a6eb6d140ccb42379
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
We're all from #3431 waiting for the review