Skip to content

Fetch default remote if it differs from the current - #4057

Merged
shiftkey merged 8 commits into
masterfrom
fetch-default-remote
Feb 22, 2018
Merged

shiftkey merged 8 commits into
masterfrom
fetch-default-remote

Conversation

@niik

@niik niik commented Feb 20, 2018

Copy link
Copy Markdown
Member

The global fetch method only fetches the 'current' (i.e. the remote derived from the tracking branch of the current branch). This changes it so that it fetches the distinct set of the default, current, and upstream remotes.

This also changes the behavior of _checkoutPullRequest so that it always fetches the remote we're switching to first. As noted in the comments I think we can relax this a little going forward.

There's one potential race condition in here that I don't plan on fixing now. The previous _checkoutPullRequest implementation did a fetch without wrapping it in the withPushPull operation that guarantees we only run one network operation at a time. So there's a potential risk here that we could silently skip the fetch if a background fetch happens to be running at the same time. That risk seems like an improvement over potentially running two fetches concurrently and risking two git processes fighting over resources.

As an additional improvement this cuts down on the number of times we need to shell out to git to get all configured remotes by consolidating them all into one method.

Fixes #4056

@niik niik added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 20, 2018
@niik niik added this to the 1.1 milestone Feb 20, 2018
@iAmWillShepherd iAmWillShepherd self-assigned this Feb 20, 2018

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

LGTM 🥇

// We need to fetch FIRST because someone may have created a PR since the last fetch
await this._fetch(repository, FetchType.UserInitiatedTask)
const defaultRemote = await getDefaultRemote(repository)
// TODO: I think we could skip this fetch if we know that we have the branch locally

This comment was marked as spam.

This comment was marked as spam.

@shiftkey
shiftkey merged commit bbaa50c into master Feb 22, 2018
@shiftkey
shiftkey deleted the fetch-default-remote branch February 22, 2018 02:58
@shiftkey shiftkey mentioned this pull request Feb 22, 2018
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