Skip to content

Support mnemonic prefixes in git diff parsing for terminal links - #298490

Merged
Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
clintharrison:clint/git-diff-mnemonic-prefixes-in-terminal-links
Jul 13, 2026
Merged

Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
clintharrison:clint/git-diff-mnemonic-prefixes-in-terminal-links

Conversation

@clintharrison

@clintharrison Clint Harrison (clintharrison) commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Git supports a config option diff.mnemonicPrefix that sometimes uses characters other than a/ and b/ in diffs to distinguish where they came from. This PR updates the link parsing in the integrated terminal, so file paths are still detected when this option is enabled.

I updated the existing tests for this functionality.

Manual testing

Make some change in a git repo (e.g. echo "hello world" >>README.md).

Enable this config option and run git diff: git -c diff.mnemonicPrefix=true diff in the terminal will now be comparing the index and the working copy files:

diff --git i/README.md w/README.md
index 6f1e94e4844..0dc323dc715 100644
--- i/README.md
+++ w/README.md
@@ -76,3 +76,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
 Copyright (c) Microsoft Corporation. All rights reserved.
 
 Licensed under the [MIT](LICENSE.txt) license.
+hello world

With this change, README.md in each location should be underlined on hover and possible to open with ⌘/ctrl+click.
Notably, cmd-click will open README.md, and not attempt to find a file named w/README.md

CleanShot 2026-02-28 at 15 31 50@2x

Fixes #302823

Copilot AI review requested due to automatic review settings February 28, 2026 20:33
@clintharrison

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

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

Updates VS Code’s integrated terminal local-file link parsing so filenames in git diff output are correctly detected when diff.mnemonicPrefix is enabled (eg. i/ and w/ instead of a/ and b/), preventing links from including the mnemonic prefix as part of the path.

Changes:

  • Generalize git-diff prefix stripping to support mnemonic prefixes via small regex helpers.
  • Expand existing git-diff parsing tests to cover the additional mnemonic prefixes.

Reviewed changes

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

File Description
src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkParsing.ts Adds regex-based detection of git diff prefixes (a/, b/, c/, i/, o/, w/) so link ranges exclude the prefix consistently.
src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test.ts Parameterizes git-diff link parsing tests to validate mnemonic-prefix handling.
@clintharrison

Copy link
Copy Markdown
Contributor Author

Megan Rogge (@meganrogge) Daniel Imms (@Tyriar) Ladislau Szomoru (@lszomoru) is there a way to get a review on this small bugfix? This has been sitting idle with assignees for a few weeks.

@clintharrison

Copy link
Copy Markdown
Contributor Author

Just wanted to bump this Megan Rogge (@meganrogge) Daniel Imms (@Tyriar) Ladislau Szomoru (@lszomoru) - this is a small bugfix in an existing feature with tests updated and passing.

Can I please get a review?

@clintharrison

Copy link
Copy Markdown
Contributor Author

Lee Murray (@mrleemurray) Ulugbek Abdullaev (@ulugbekna) can I please get a review on this PR, or someone to explicitly acknowledge that it's not going to be accepted?

How does one get any response from a maintainer in this project?

@anthonykim1

Copy link
Copy Markdown
Contributor

Clint Harrison (@clintharrison) Apologies for the delay, and thanks much for the PR.

PR looks generally good,
We'd probably also benefit from adding support for numeric mnemonic prefixes like 1/ and 2/ that git uses for git diff --no-index
Ref: https://github.com/git/git/blob/f60db8d575adb79761d363e026fb49bddf330c73/diff-no-index.c#L425
, https://git-scm.com/docs/diff-config#Documentation/diff-config.txt-diffmnemonicPrefix

@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.130.0 milestone Jul 12, 2026
@meganrogge
Megan Rogge (meganrogge) merged commit 51ed891 into microsoft:main Jul 13, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

8 participants