Skip to content

auto recover missing repository - #6228

Merged
outofambit merged 10 commits into
desktop:developmentfrom
msftrncs:MissingRepositoryAutoRecovery
Jan 10, 2019
Merged

outofambit merged 10 commits into
desktop:developmentfrom
msftrncs:MissingRepositoryAutoRecovery

Conversation

@msftrncs

Copy link
Copy Markdown
Contributor

Overview

Addresses issues #4264, #5734. Attempts to recover the repository where it was last known to be, automatically.

Description

Updates to 'missing-repository' to trigger a rechecking of the repository state after a delay, and repetitively with a delay while the repository remains in the missing state. Technically every action the user performs while the missing repository view is up, triggers a rechecking of the repository, after a delay.

Release notes

  • no notes

Notes:
On a network environment, some operations may become hesitant depending on the order of events or something.

@Daniel-McCarthy Daniel-McCarthy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, thanks for working on a solution for this Issue!
I see you have this set up to auto-recover on a timer interval. One idea I wanted to float by was potentially attempt to auto-recover on window focus, since the user may leave GitHub Desktop to make a change and then return to the GitHub Desktop window to check the status.

I am leaving this as a comment since I wanted to see what you and others thought about this idea. And for an example of such functionality within GitHub Desktop, here is a commit that adds a listener for focus.

@msftrncs

Copy link
Copy Markdown
Contributor Author

@Daniel-McCarthy, Thanks for the feedback. I got to noticing that the 'MissingRepository' happens after a window focus event. Also, it was seeming like the auto recovery was kicking in on a window focus event as well, but in reality it was on any user activity, such as mousing between menus, and I thought that level of triggering the GIT process to detect the return of the repository shouldn't happen, and so changed it to only perform the check after the time delay, instead of before it.

I've followed through the code and determined how the window focus event triggers the detection of the missing repository, and the detection is done first most with pathExists in _refreshRepository in 'app-store.ts'. I did not utilize pathExists as a precheck before checking with isGitRepository, and I should as it will make less activity. Also by checking the path first, the logic could be changed so the repeat rate could be different when its a git error rather than a root folder existence issue.

Now, more on the window focus event. This means there is already a window focus event in 'index.tsx'. It currently calls to refresh the repository if the selected repository is not already in the missing state. I could see this whole process being changed so that _refreshRepository is responsible for recovering a repository that has returned, since it was responsible for marking it missing in the first place.

On a further note regarding window focus. It seems common place today for users to consider all events in the system to be interconnected. Thus, if I delete or rename a folder in Explorer, I tend to expect (only though examples all around) that GitHub Desktop might see that immediately. Programmers may be aware of the actual complexity that this interconnected appearance requires (file watchers, etc...) but common users just expect it to be.

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 19, 2018

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi again @msftrncs and thanks so much for this PR! :) I'm inclined to agree with @Daniel-McCarthy's suggestion and your proposal to use _refreshRepository to trigger this check. Perhaps AutoRecovery could become a method on AppStore that gets called from there? I think attempting to handle this case as its detected would be amazing! 🌟

@outofambit outofambit self-assigned this Nov 19, 2018
@msftrncs

Copy link
Copy Markdown
Contributor Author

I have altered my idea slightly, on AppStore._refreshRepository. Attempting to recover the missing repository at that exact location gives two potential problems.

  1. _updateRepositoryMissing returns a new Repository, the rest of _refreshRepository would be using the old value, or would require re-entering the method with the new value, and I am not sure that is desired.
  2. A lot of methods in AppStore call _refreshRepository, when recovering a missing repository probably isn't even on the radar.

However, the code probably does belong in AppStore. Also, where Dispatcher.refreshRepository is utilized (only in index.tsx for the 'focus' event), it might be more appropriate for the auto recovery to occur. I will present a commit on this premise, with the cyclic refresh timer removed, but a 'Refresh' button added, though as long as the repository remains missing, the button appears to do nothing.

These changes more follow the current design of the app.

@msftrncs

Copy link
Copy Markdown
Contributor Author

I missed that selecting a missing repository should probably also attempt to recover the repository, and have included a commit to cover that as well. The approach in 'app-store.ts' (AppStore) _selectRepository probably deserves some discussion. Maybe it (_selectRepository_refreshTasks) should be an arrow function, and maybe that concept could be used in _refreshRepository too, but I am not sure how the async/await works through there.

Comment thread app/src/lib/stores/app-store.ts Resolved
@outofambit

Copy link
Copy Markdown
Contributor

@desktop/design could you take a look at this mockup and see if the button order and text looks good to you? This PR adds the Refresh button.

screen shot 2018-11-28 at 8 32 36 am

@outofambit
outofambit dismissed their stale review November 28, 2018 16:44

changes made, now pending design input

@ampinsk

ampinsk commented Nov 28, 2018

Copy link
Copy Markdown
Contributor

Since this is covering an edge case, I don't think we need to emphasize the action with a button. How about moving it as a text link to the end of the message, and rewording to Check again?

frame

@msftrncs

msftrncs commented Dec 2, 2018

Copy link
Copy Markdown
Contributor Author

I have attempted to implement the text link. Note, that the text link might wrap. Also, I cannot seem to get a space between the end of the SPAN with the path in it, and the text link. I have left the button (text changed) for evaluation.

image

@Daniel-McCarthy

Copy link
Copy Markdown
Member

@msftrncs I have also had to do this recently and hit the same road block. I found that a place in the code base that does this is the About dialog.

To accomplish it, they stored the LinkButton in a variable.

const releaseNotesLink = (
<LinkButton uri={releaseNotesUri}>release notes</LinkButton>
)

Then, they embedded the variable with {' '} preceding.

</LinkButton>{' '}
({releaseNotesLink})

This is how I ended up doing it as well as I was not able to find another way to get the space to show up as expected.

@msftrncs

msftrncs commented Dec 2, 2018 •

Copy link
Copy Markdown
Contributor Author

@Daniel-McCarthy, I guess there is a space there. I went back and took the space out, and its a big difference, its just that there doesn't appear to be much space there, until there is none there at all.

It was last seen at{' '}
<span className="path">{this.props.repository.path}</span>.{' '}
<LinkButton onClick={this.checkAgain}>Check&nbsp;again.</LinkButton>

I used &nbsp; to prevent the 'Check again' text from being split.

@msftrncs

msftrncs commented Dec 2, 2018

Copy link
Copy Markdown
Contributor Author

public async _attemptRecoverMissingRepository(
repository: Repository
): Promise<void> {
// if repository is missing, try checking if it has been restored
if (repository.missing) {
const updatedRepository = await this.recoverMissingRepository(repository)
if (!updatedRepository.missing) {
// repository has been restored, attempt to refresh it now.
return this._refreshRepository(updatedRepository)
}
}
}

public refreshRepository(repository: Repository): Promise<void> {
return repository.missing
? this.appStore._attemptRecoverMissingRepository(repository)
: this.appStore._refreshRepository(repository)
}

Would there be any value in changing (App-Store) _attemptRecoverMissingRepository to something like _refreshOrRecoverRepository and eliminating the ternary in (Dispatcher) refreshRepository? (an additional else would be needed in the current _attemptRecoverMissingRepository to be sure to complete the refresh operation.) There could be some confusion however from App-Store indicating 'see Dispatcher' regarding _refreshRepository.

@msftrncs

msftrncs commented Dec 3, 2018

Copy link
Copy Markdown
Contributor Author

I just want to mention a thought I have for UI reaction to the 'Check again' concept. Without any reaction, the user would think nothing is happening. My thought would be to change the text, from 'Check again' to 'Checking...' for a small period of time, the maximum of which would be some constant period of time (0.5 to 1 second maybe) via a timer, or the length of time it takes to complete, unsuccessfully, the repository recovery tests.

@billygriffin

Copy link
Copy Markdown
Contributor

Seems reasonable to me @msftrncs, always have ❤️ for feedback to users on what's taking place. 😄

@ampinsk

ampinsk commented Dec 3, 2018

Copy link
Copy Markdown
Contributor

This looks great @msftrncs, thanks so much for making that change! Would it be possible to center align the text as well?

@msftrncs

msftrncs commented Dec 3, 2018

Copy link
Copy Markdown
Contributor Author

@ampinsk, I too noticed the uncentered appearance, but I think centering the text 'It was last seen at "{path}". Check again.' might result in a small side affect. When the text is wrapped, both the first line and each of the continuing wrapped line(s) will be separately centered. I'll check this out and see what it looks like.

@outofambit

Copy link
Copy Markdown
Contributor

@msftrncs

Would there be any value in changing (App-Store) _attemptRecoverMissingRepository to something like _refreshOrRecoverRepository and eliminating the ternary in (Dispatcher) refreshRepository?

i like this idea a lot! good call on moving logic out of dispatcher into app-store. 👍

@msftrncs

msftrncs commented Dec 4, 2018

Copy link
Copy Markdown
Contributor Author

@ampinsk, here is what it could look like center aligned.

image

@ampinsk

ampinsk commented Dec 4, 2018

Copy link
Copy Markdown
Contributor

@msftrncs that looks great, thank you!

outofambit
outofambit previously approved these changes Dec 4, 2018
@outofambit outofambit added this to the 1.6.0 milestone Dec 4, 2018
@ampinsk

ampinsk commented Dec 4, 2018

Copy link
Copy Markdown
Contributor

@msftrncs Ooh sorry, a couple things I didn't notice before:

  • Should the Check again button be Clone again?
  • The Locate button should be on the end on the left

cc @outofambit

@msftrncs

msftrncs commented Dec 4, 2018

Copy link
Copy Markdown
Contributor Author

@ampinsk, @outofambit, sorry, I had left the button Check Again along with the textlink 'Check again.' for evaluation. This particular repository that is shown in my image isn't a GitHub repo, so the 'Clone Again' button is not shown. Also, the centering of the text was not included in my most recent commit, nor was any attempt to provide a UI reaction to clicking the textlink. I can get the first time items commited later this evening, and I can work on the reaction part in a later PR if that it desired.

@msftrncs

msftrncs commented Dec 5, 2018

Copy link
Copy Markdown
Contributor Author

Description

Restores access to a known repository that has been marked missing, if the repository is restored to its original location:

  1. upon focus of the GitHub Desktop window,
  2. the user selecting the repository from the known repositories list,
  3. the user activates a text link in the UI.

@tierninho

tierninho commented Dec 5, 2018 •

Copy link
Copy Markdown
Contributor

The UI was tested for this change, and overall it functions well.

  • check again, etc is surfaced when repo is moved
  • check again finds repo if path restored
  • check again ignores non-git repo of same name
  • repo is auto-added back if placed back in prior path
  • repo is added back if new path located manually

Notes:

  • two log identical entries appear each time I click Check Again: debug: [ui] Executing getTopLevelWorkingDirectory: git rev-parse --show-cdup
  • We should surface the "This is not a git repository." warning msg if I click Locate and attempt to clone a non-git repo. If you cmd-O, and do the same, the warning is shown as so:

screen shot 2018-12-05 at 11 22 42 am

  • In the Repo list, the "up arrow" is still intact if the repo is missing. Should we remove this until the repo is located again?

screen shot 2018-12-05 at 11 17 13 am

Build/OS: 1.5.1-beta1, mac, 549e6ce

@msftrncs

msftrncs commented Dec 6, 2018 •

Copy link
Copy Markdown
Contributor Author

@tierninho,

In the Repo list, the "up arrow" is still intact if the repo is missing. Should we remove this until the repo is located again?

By chance does this go away if you 'select' that repository (after having a different one selected) ??

I noticed some code in the selection handler clears the GIT cache (for the repository) if the repository is missing when its selected, but this doesn't seem to happen at any other time.

EDIT: I have confirmed that the process of selecting a repository has no effect on the 'up' or 'down' arrows shown in the repository list on missing repositories. Instead I noticed that those status icons are only shown if the repository was able to be found and refreshed during the current execution run.

@tierninho

Copy link
Copy Markdown
Contributor

I have confirmed that the process of selecting a repository has no effect on the 'up' or 'down' arrows shown in the repository list on missing repositories.

@msftrncs Thanks for confirming above. The icon does go away after moving the repo to another location, clicking the Clone Again button, dismissing the error, and then reopening the repo list. Not a good use case, but might offer a clue to fixing it. 💭

@outofambit
outofambit changed the base branch from master to development December 27, 2018 21:47
@outofambit

Copy link
Copy Markdown
Contributor

this looks good to me from a technical perspective @msftrncs! @ampinsk are we good on the design side? Here's a screenshot of the current state:

screen shot 2019-01-07 at 9 36 27 am

@shiftkey shiftkey self-assigned this Jan 9, 2019
@shiftkey

shiftkey commented Jan 9, 2019

Copy link
Copy Markdown
Member

Assigning myself to also review this because this all happened while I was out on leave last month and I just now noticed it's planned for 1.6.0. selectRepository/refreshRepository is a important hot path for the app I'd like to test this out to ensure the default happy path isn't affected by this change.

@shiftkey shiftkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one readability suggestion that can be landed later if you're interested @msftrncs!

*/
if (
repository.missing
? (await pathExists(repository.path))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 I'm not a huge fan of the readability of this nested ternary with multiple await-s inside an if statement. I had a go at getting these same rules down in a way that's hopefully easier to understand and makes the large code comment less important. Happy to get this into a follow-up PR:

  private async recoverMissingRepository(
    repository: Repository
  ): Promise<Repository> {
    if (!repository.missing) {
      return repository
    }

    // if the repository is marked missing, check to see if the file path exists,
    // and if so then see if git recognizes the path as a valid repository,
    // and if so, reset the missing status as its been restored
    const exists = await pathExists(repository.path)
    if (exists) {
      const isGitRepo = await isGitRepository(repository.path)
      if (isGitRepo) {
        return this._updateRepositoryMissing(repository, false)
      }
    }

    // otherwise just return the original repository
    return repository
  }

@shiftkey shiftkey removed their assignment Jan 9, 2019
@ampinsk

ampinsk commented Jan 9, 2019

Copy link
Copy Markdown
Contributor

Looks good from the design side!

@outofambit

Copy link
Copy Markdown
Contributor

Awesome! 🎉 Thanks for your work on this @msftrncs!!

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

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants