diff --git a/src/ai/aiProviderService.ts b/src/ai/aiProviderService.ts index 198e94b..d48b42c 100644 --- a/src/ai/aiProviderService.ts +++ b/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; diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index eb958f3..1b4d360 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -2744,17 +2744,22 @@ export class LocalGitProvider implements GitProvider, Disposable { ref2?: string, options?: { context?: number }, ): Promise { + 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;