Repository navigation
Refactor checkout branch and stash logic - #10957
Merged
Merged
Conversation
Rather than depending on the error handler ping pong game See #7474 (comment)
Don't count a branch switch as a non default switch if we don't know for sure what the default branch is
This was referenced Nov 26, 2020
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
Closes #9297 - Infinite loop when checking out branch
Closes #10956 - GitHub Desktop may overwrite existing stash
Closes #8099 - Reduce complexity of checkout logic
Closes #7617 - Rewrite checkout logic to keep logic inline as opposed to relying on error handlers and continuations.
Description
I set out to understand the cause of #9297 and ended up having to significantly rework our stashing and checkout logic.
What was the problem with the previous logic
Aside from the two serious bugs of an infinite loop (#9297) and the potential for users to loose work by Desktop overwriting their existing stash (#10956) the checkout logic has been a source of much confusion and complexity for a long time. #8099 does a good job of providing an overview of the problem:
In what ways does the new logic improve things
First of all it removes the re-entrant problem described above by explicitly detecting when changes would be overwritten and acting upon it as it happens rather than relying on an error handler. I've already fixed one issue due to the re-entrant nature (#9038) and #9297 proved there's at least one more serious issue. My comment from the original implementation which introduced this unfortunately proved to be well founded
Furthermore it ensures all different ways of checking out a branch (regular branch checkout, PR checkout, web links, etc) use the same consolidated logic.
Whether it achieves its goal of being easier to understand (and therefore also to maintain) is subjective but I absolutely think so. What was previously scattered across several flows in the application spanning hundreds of lines of code has now been reduced to a single linear flow that's easily debuggable. I think this is best illustrated by the top level logic:
desktop/app/src/lib/stores/app-store.ts
Lines 3192 to 3196 in 0b4d244
The three different strategies for checking out a branch has now been extracted into three distinct methods that no longer share unrelated logic making it easier to reason about each individual one
desktop/app/src/lib/stores/app-store.ts
Lines 3207 to 3212 in 0b4d244
Needless stashing
Thanks to this restructuring we're now able to only create a stash when it's really needed (i.e. when
git checkout branchfails due to local changes being overwritten) whereas before there were scenarios (such as if there were deleted files in the working directory) where we'd always create a stash regardless of whether it was necessary.Release notes
Notes: