Skip to content

Commit 117e817

Browse files
authored
Use git setting to fetch before checkout in checkoutExistingPullRequestBranch (#4759)
* Check git setting to fetch before checkout in checkoutExistingPullRequestBranch * formatting changes reverted * Added new setting to control if PR has to be pulled before checkout
1 parent 58f5b9d commit 117e817

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@
347347
"description": "%githubPullRequests.setAutoMerge.description%",
348348
"default": false
349349
},
350+
"githubPullRequests.pullPullRequestBranchBeforeCheckout": {
351+
"type": "boolean",
352+
"description": "%githubPullRequests.pullPullRequestBranchBeforeCheckout.description%",
353+
"default": true
354+
},
350355
"githubIssues.ignoreMilestones": {
351356
"type": "array",
352357
"default": [],

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"githubPullRequests.defaultCommentType.single": "Submits the comment as a single comment that will be immediately visible to other users",
6464
"githubPullRequests.defaultCommentType.review": "Submits the comment as a review comment that will be visible to other users once the review is submitted",
6565
"githubPullRequests.setAutoMerge.description": "Checks the \"Auto-merge\" checkbox in the \"Create Pull Request\" view.",
66+
"githubPullRequests.pullPullRequestBranchBeforeCheckout.description": "Pulls pull request before checkout",
6667
"githubIssues.ignoreMilestones.description": "An array of milestones titles to never show issues from.",
6768
"githubIssues.createIssueTriggers.description": "Strings that will cause the 'Create issue from comment' code action to show.",
6869
"githubIssues.createIssueTriggers.items": "String that enables the 'Create issue from comment' code action. Should not contain whitespace.",

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const DEFAULT_DELETION_METHOD = 'defaultDeletionMethod';
2727
export const SELECT_LOCAL_BRANCH = 'selectLocalBranch';
2828
export const SELECT_REMOTE = 'selectRemote';
2929
export const REMOTES = 'remotes';
30+
export const PULL_PR_BRANCH_BEFORE_CHECKOUT = 'pullPullRequestBranchBeforeCheckout';
3031

3132
export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues';
3233
export const ASSIGN_WHEN_WORKING = 'assignWhenWorking';

src/github/pullRequestGitHelper.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { GitErrorCodes } from '../api/api1';
1212
import Logger from '../common/logger';
1313
import { Protocol } from '../common/protocol';
1414
import { parseRepositoryRemotes, Remote } from '../common/remote';
15+
import { PR_SETTINGS_NAMESPACE, PULL_PR_BRANCH_BEFORE_CHECKOUT } from '../common/settingKeys';
1516
import { IResolvedPullRequestModel, PullRequestModel } from './pullRequestModel';
1617

1718
const PullRequestRemoteMetadataKey = 'github-pr-remote';
@@ -188,14 +189,20 @@ export class PullRequestGitHelper {
188189
const branchName = branchInfos[0].branch!;
189190
progress.report({ message: vscode.l10n.t('Checking out branch {0}', branchName) });
190191
await repository.checkout(branchName);
191-
const remote = readConfig(`branch.${branchName}.remote`);
192-
const ref = readConfig(`branch.${branchName}.merge`);
193-
progress.report({ message: vscode.l10n.t('Fetching branch {0}', branchName) });
194-
await repository.fetch(remote, ref);
192+
193+
// respect the git setting to fetch before checkout
194+
if (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(PULL_PR_BRANCH_BEFORE_CHECKOUT, true)) {
195+
const remote = readConfig(`branch.${branchName}.remote`);
196+
const ref = readConfig(`branch.${branchName}.merge`);
197+
progress.report({ message: vscode.l10n.t('Fetching branch {0}', branchName) });
198+
await repository.fetch(remote, ref);
199+
}
200+
195201
const branchStatus = await repository.getBranch(branchInfos[0].branch!);
196202
if (branchStatus.upstream === undefined) {
197203
return false;
198204
}
205+
199206
if (branchStatus.behind !== undefined && branchStatus.behind > 0 && branchStatus.ahead === 0) {
200207
Logger.debug(`Pull from upstream`, PullRequestGitHelper.ID);
201208
progress.report({ message: vscode.l10n.t('Pulling branch {0}', branchName) });

0 commit comments

Comments
 (0)