kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

fix(jetbrains): use selected files for commit message generation

Open Ownistic opened this issue 1 month ago • 1 comments

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 resolveCommitChanges to check for selectedFiles first.
    • If present, it now maps the file paths directly to GitChange objects, 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.
  • 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

  1. Make changes to multiple files in your project (e.g., modify fileA.ts, fileB.ts, and fileC.ts).
  2. Open the Git commit window (Ctrl+K or Cmd+K).
  3. Select only one or two of the changed files (e.g., fileA.ts and fileC.ts), leaving fileB.ts unselected.
  4. Trigger the Kilo Code commit message generation.
  5. Expected Result: The generated commit message should only reference and be based on the changes in fileA.ts and fileC.ts.
  6. 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

Ownistic avatar Nov 21 '25 10:11 Ownistic

⚠️ 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

changeset-bot[bot] avatar Nov 21 '25 10:11 changeset-bot[bot]

We're all from #3431 waiting for the review

SumJest avatar Dec 03 '25 11:12 SumJest