Skip to content

Git - resolve the active notebook for Open Changes / Open File#326468

Open
soreavis wants to merge 1 commit into
microsoft:mainfrom
soreavis:fix/176401-git-open-notebooks
Open

Git - resolve the active notebook for Open Changes / Open File#326468
soreavis wants to merge 1 commit into
microsoft:mainfrom
soreavis:fix/176401-git-open-notebooks

Conversation

@soreavis

Copy link
Copy Markdown

Fixes #176401

Problem

Git: Open Changes, Git: Open File and Git: Open File (HEAD) do nothing for notebooks when invoked from a keybinding (or the command palette), even though the editor-title buttons and the SCM context menu work. git.openChange logs Invoking command git.openChange and then silently returns.

Cause

The keybinding path of these commands resolves the target through getSCMResource, whose fallback only looked at window.activeTextEditor. That is undefined when a notebook editor is active (and a focused cell is a vscode-notebook-cell editor, which the file-scheme check rejects), so no resource is found and the command returns. The buttons/menu work because they pass the resource explicitly.

Fix

In getSCMResource, resolve window.activeNotebookEditor?.notebook.uri before falling back to the active text editor, and — since a notebook diff editor is neither the active text nor notebook editor — fall back to the active TabInputNotebookDiff's modified resource so Open File can toggle back from an open notebook diff. This gives notebooks the same round-trip behavior text files already have.

Validation

Verified in a dev build with alt+dgit.openChange, alt+fgit.openFile:

Case Before After
Notebook active → Open Changes no-op opens notebook diff
Notebook diff active → Open File no-op back to the notebook
Focused cell → Open Changes no-op opens notebook diff
Text file (both directions) works unchanged

Added a git smoke test covering both directions (active notebook → Open Changes, then Open File back from the notebook diff). Full git integration suite green.

getSCMResource is shared, so git.stage/git.unstage/git.clean invoked via keybinding while a notebook is active now resolve the notebook file too, consistent with how they already work for text files.

The keybinding path of git.openChange, git.openFile and git.openHEADFile
resolves the target through getSCMResource, which only considered
window.activeTextEditor. That is undefined when a notebook editor is
active, so the commands silently did nothing for notebooks while the
editor-title buttons and SCM context menu (which pass the resource) kept
working.

Resolve the notebook uri from window.activeNotebookEditor first, and fall
back to a notebook diff editor's modified resource so Open File can toggle
back from an open notebook diff, matching the text-editor behavior.

Fixes microsoft#176401
Copilot AI review requested due to automatic review settings July 18, 2026 19:11
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/commands.ts
  • extensions/git/src/test/smoke.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes Git commands failing to resolve active notebook resources.

Changes:

  • Resolves active notebooks and notebook diffs in getSCMResource.
  • Adds smoke coverage for opening notebook changes and returning to the file.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
extensions/git/src/commands.ts Adds notebook-aware SCM resource resolution.
extensions/git/src/test/smoke.test.ts Tests notebook diff round-tripping.

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

Successfully merging this pull request may close these issues.

Git - "Git: Open Changes" and "Git: Open File" do not work for notebooks

3 participants