|
1 | 1 | import type { CancellationToken, TextEditor, Uri } from 'vscode'; |
2 | 2 | import { ProgressLocation } from 'vscode'; |
3 | | -import type { Source } from '../constants.telemetry'; |
4 | 3 | import type { Container } from '../container'; |
5 | 4 | import { GitUri } from '../git/gitUri'; |
6 | 5 | import type { GitBranch } from '../git/models/branch'; |
7 | 6 | import { showGenericErrorMessage } from '../messages'; |
8 | 7 | import type { AIExplainSource } from '../plus/ai/aiProviderService'; |
9 | 8 | import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker'; |
10 | | -import { getBestRepositoryOrShowPicker, getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker'; |
| 9 | +import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker'; |
11 | 10 | import { command } from '../system/-webview/command'; |
12 | 11 | import { showMarkdownPreview } from '../system/-webview/markdown'; |
13 | 12 | import { Logger } from '../system/logger'; |
14 | | -import { getSettledValue } from '../system/promise'; |
15 | 13 | import { GlCommandBase } from './commandBase'; |
16 | 14 | import { getCommandUri } from './commandBase.utils'; |
17 | 15 | import type { CommandContext } from './commandContext'; |
@@ -134,161 +132,6 @@ export class ExplainBranchCommand extends GlCommandBase { |
134 | 132 | } |
135 | 133 | } |
136 | 134 |
|
137 | | -export interface ExplainBranchCommandArgs2 { |
138 | | - repoPath: string; |
139 | | - branch: string; |
140 | | - source?: Source; |
141 | | -} |
142 | | - |
143 | | -@command() |
144 | | -export class ExplainBranchCommand2 extends GlCommandBase { |
145 | | - constructor(private readonly container: Container) { |
146 | | - super('gitlens.ai.explainBranch'); |
147 | | - } |
148 | | - |
149 | | - async execute(args?: ExplainBranchCommandArgs2): Promise<void> { |
150 | | - let repo; |
151 | | - if (args?.repoPath != null) { |
152 | | - repo = this.container.git.getRepository(args.repoPath); |
153 | | - } |
154 | | - repo ??= await getRepositoryOrShowPicker( |
155 | | - 'Explain Branch', |
156 | | - 'Choose which repository to explain a branch from', |
157 | | - undefined, |
158 | | - ); |
159 | | - if (repo == null) return; |
160 | | - |
161 | | - try { |
162 | | - // If no ref is provided, show a picker to select a branch |
163 | | - if (args == null) { |
164 | | - const pick = await showReferencePicker(repo.path, 'Explain Branch', 'Choose a branch to explain', { |
165 | | - include: ReferencesQuickPickIncludes.Branches, |
166 | | - sort: { branches: { current: true } }, |
167 | | - }); |
168 | | - if (pick?.ref == null) return; |
169 | | - |
170 | | - args = { |
171 | | - repoPath: repo.path, |
172 | | - branch: pick.ref, |
173 | | - }; |
174 | | - } |
175 | | - |
176 | | - // Get the branch |
177 | | - const branch = await repo.git.branches().getBranch(args.branch); |
178 | | - if (branch == null) { |
179 | | - void showGenericErrorMessage('Unable to find the specified branch'); |
180 | | - return; |
181 | | - } |
182 | | - const headRef = branch.ref; |
183 | | - const baseRef = branch.upstream?.name; |
184 | | - |
185 | | - // Get the diff between the branch and its upstream or base |
186 | | - const [diffResult, logResult] = await Promise.allSettled([ |
187 | | - repo.git.diff().getDiff?.(headRef, baseRef, { notation: '...' }), |
188 | | - repo.git.commits().getLog(`${baseRef}..${headRef}`), |
189 | | - ]); |
190 | | - |
191 | | - const diff = getSettledValue(diffResult); |
192 | | - const log = getSettledValue(logResult); |
193 | | - |
194 | | - if (!diff?.contents || !log?.commits?.size) { |
195 | | - void showGenericErrorMessage('No changes found to explain'); |
196 | | - } |
197 | | - } catch (ex) { |
198 | | - Logger.error(ex, 'ExplainBranchCommand', 'execute'); |
199 | | - void showGenericErrorMessage('Unable to explain branch'); |
200 | | - } |
201 | | - } |
202 | | -} |
203 | | - |
204 | | -// export interface ExplainBranchCommandArgs { |
205 | | -// repoPath: string; |
206 | | -// branch: GitBranchReference; |
207 | | -// source?: Source; |
208 | | -// } |
209 | | - |
210 | | -// @command() |
211 | | -// export class ExplainBranchCommand extends GlCommandBase { |
212 | | -// constructor(private readonly container: Container) { |
213 | | -// super('gitlens.ai.explainBranch'); |
214 | | -// } |
215 | | - |
216 | | -// async execute(args?: ExplainBranchCommandArgs): Promise<void> { |
217 | | -// try { |
218 | | -// // I'm declining it for now, because it can be a behaviour for "explain comparison" command, |
219 | | -// // that can be called either from the command palette or from the compare view. |
220 | | -// const comparisonResult = await showComparisonPicker(this.container, args?.repoPath, { |
221 | | -// head: args?.branch, |
222 | | -// getTitleAndPlaceholder: step => { |
223 | | -// switch (step) { |
224 | | -// case 1: |
225 | | -// return { |
226 | | -// title: 'Explain Branch', |
227 | | -// placeholder: 'Choose a branch to explain', |
228 | | -// }; |
229 | | -// case 2: |
230 | | -// return { |
231 | | -// title: `Explain Branch \u2022 Select Base to Start From`, |
232 | | -// placeholder: 'Choose a base branch to explain from', |
233 | | -// }; |
234 | | -// } |
235 | | -// }, |
236 | | -// }); |
237 | | -// if (comparisonResult == null) return; |
238 | | - |
239 | | -// const repo = this.container.git.getRepository(comparisonResult.repoPath); |
240 | | -// if (repo == null) return; |
241 | | - |
242 | | -// const mergeBase = await repo.git.refs().getMergeBase(comparisonResult.head.ref, comparisonResult.base.ref); |
243 | | - |
244 | | -// const [diffResult, logResult] = await Promise.allSettled([ |
245 | | -// repo.git.diff().getDiff?.(comparisonResult.head.ref, mergeBase, { notation: '...' }), |
246 | | -// repo.git.commits().getLog(`${mergeBase}..${comparisonResult.head.ref}`), |
247 | | -// ]); |
248 | | - |
249 | | -// const diff = getSettledValue(diffResult); |
250 | | -// const log = getSettledValue(logResult); |
251 | | - |
252 | | -// if (!diff?.contents || !log?.commits?.size) { |
253 | | -// void showGenericErrorMessage('No changes found to explain'); |
254 | | -// return; |
255 | | -// } |
256 | | - |
257 | | -// const commitMessages: string[] = []; |
258 | | -// for (const commit of [...log.commits.values()].sort((a, b) => a.date.getTime() - b.date.getTime())) { |
259 | | -// commitMessages.push(commit.message ?? commit.summary); |
260 | | -// } |
261 | | - |
262 | | -// const result = await this.container.ai.explainChanges( |
263 | | -// { |
264 | | -// diff: diff.contents, |
265 | | -// message: commitMessages.join('\n\n'), |
266 | | -// }, |
267 | | -// { |
268 | | -// source: 'commandPalette', |
269 | | -// ...args?.source, |
270 | | -// type: 'branch', |
271 | | -// }, |
272 | | -// { |
273 | | -// progress: { location: ProgressLocation.Notification, title: 'Explaining branch changes...' }, |
274 | | -// }, |
275 | | -// ); |
276 | | - |
277 | | -// // Display the result |
278 | | -// let content = `# Branch: ${comparisonResult.head.name}\n`; |
279 | | -// if (result != null) { |
280 | | -// content += `> Generated by ${result.model.name}\n\n----\n\n${result?.parsed.summary}\n\n${result?.parsed.body}`; |
281 | | -// } else { |
282 | | -// content += `> No changes found to explain.`; |
283 | | -// } |
284 | | -// void showMarkdownPreview(content); |
285 | | -// } catch (ex) { |
286 | | -// Logger.error(ex, 'ExplainBranchCommand', 'execute'); |
287 | | -// void showGenericErrorMessage('Unable to explain branch'); |
288 | | -// } |
289 | | -// } |
290 | | -// } |
291 | | - |
292 | 135 | async function getMergeTarget( |
293 | 136 | container: Container, |
294 | 137 | branch: GitBranch, |
|
0 commit comments