Skip to content

Stashing [Tracking Issue] #6987

Closed
Closed

Description

@iAmWillShepherd

Original issue: #6107

Design notes

Git Commands

git-stash list

> git stash list
stash@{0}: WIP on stashing: 41f7b73 some random commit message
stash@{1}: WIP on stashing: 41f7b73 some random commit message
stash@{2}: On stashing: a message
stash@{3}: On stashing: this is a message
stash@{4}: WIP on stashing: 531bd83 1
stash@{5}: WIP on stashing: 531bd83 1

I'll be using git log -g refs/stash to emulate the behaviour of git stash list since it uses git log under the hood (docs). Doing it this way will help us avoid doing extra work which is super important on Windows as process creation is very expensive.

Git implementation


git-stash push

> git stash push -m “a message”
Saved working directory and index state On stashing: a message

I’ll be using a specially formatted message to differentiate between stash objects created by the user and Desktop on the user’s behalf.
This is not a bullet-proof solution because

  • a user can use our message format when they stash something from the CLI and
  • they can edit the message stored in a stash object by modifying git/logs/refs/stash

However, we take a similar approach for adding remotes and checking out pull requests, so I think we can safely ignore the risks above.

Message Format

github-desktop: fully qualified branch name

Component Reasoning
github-desktop It’s unlikely anyone would use that in their own stash message and it makes is super clear which entries are created by Desktop.
tip Having the tip of the branch at the time the stash object is created should prevent issues related to ambiguous branch names. An added benefit is we could deal with branch renaming.

My thinking is that I can use the tip to make extra sure the stash entry is based on a specific branch. I am making an assumption that if the commit SHA is a branch’s history, then it likely is that branch. I think this means I can get by without using fully-qualified branch names.

git-stash apply

Happy path

> git stash apply stash{1}
On branch stashing
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  modified:   aoc-day2.ts

no changes added to commit (use "git add" and/or "git commit -a")

Conflicts

> git stash apply stash{3}
Auto-merging aoc-day2.ts
CONFLICT (content): Merge conflict in aoc-day2.ts

I should be able to lean on the current plumbing in Desktop to respond to the working tree state getting updated and on the conflict resolution flow in the event of conflicts.

Desktop Plumbing

Entry point

The entry point for this feature is the user attempts to checkout a new branch while they have uncommitted changes that would get lost by switching branches. Since we already have a dialog that's presented when a user tries to switch branches with uncommitted changes, I'll update that flow for stashing.

Files Overwritten dialog

screen shot 2019-03-01 at 10 19 13 am

Responsible error handler

/**
* Handler for when we attempt to checkout a branch and there are some files that would
* be overwritten.
*/
export async function localChangesOverwrittenHandler(
error: Error,
dispatcher: Dispatcher
): Promise<Error | null> {
const e = asErrorWithMetadata(error)
if (!e) {
return error
}
const gitError = asGitError(e.underlyingError)
if (!gitError) {
return error
}
const dugiteError = gitError.result.gitError
if (!dugiteError) {
return error
}
if (dugiteError !== DugiteError.LocalChangesOverwritten) {
return error
}
const { repository, retryAction } = e.metadata
if (repository == null) {
return error
}
if (!(repository instanceof Repository)) {
return error
}
if (!retryAction) {
log.error(`No retry action provided for a git checkout error.`, e)
return error
}
// find the overwritten files from the error
const overwrittenFiles = []
const pathRegex = /^\t(.*)/gm
const { stderr } = gitError.result
let match = pathRegex.exec(stderr)
while (match !== null) {
overwrittenFiles.push(match[1])
match = pathRegex.exec(stderr)
}
dispatcher.showPopup({
type: PopupType.LocalChangesOverwritten,
repository,
retryAction,
overwrittenFiles,
})
return null
}

Conflicts

Conflicts that arise as a result of applying a stash differ or not the same as merge conflicts. That detail is important here because Desktop requires a merge conflict to intiate the merge conflict resolution flow. Some thought will have to be put into how to handle stash conflicts, but since these types of conflicts don't have to be resolved due to them not being merge conflicts, I can punt this issue down the road a bit.

Metrics for Success

