Skip to content

Handle when checkout branch fails - #8076

Closed
probablycorey wants to merge 7 commits into
developmentfrom
chore/prevent-re-entrant-checkout-branch
Closed

probablycorey wants to merge 7 commits into
developmentfrom
chore/prevent-re-entrant-checkout-branch

Conversation

@probablycorey

@probablycorey probablycorey commented Aug 7, 2019 •

Copy link
Copy Markdown
Contributor

Overview

Addresses #7617

One of the concerns in the issue above was that Desktop wasn't awaiting calls to checkoutBranch

 const checkoutSucceeded =
  (await this.withAuthenticatingUser(repository, (repository, account) =>
    gitStore.performFailableOperation(
      () =>
        checkoutBranch(repository, account, foundBranch, progress => {
          this.updateCheckoutProgress(repository, progress)
  }),

It turns out it is already awaiting, because checkoutBranch returns a promise to performFailableOperation which returns a promise to withAuthenticatingUser which is awaited.

But there is another concern raised in the issue. When a checking out a branch fails (because of conflicts or some other evil) Desktop should stashing the changes and checkout the branch again. This was happening as a side effect in the error handlers, but now it is handled explicitly in the AppStore._checkoutBranch method.

Speaking of the _checkoutBranch method, it's pretty long and tricky to follow. I created this pseudo code story to help me understand what the method is trying to do:

Do you have changes and is “ask before stashing” set?
	**Yes**
		Show a that popup and exit before doing anything (the popup will end up calling checkoutBranch again)
	**No**
		continue	
Are you on a branch and you want to keep your changes on that current branch?
	Stash the changes for the current branch
Or do you want to move your changes to the branch you are checking out?
	Are there deleted files and there is no transientStashEntry
		Create a stash
Checkout the branch
	Was there an error (maybe a conflict or some other badness)
		Is there already a stash
			THROW ERROR
		Are there no local changes?
			THROW ERROR
		Stash the changes
		Checkout again
Is there a stash and you moving changes to a new branch?
        Apply the stash
etc...

Now that I understand how it works I think I'll be able to clean up the method a bit (like #7609 describes) in a follow up PR.

Closes #7617

Description

Notes:

  • Diff best viewed with Hide whitespace changes on.

@probablycorey
probablycorey marked this pull request as ready for review August 8, 2019 23:40
@probablycorey probablycorey self-assigned this Aug 8, 2019
@probablycorey probablycorey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 8, 2019
@probablycorey probablycorey changed the title Chore/prevent re entrant checkout branch Handle when checkout branch fails Aug 9, 2019
@probablycorey

Copy link
Copy Markdown
Contributor Author

I think there is a problem with some of my assumptions, specifically "Was there an error (maybe a conflict or some other badness)"

During my testing I was trying to get a checkout to fail, but I couldn't. I tried checking out a file with conflicts, and checking out a file with unstaged changes, but none of that caused checkout to fail. So I need to dig into this a little deeper.

@probablycorey probablycorey removed the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 9, 2019
@probablycorey probablycorey removed their assignment Aug 9, 2019
@probablycorey

Copy link
Copy Markdown
Contributor Author

I moved the logic from @niik's into another method. The only major difference is I removed the gitStore.performFailableOperation so the error from checkoutBranch can be caught. But after looking at this with @kuychaco, we were wondering if this change was worth it.

The user-facing experience with this is pretty minimal. It would ensure that popups remain open while the reentrant checkoutBranch is run. In my testing this wasn't noticeable, but maybe if it is a giant stash or checkout it would be more noticeable.

One thing we did notice is how complicated checkoutBranch has become, so maybe it makes more sense to refactor more of the method before adding this additional error detection?

@probablycorey

Copy link
Copy Markdown
Contributor Author

Closing based on the findings described in #8099

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent concurrent appStore._checkoutBranch call from error handlers

2 participants