Git: Use stash hash instead of index for editor identity#288616
Open
ynss wants to merge 1 commit intomicrosoft:mainfrom
Open
Git: Use stash hash instead of index for editor identity#288616ynss wants to merge 1 commit intomicrosoft:mainfrom
ynss wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where stash diff editors would incorrectly redirect when stash indices change. The fix replaces index-based stash identification with hash-based identification using the stash commit hash.
Changes:
- Changed stash artifact IDs from
stash@{index}format to commit hash for stable identification - Updated stash URI generation to use hash instead of index
- Refactored stash lookup methods to find stashes by hash rather than index
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| extensions/git/src/artifactProvider.ts | Changes stash artifact ID from stash@{index} to the commit hash for stable identification |
| extensions/git/src/commands.ts | Updates stash identification logic throughout: getStashFromUri now validates and matches by hash, _viewStash uses hash in URIs, adds _findStashByArtifactId helper, and updates all artifact stash commands to look up by hash |
View stash relies on stash index, but if a new stash is created while the last one is shown in editor, trying to open the now recent one with index 0 will not work, it will redirect to the already opened now stash 1. This results in random behavior and seems like if the recent stash wasn't saved correctly or lost. With unique hash per stash, every opened editor is linked to its exact stash diff, and trying to open any new stash will open a new tab.
0944b36 to
ee8d123
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
View stash relies on stash index, but if a new stash is created while the last one is shown in editor, trying to open the now recent one with index 0 will not work, it will redirect to the already opened now stash 1.
I found this bug when I pinned a stash A diff editor, then worked on something else and created a new stash B. When I tried to open the recent stash B, VS Code redirected me to the pinned editor showing the OLD stash A instead. This was very confusing - I thought my recent stash wasn't saved correctly or was lost, and almost started redoing the changes A from scratch, but I saw with git stash list that it was there but now with index {1}...
This is not only pinned stash - it can be simple opened and kept stash diff.
How to Reproduce
git stashthem to create stash A (now atstash@{0})git stashagain to create stash B (B is nowstash@{0}, A becomesstash@{1})Solution
With unique hash per stash, every opened editor is linked to its exact stash diff, and trying to open any new stash will open a new tab.
Side effect/Known limitation
When a stash editor is already open and the stash index shifts (due to new stashes being created), the editor title still shows the original index, even if you re-try to open the stash by View stash menu. The only way to get the updated index is by closing this editor and viewing the stash again.
Testing
I manually tested with the reproduction steps above. After the fix:
Related Issues
I found this old issue #203188 that may be linked to this fix.