Skip to content

[codex] fix(vscode): fall back to git CLI for diffs#12091

Open
yzlu0917 wants to merge 2 commits intocontinuedev:mainfrom
yzlu0917:codex/issue-9136-vscode-gitdiff-fallback
Open

[codex] fix(vscode): fall back to git CLI for diffs#12091
yzlu0917 wants to merge 2 commits intocontinuedev:mainfrom
yzlu0917:codex/issue-9136-vscode-gitdiff-fallback

Conversation

@yzlu0917
Copy link
Copy Markdown

@yzlu0917 yzlu0917 commented Apr 9, 2026

Summary

  • keep using the VS Code Git extension as the primary source for diffs
  • fall back to git diff / git diff --cached from workspace or repo roots when the Git API returns no diff content
  • add regression coverage for splitting combined diffs and CLI fallback behavior

Why

In some remote environments such as WSL, Continue can end up with an empty diff from the VS Code Git API even though git diff in the integrated terminal shows changes. That causes the @Git Diff context provider to incorrectly say Git shows no current changes.

This change preserves the existing fast path but adds a CLI fallback so diff context still works when the Git extension cannot provide the patch content.

Validation

  • ran npx vitest run src/util/gitDiffFallback.vitest.ts in extensions/vscode
  • ran git diff --check

Closes #9136


Summary by cubic

Add a CLI fallback for git diffs in VS Code so the @Git Diff context works when the Git API returns no content (e.g., WSL/remote). Keeps the Git API as the fast path and falls back to git diff --cached and optionally git diff from repo/workspace roots. Fixes #9136.

  • Bug Fixes
    • Discover repo roots via git rev-parse --show-toplevel, dedupe, and skip non-git dirs before running CLI diffs with a 10MB buffer.
    • Split combined patch output into per-file entries with splitGitDiff, returning only non-empty diffs.
    • Use the CLI fallback in ideUtils when API diffs are empty; added vitest coverage for split logic and fallback behavior.

Written for commit c55df2e. Summary will update on new commits.

@yzlu0917 yzlu0917 requested a review from a team as a code owner April 9, 2026 08:48
@yzlu0917 yzlu0917 requested review from sestinj and removed request for a team April 9, 2026 08:48
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/vscode/src/util/gitDiffFallback.ts">

<violation number="1" location="extensions/vscode/src/util/gitDiffFallback.ts:12">
P2: Diff splitting regex is not line-anchored, so hunk content containing `diff --git ...` can be misinterpreted as a new file header and corrupt split results.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

const GIT_DIFF_MAX_BUFFER = 10 * 1024 * 1024;

export function splitGitDiff(diffString: string): string[] {
const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/;
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Diff splitting regex is not line-anchored, so hunk content containing diff --git ... can be misinterpreted as a new file header and corrupt split results.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/vscode/src/util/gitDiffFallback.ts, line 12:

<comment>Diff splitting regex is not line-anchored, so hunk content containing `diff --git ...` can be misinterpreted as a new file header and corrupt split results.</comment>

<file context>
@@ -0,0 +1,69 @@
+const GIT_DIFF_MAX_BUFFER = 10 * 1024 * 1024;
+
+export function splitGitDiff(diffString: string): string[] {
+  const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/;
+  const diffs = diffString.split(fileDiffHeaderRegex);
+
</file context>
Suggested change
const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/;
const fileDiffHeaderRegex = /(?=^diff --git a\/.* b\/.*$)/m;
Fix with Cubic

@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

setFetchedModelsList((prev) =>
selectedProvider.provider === providerAtFetchTime ? models : prev,

P2 Badge Keep async model fetches scoped to the current provider

The guard in setFetchedModelsList compares selectedProvider.provider to providerAtFetchTime, but both values are captured from the same render, so this condition is effectively always true for that request. If a user starts fetching models, switches providers before the request resolves, and the old request returns later, the old provider's model list can overwrite the current provider's options, leading to mismatched selections and incorrect model/provider combinations being saved.


const base = apiBase || "https://generativelanguage.googleapis.com/v1beta/";
const url = new URL("models", base);

P2 Badge Preserve Gemini API base path when composing /models URL

Constructing the endpoint with new URL("models", base) breaks for user-provided Gemini apiBase values that omit a trailing slash (for example, .../v1beta resolves to .../models instead of .../v1beta/models). In that common input form, model fetching hits the wrong endpoint and fails, so the Add Model flow cannot discover Gemini models even with a valid key/base pair.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yzlu0917 yzlu0917 force-pushed the codex/issue-9136-vscode-gitdiff-fallback branch from e030a32 to 5f109aa Compare April 9, 2026 11:29
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

@Git Diff context provider fails in WSL (Remote) - "Git shows no current changes"

1 participant