Questions:

  1. What percentage of the time do people bring their changes across to a different branch vs. stashing them in their current branch?
  2. What percentage of time are people restoring the stash vs. deleting the stash vs. neither of those things? The total of these should equal the number of times users return to a branch that contains a stash.
  3. What percent of changes viewed are via clicking on the "Stashed changes" row directly vs. clicking on the prompt in the suggested next step? (there's not a metric for this below yet)
  4. How many times do users currently stash outside of Desktop, and can we demonstrate that supporting this shows a decline in that overall per-user number? This is intended to understand whether we are improving context-switching and allowing people to do more of their overall workflow in Desktop.
Metric Description
stash-prompt-displayed The number of times the user is prompted to either stash their changes on their current branch or bring them to their new branch.
stash-created-on-current-branch-count The number of times the user selects the option to stash changes on their current branch.
stash-created-on-new-branch-count The number of times the user selects the option to bring their changes to a new branch.
stash-applied-count The number of times the user applies a stash (this count applies only to stash objects not taken to the new branch*).
stash-discard-count The number of times the user removes a stash object from their branch (this count applies only to stash objects not taken to the new branch*).
stash-view-count The number of times the user clicks the Stashed changes button in the Changes tab.
stashes-outside-desktop* The number of times a Desktop user creates a stash outside of GitHub Desktop.

*This is a derived metric.

Although we are planning to move to an event-based metric approach, I'll be implementing these metrics as we currently do because we have not switched to the new approach yet.

Questions

  1. When should I perform housekeeping of stash entries?
    1. When git stash apply succeeds? or
    2. after the user commits the newly applied stash (assuming merge conflicts have been taken care of)?
  2. Should we also allow for discarding changes instead of always stashing them?
  3. If the option to take changes to the new branch is selected, should I try to apply the stash immediately or stash it and let the user apply it?
  4. The Stashed changes view doesn't have a way to close other than applying or clearing the stash, should we allow users to close this?
    1. If we aren't going to have an x button to close the view, should selecting an item in the changes list close the view?

Answers

Questions to validate with users

  1. If a stash is created outside of Desktop on a given branch and a user returns to that branch in Desktop, what is their expectation?
  2. How do people navigate away from the "View stash" view? Do they find it intuitive to "get out of it" or do they need something more explicit?

Todo

Activity

  1. added
    meta
    on Mar 1, 2019
  2. added this to the 1.7.0 milestone on Mar 1, 2019
  3. billygriffin commented on Mar 1, 2019

    @billygriffin
    Contributor

    Thanks @iAmWillShepherd. Here are some thoughts/clarifying questions from your questions:

    When should I perform housekeeping of stash entries?

    Do you mean when to delete the stash after it has been applied?

    Should we allow for discarding changes instead of always stashing them?

    I'm not sure I follow this. At what point in the flow? Do you mean that a user might be presented with three options? (1) stash, (2) bring changes with you, (3) discard the changes and switch?

    If that's correct, my inclination would be to wait until that becomes a thing we see or hear from users before doing that, but I'm open to changing my mind. It's not super clear to me that that solves a real problem people have (for example, "I want to switch branches and just blow away everything that hasn't been committed").

    If the option to take changes to the new branch is selected, should I try to apply the stash immediately or stash it and let the user apply it?

    I don't think we do any stashing in this case. I think we just use the default behavior of Git, right?

    The stashed changes view doesn't have a way to close other than applying or clearing the stash, should we allow users to close this?

    Let's walk through a use case on this and discuss. Looking forward to @ampinsk's thoughts.

  4. iAmWillShepherd commented on Mar 4, 2019

    @iAmWillShepherd
    ContributorAuthor

    Do you mean when to delete the stash after it has been applied?
    Yes

    Should we allow for discarding changes instead of always stashing them?
    At the moment, if a user has uncommitted changes and tries to change branches, we warn them and give them an opportunity to discard the changes. So was wondering if we're axing that behaviour.

    And yes, I was thinking we'd keep the option to discard changes while adding the other 2 stashing options.

    If the option to take changes to the new branch is selected, should I try to apply the stash immediately or stash it and let the user apply it?

    The default behaviour could result in getting the git error that changes would be lost. We currently offer the user the chance to discard changes when this happens.

  5. iAmWillShepherd commented on Mar 4, 2019

    @iAmWillShepherd
    ContributorAuthor

    Answers to questions 1-4.

    1. When should I perform housekeeping of stash entries?
      i. When git stash apply succeeds? or
      ii. after the user commits the newly applied stash (assuming merge conflicts have been taken care of)?

    We're going to delete a stash entry after it is successfully applied and a commit is made.

    1. Should we also allow for discarding changes instead of always stashing them?

    We will not provide the option to discard changes, we will instead rely on the discard changes action available in the Changes view context menu.

    1. If the option to take changes to the new branch is selected, should I try to apply the stash immediately or stash it and let the user apply it?

    In situations that require stashing, Desktop will stash then immediately pop that object on the new branch. This means Desktop will not present the user with the Stashed changes button in the Changes view when bringing uncommitted changes to a different branch.

    1. The Stashed changes view doesn't have a way to close other than applying or clearing the stash, should we allow users to close this?
      i. If we aren't going to have an x button to close the view, should selecting an item in the changes list close the view?

    We will rely on Desktop's current behaviour of dismissing a modal by clicking outside the popup. In this event, the user can click in the Changes view to dismiss the Stashed Changes view.

  6. billygriffin commented on Mar 4, 2019

    @billygriffin
    Contributor

    @iAmWillShepherd @nerdneha @ampinsk I updated the metrics portion of the original comment. Please feel free to add to it or ask amplifying questions.

  7. billygriffin commented on Mar 12, 2019

    @billygriffin
    Contributor

    Notes & decisions from our meeting today. All decisions are what we're going with for now, but we're still gathering feedback and doing usability testing as we continue implementation:

    • Decision: We'll treat tracked and untracked files the same in this flow. Since Desktop doesn't distinguish between the two in the app, there's no reason to do so here. Since we'll need to convert untracked files to tracked files as part of this process, our assumption is that that's ok and that there's no need to revert that.
    • Decision: If you’ve unchecked some subset of files and switch branches, all of the files get either stashed or brought with you, depending on your choice. We don't distinguish between checked and unchecked files in this process.
    • Decision: We're going to punt on the idea of combining multiple stashes until we know it's a real problem that we need to solve. It's tricky and there's a lot that can go wrong, so unless this surfaces as a major thing, we'll likely leave it out.
    • Decision: We're going to use "Restore" for the button where it currently says "Apply" to apply the stash
      • I am going to propose verbiage for grey explanatory text that goes next to that button
    • Decision: If you bring changes over to a branch that already has a stash, the changes are brought over and the stash stays in place. You're unable to restore the stash until you've done something with the changes that you brought over.
    • From a user's perspective, renaming, adding, modifying, and deleting files should just work (we should test these cases thoroughly to be sure there aren't any pitfalls).
    • We're going to continue to think about how to make the stashed changes more obvious when a user returns to the branch it's on. A couple ideas are a one-time popup that points to the area where you access them or an animation that helps guide your eye there.

    cc: @iAmWillShepherd @nerdneha @ampinsk

  8. donokuda commented on Mar 14, 2019

    @donokuda
    Contributor

    We're going to continue to think about how to make the stashed changes more obvious when a user returns to the branch it's on. A couple ideas are a one-time popup that points to the area where you access them or an animation that helps guide your eye there.

    Something that we can consider doing is utilizing the "Suggested Next Steps" pattern that @niik created to guide people to their stashed changes:

    image

    Which clicking on "View Stash" will bring up the stashed changes view:

    image

    My assumption is that this approach would be quicker to implement than a popover (and all the potential state around whether or not a user has seen it) and more obvious than an animation. I've created a simple prototype in Figma if anyone wanted to get a feel of it.

    Open to any feedback with this approach! 😃

  9. billygriffin commented on Mar 14, 2019

    @billygriffin
    Contributor

    Verbiage (finalized after discussions) here:

    Proposed verbiage for grey explanatory text next to "Restore"

    • Green check mark immediately to the right of the restore button if the stash can be applied without issue (like when you can merge knowing that there won't be any conflicts)
    • Verbiage next to green check mark: This will apply this stash as changed files

    Proposed verbiage for suggested next step if we go with @donokuda's proposal above

    • You have [number of files] changes in progress that you have not yet committed
    • Second lighter line: When a stash exists, access it at the bottom of the Changes tab to the left
    • Button text: "View stash"
  10. billygriffin commented on Apr 1, 2019

    @billygriffin
    Contributor

    Documenting decisions from our weekly meetings and discussions:

    1. We'll use the suggested next step as described by @donokuda above, with the verbiage here.

    2. The suggested next step will be used (with proposed verbiage here) to let users know that there's a stash when they return to the branch. If the stash suggested next step conflicts with another one (like commits to pull from the remote), the stash suggestion will always be more prominent.

  11. added
    epic:stashing
    on Apr 23, 2019
  12. shiftkey commented on May 30, 2019

    @shiftkey
    Member

    Dropping this from the 1.7 milestone to indicate it's no longer holding up the release.

    @iAmWillShepherd could you provide a quick summary about what's left (if anything) in this issue to work on?

  13. removed this from the 1.7.0 milestone on May 30, 2019
  14. drdavi commented on May 31, 2019

    @drdavi
  15. billygriffin commented on Jun 7, 2019

    @billygriffin
    Contributor

    This has shipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:stashingmeta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions