Skip to content
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@
"description": "%githubPullRequests.setAutoMerge.description%",
"default": false
},
"githubPullRequests.pullPullRequestBranchBeforeCheckout": {
"type": "boolean",
"description": "%githubPullRequests.pullPullRequestBranchBeforeCheckout.description%",
"default": true
},
"githubIssues.ignoreMilestones": {
"type": "array",
"default": [],
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"githubPullRequests.defaultCommentType.single": "Submits the comment as a single comment that will be immediately visible to other users",
"githubPullRequests.defaultCommentType.review": "Submits the comment as a review comment that will be visible to other users once the review is submitted",
"githubPullRequests.setAutoMerge.description": "Checks the \"Auto-merge\" checkbox in the \"Create Pull Request\" view.",
"githubPullRequests.pullPullRequestBranchBeforeCheckout.description": "Pulls pull request before checkout",
"githubIssues.ignoreMilestones.description": "An array of milestones titles to never show issues from.",
"githubIssues.createIssueTriggers.description": "Strings that will cause the 'Create issue from comment' code action to show.",
"githubIssues.createIssueTriggers.items": "String that enables the 'Create issue from comment' code action. Should not contain whitespace.",
Expand Down
1 change: 1 addition & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const DEFAULT_DELETION_METHOD = 'defaultDeletionMethod';
export const SELECT_LOCAL_BRANCH = 'selectLocalBranch';
export const SELECT_REMOTE = 'selectRemote';
export const REMOTES = 'remotes';
export const PULL_PR_BRANCH_BEFORE_CHECKOUT = 'pullPullRequestBranchBeforeCheckout';

export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues';
export const ASSIGN_WHEN_WORKING = 'assignWhenWorking';
Expand Down
15 changes: 11 additions & 4 deletions src/github/pullRequestGitHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { GitErrorCodes } from '../api/api1';
import Logger from '../common/logger';
import { Protocol } from '../common/protocol';
import { parseRepositoryRemotes, Remote } from '../common/remote';
import { PR_SETTINGS_NAMESPACE, PULL_PR_BRANCH_BEFORE_CHECKOUT } from '../common/settingKeys';
import { IResolvedPullRequestModel, PullRequestModel } from './pullRequestModel';

const PullRequestRemoteMetadataKey = 'github-pr-remote';
Expand Down Expand Up @@ -188,14 +189,20 @@ export class PullRequestGitHelper {
const branchName = branchInfos[0].branch!;
progress.report({ message: vscode.l10n.t('Checking out branch {0}', branchName) });
await repository.checkout(branchName);
const remote = readConfig(`branch.${branchName}.remote`);
const ref = readConfig(`branch.${branchName}.merge`);
progress.report({ message: vscode.l10n.t('Fetching branch {0}', branchName) });
await repository.fetch(remote, ref);

// respect the git setting to fetch before checkout
if (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(PULL_PR_BRANCH_BEFORE_CHECKOUT, true)) {
const remote = readConfig(`branch.${branchName}.remote`);
const ref = readConfig(`branch.${branchName}.merge`);
progress.report({ message: vscode.l10n.t('Fetching branch {0}', branchName) });
await repository.fetch(remote, ref);
}

const branchStatus = await repository.getBranch(branchInfos[0].branch!);
if (branchStatus.upstream === undefined) {
return false;
}

if (branchStatus.behind !== undefined && branchStatus.behind > 0 && branchStatus.ahead === 0) {
Logger.debug(`Pull from upstream`, PullRequestGitHelper.ID);
progress.report({ message: vscode.l10n.t('Pulling branch {0}', branchName) });
Expand Down