Skip to content

Commit 96c45a6

Browse files
committed
Replace individual prompt removal with bulk cleanup of committed file references from prompts
- when a prompt is chosen for commit, we should remove from its object in 'prompts-for-commit.json' file paths that are chosen to commit. The overall object should be only removed if all files are chosen for commit
1 parent b7522cb commit 96c45a6

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ export const generate_commit_message_command = (
247247

248248
repository.inputBox.value = edited_message + selected_prompts_text
249249
await vscode.commands.executeCommand('git.commit', repository)
250-
relevant_prompts.forEach((p) => {
251-
PromptsForCommitMessagesUtils.remove({
252-
context,
253-
prompt: p.prompt
254-
})
250+
PromptsForCommitMessagesUtils.remove_committed_files({
251+
context,
252+
workspace_root,
253+
prompts: relevant_prompts.map((p) => p.prompt),
254+
committed_files: staged_files
255255
})
256256
} else if (was_empty_stage) {
257257
await vscode.commands.executeCommand('git.unstageAll')

‎apps/editor/src/utils/prompts-for-commit-messages-utils.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,41 @@ export namespace PromptsForCommitMessagesUtils {
160160
})
161161
}
162162
}
163+
164+
export const remove_committed_files = (params: {
165+
context: vscode.ExtensionContext
166+
workspace_root: string
167+
prompts: string[]
168+
committed_files: string[]
169+
}) => {
170+
const all_prompts = load_all(params.context)
171+
if (!all_prompts[params.workspace_root]) return
172+
173+
let changed = false
174+
const committed_set = new Set(params.committed_files)
175+
const prompt_set = new Set(params.prompts)
176+
177+
all_prompts[params.workspace_root] = all_prompts[params.workspace_root]
178+
.map((p) => {
179+
if (!prompt_set.has(p.prompt)) return p
180+
const filtered_files = p.files.filter((f) => !committed_set.has(f))
181+
if (filtered_files.length != p.files.length) {
182+
changed = true
183+
return { ...p, files: filtered_files }
184+
}
185+
return p
186+
})
187+
.filter((p) => p.files.length > 0)
188+
189+
if (all_prompts[params.workspace_root].length == 0) {
190+
delete all_prompts[params.workspace_root]
191+
}
192+
193+
if (changed) {
194+
save_all({
195+
context: params.context,
196+
prompts: all_prompts
197+
})
198+
}
199+
}
163200
}

0 commit comments

Comments
 (0)