Skip to content

Commit 4f22ef5

Browse files
committed
Refactor get_prompt_data to accept a GitRepository instance instead of resolving it internally
1 parent 780bc6d commit 4f22ef5

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-command/generate-commit-message-command.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import {
44
get_git_repository,
5-
prepare_staged_changes
5+
prepare_staged_changes,
6+
GitRepository
67
} from '../../utils/git-repository-utils'
78
import { display_token_count } from '../../utils/display-token-count'
89
import { get_commit_message_config } from './utils/get-commit-message-config'
@@ -23,19 +24,18 @@ export const generate_commit_message_command = (
2324
context: vscode.ExtensionContext
2425
) => {
2526
const get_prompt_data = async (
26-
source_control?: vscode.SourceControl,
27+
repository: GitRepository,
28+
is_source_control_action: boolean,
2729
selection_state?: { files?: string[] }
2830
) => {
29-
const repository = await get_git_repository(source_control)
30-
if (!repository) return null
3131
await vscode.workspace.saveAll()
3232
await repository.status()
3333
const was_empty_stage = (repository.state.indexChanges || []).length == 0
3434
const working_tree_changes = repository.state.workingTreeChanges || []
3535
const is_single_change = was_empty_stage && working_tree_changes.length == 1
3636
const diff = await prepare_staged_changes(
3737
repository,
38-
!!source_control,
38+
is_source_control_action,
3939
selection_state
4040
)
4141
if (!diff) return null
@@ -52,10 +52,17 @@ export const generate_commit_message_command = (
5252
let force_quick_pick = false
5353
const selection_state: { files?: string[] } = {}
5454

55+
const repository = await get_git_repository(params.source_control)
56+
if (!repository) return
57+
5558
while (true) {
56-
const data = await get_prompt_data(params.source_control, selection_state)
59+
const data = await get_prompt_data(
60+
repository,
61+
!!params.source_control,
62+
selection_state
63+
)
5764
if (!data) return
58-
const { repository, message_prompt, is_single_change } = data
65+
const { message_prompt, is_single_change } = data
5966
let { was_empty_stage } = data
6067

6168
// token count for the prompt, used in the config UI
@@ -284,7 +291,9 @@ export const generate_commit_message_command = (
284291
const copy_command = vscode.commands.registerCommand(
285292
'codeWebChat.copyCommitMessagePrompt',
286293
async (source_control?: vscode.SourceControl) => {
287-
const data = await get_prompt_data(source_control)
294+
const repository = await get_git_repository(source_control)
295+
if (!repository) return
296+
const data = await get_prompt_data(repository, !!source_control)
288297
if (!data) return
289298
const { was_empty_stage, message_prompt } = data
290299

0 commit comments

Comments
 (0)