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

GitHub Desktop may overwrite existing stash when "Always stash and leave my changes" is selected #10956

Closed
niik opened this issue Nov 2, 2020 · 2 comments · Fixed by #10957
Closed
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs priority-1 Bug that affects many users in a significant way and prevents core functions

Comments

@niik
Copy link
Member

niik commented Nov 2, 2020

Describe the bug

When checking out a branch using the pull request list or by following a "Checkout in Desktop" link on GitHub.com while having the "Always stash and leave my changes on the current branch" option selected in preferences (under Advanced) GitHub Desktop fails to prompt the user for confirmation before overwriting their existing stash.

Version & OS

I believe this has been true since #8813 which shipped in 2.3.0. OS-independent

Steps to reproduce the behavior

  1. Ensure your current branch has a stash associated with it.
  2. Ensure you have uncommitted changes in your working directory
  3. Ensure you've selected the "Always stash and leave my changes on the current branch" option in preferences
  4. Attempt to check out a pull request (note: not a branch, there's different logic involved here)

Expected behavior

GitHub Desktop should show a confirmation prompt like the one below

image

Actual behavior

The PR branch is checked out and the stash on the previous branch is overwritten with a newly created stash containing your uncommitted changes.

Additional context

I've got a fix ready for this, I just wanted to ensure we have a record of this being a bug that we can refer back to. The dropped stash can be restored by looking through the GitHub Desktop logs and searching for a message with the following format:

 info: [ui] Dropped stash '0e95c933c4c6ba4403564407f2c8a7fbe829fb3d' associated with main

Taking that stash SHA one could restore the changes by running git stash apply 0e95c933c4c6ba4403564407f2c8a7fbe829fb3d

@niik niik added bug Confirmed bugs or reports that are very likely to be bugs priority-1 Bug that affects many users in a significant way and prevents core functions labels Nov 2, 2020
@niik niik self-assigned this Nov 2, 2020
@givihuda
Copy link

This is a bug? I don't know why anyone would want to overwrite their stash period. When I stash on CLI before switching branch, I don't need to overwrite a stash. The stash records the branch I'm on anyway. I just stash, switch branches, then unstash from the stash I see is marked as for that branch. I don't know why GitHub Desktop needs to overwrite stashes at all.

@gnowland
Copy link

gnowland commented Jun 17, 2022

I second this and add that the "Your current stash will be overwritten by creating a new stash" message on the "stash my changes and switch branches" dialog is way too subtle:

Screen Shot 2022-06-17 at 2 28 43 PM

A destructive procedure such as overwriting a current stash should require an explicit confirmation of intent, ideally in a separate dialog, as you mocked up.

I've hit the "switch branch" button too quickly a couple of times (muscle memory, combined with the destructive action being highlighted blue) before realizing what i've done 😫 thank god for git fsck...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs priority-1 Bug that affects many users in a significant way and prevents core functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@niik @gnowland @givihuda and others