Skip to content

Conversation

@Ownistic
Copy link

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

#3431

Previously, the orchestrator would query for all staged/unstaged changes and then
filter them, which was inefficient and failed if no general changes existed.
This commit inverts the logic to construct changes directly from the list of
selected files provided by the JetBrains plugin, ensuring it correctly uses the user's
selection.
@changeset-bot
Copy link

changeset-bot bot commented Nov 21, 2025

⚠️ No Changeset found

Latest commit: ae712aa

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant