Skip to content

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

Closed

Description

@niik

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

Activity

  1. added
    bug
    priority-1
    on Nov 2, 2020
  2. self-assigned this
    on Nov 2, 2020
  3. givihuda commented on Dec 21, 2021

    @givihuda

    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.

  4. gnowland commented on Jun 17, 2022

    @gnowland

    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

Metadata

Metadata

Assignees

Labels

bugpriority-1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions