Skip to content

teach getRemotes about handling this error code instead of failing fast - #5298

Merged
outofambit merged 5 commits into
masterfrom
teach-git-things
Jul 31, 2018
Merged

outofambit merged 5 commits into
masterfrom
teach-git-things

Conversation

@shiftkey

@shiftkey shiftkey commented Jul 31, 2018 •

Copy link
Copy Markdown
Member

This is related to exercising #5297 and the steps to reproduce this are roughly:

  • add a repository to Desktop
  • switch to a different repository in the list
  • rename the .git directory to something else
  • open Desktop again
  • change to the problem repository
  • 💥

Inside AppStore._refreshRepository there are a bunch of Git operations that assume the missing flag is in the right state when it runs.

My testing shows these two operations did not handle this "folder exists but it's not a Git repository" scenario:

I'm going to address the first one in a separate up PR because the app is currently in a loop and doesn't set the repository to missing=true , but this fix here was easier to address because:

  • 128 is the generic error code for "no Git repository here, yo"
  • if this error code is encountered, we can just return an empty array of remotes

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 31, 2018
@shiftkey shiftkey added this to the 1.3.2 milestone Jul 31, 2018
Comment thread app/src/lib/git/remote.ts Outdated
): Promise<ReadonlyArray<IRemote>> {
const result = await git(['remote', '-v'], repository.path, 'getRemotes')
const result = await git(['remote', '-v'], repository.path, 'getRemotes', {
successExitCodes: new Set<number>([0, 128]),

This comment was marked as spam.

Comment thread app/src/lib/git/remote.ts
): Promise<ReadonlyArray<IRemote>> {
const result = await git(['remote', '-v'], repository.path, 'getRemotes')
const result = await git(['remote', '-v'], repository.path, 'getRemotes', {
successExitCodes: new Set([0, 128]),

This comment was marked as spam.

Comment thread app/test/unit/git/remote-test.ts Outdated

it('returns empty array for directory without a .git directory', async () => {
const emptyDir = mkdirSync('no-repo-here')
const repository = new Repository(emptyDir, -1, null, false)

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

Copy link
Copy Markdown
Member Author

🍎

@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.

💟

@outofambit
outofambit merged commit 575bcb3 into master Jul 31, 2018
@outofambit
outofambit deleted the teach-git-things branch July 31, 2018 18:26
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.

3 participants