瀏覽代碼

Fixes diff to uncommitted

main
Eric Amodio 1 年之前
父節點
當前提交
6858c2a715
共有 2 個檔案被更改,包括 17 行新增6 行删除
  1. +3
    -3
      src/ai/aiProviderService.ts
  2. +14
    -3
      src/env/node/git/localGitProvider.ts

+ 3
- 3
src/ai/aiProviderService.ts 查看文件

@ -75,9 +75,9 @@ export class AIProviderService implements Disposable {
if (repository == null) throw new Error('Unable to find repository');
let diff = await this.container.git.getDiff(repository.uri, uncommittedStaged);
if (diff == null) {
if (!diff?.contents) {
diff = await this.container.git.getDiff(repository.uri, uncommitted);
if (diff == null) throw new Error('No changes to generate a commit message from.');
if (!diff?.contents) throw new Error('No changes to generate a commit message from.');
}
if (options?.cancellation?.isCancellationRequested) return undefined;
@ -128,7 +128,7 @@ export class AIProviderService implements Disposable {
if (commit == null) throw new Error('Unable to find commit');
const diff = await this.container.git.getDiff(commit.repoPath, commit.sha);
if (diff == null) throw new Error('No changes found to explain.');
if (!diff?.contents) throw new Error('No changes found to explain.');
const provider = this.provider;

+ 14
- 3
src/env/node/git/localGitProvider.ts 查看文件

@ -2744,17 +2744,22 @@ export class LocalGitProvider implements GitProvider, Disposable {
ref2?: string,
options?: { context?: number },
): Promise<GitDiff | undefined> {
const scope = getLogScope();
const params = [`-U${options?.context ?? 3}`];
if (ref1 === uncommitted) {
if (ref2 != null) {
params.push(ref2);
} else {
// Get only unstaged changes
ref2 = 'HEAD';
}
} else if (ref1 === uncommittedStaged) {
// Get up to staged changes
params.push('--staged');
if (ref2 != null) {
params.push(ref2);
} else {
// Get only staged changes
ref2 = 'HEAD';
}
} else if (ref2 == null) {
@ -2769,8 +2774,14 @@ export class LocalGitProvider implements GitProvider, Disposable {
params.push(ref1, ref2);
}
const data = await this.git.diff2(repoPath, undefined, ...params);
if (!data) return undefined;
let data;
try {
data = await this.git.diff2(repoPath, { errors: GitErrorHandling.Throw }, ...params);
} catch (ex) {
debugger;
Logger.error(ex, scope);
return undefined;
}
const diff: GitDiff = { baseSha: ref2, contents: data };
return diff;

Loading…
取消
儲存