Git: Use stash hash instead of index for editor identity #288616
+31
−39
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.