Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode.diff fails with valid git: URIs constructed from tracked, staged files #245054

Open
JohnAllenTech opened this issue Mar 30, 2025 · 2 comments
Assignees

Comments

@JohnAllenTech
Copy link

JohnAllenTech commented Mar 30, 2025

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: Version: 1.98.2 (Universal)
    Commit: ddc367e
    Date: 2025-03-12T13:32:45.399Z (2 wks ago)
    Electron: 34.2.0
    ElectronBuildId: 11161602
    Chromium: 132.0.6834.196
    Node.js: 20.18.2
    V8: 13.2.152.36-electron.0
    OS: Darwin arm64 24.1.0

Steps to Reproduce

  1. Create or modify a file that is tracked by Git and has already been committed at least once.
  2. Use a VS Code extension to programmatically attempt a diff between the git: version of the file and the working tree version:
// `target` is a `Change` from the Git API (`indexChanges` or `workingTreeChanges`)
const left = target.originalUri && target.originalUri.toString() !== target.uri.toString()
  ? target.originalUri
  : target.uri.with({ scheme: 'git', query: isStaged ? '^' : '~' });

const right = target.uri;
vscode.commands.executeCommand('vscode.diff', left, right, title);
  1. Observe that the diff does not open, despite:
    • The file being modified and committed
    • The Source Control panel correctly showing a diff
    • The constructed left URI being well-formed:
      git:/Users/.../file.json?^
      

Expected Behavior

VS Code should open a diff between the git: URI and the file: URI for a staged or modified file, just like the built-in Source Control view.


Actual Behavior

The file does not open in diff view. The command fails silently or falls back to a plain editor. In some cases, target.originalUri is either:

  • Undefined
  • Identical to target.uri, resulting in no diff view

Manually constructing git: URIs using .with({ scheme: 'git', query: '^' }) or ?~ fails even for valid files.


Additional Info

We have also tested:

  • Using Uri.from(...) with authority
  • Using fully normalized Uri.file(...)
  • Logging and comparing uri and originalUri
  • Ensuring the file is in a valid Git state (tracked, staged, or committed)

This appears to be a gap in how vscode.diff resolves manually created git: URIs compared to URIs internally created by the Git extension.


Ask

Can the VS Code team:

  • Confirm the correct and supported way to programmatically open a diff using vscode.diff for staged or modified files?
  • Clarify what structure or metadata the Git extension expects in a git: URI to resolve correctly?
  • Provide a public helper in the Git API to generate valid diffable URIs?

Thank you!

Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.98.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@JohnAllenTech
Copy link
Author

Thanks for the suggestion. I have updated to the latest version of vscode and I am still experiencing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants