diff --git a/src/common/settingKeys.ts b/src/common/settingKeys.ts index 9891154185..cd1b21fdf3 100644 --- a/src/common/settingKeys.ts +++ b/src/common/settingKeys.ts @@ -26,4 +26,5 @@ export const SHOW_PULL_REQUEST_NUMBER_IN_TREE = 'showPullRequestNumberInTree'; // git export const GIT = 'git'; +export const PULL_BEFORE_CHECKOUT = 'pullBeforeCheckout'; export const OPEN_DIFF_ON_CLICK = 'openDiffOnClick'; diff --git a/src/github/folderRepositoryManager.ts b/src/github/folderRepositoryManager.ts index 6647a4a231..892264ee4d 100644 --- a/src/github/folderRepositoryManager.ts +++ b/src/github/folderRepositoryManager.ts @@ -14,7 +14,7 @@ import { commands, contexts } from '../common/executeCommands'; import Logger from '../common/logger'; import { Protocol, ProtocolType } from '../common/protocol'; import { GitHubRemote, parseRepositoryRemotes, Remote } from '../common/remote'; -import { PULL_BRANCH } from '../common/settingKeys'; +import { GIT, PULL_BEFORE_CHECKOUT, PULL_BRANCH } from '../common/settingKeys'; import { ITelemetry } from '../common/telemetry'; import { EventType, TimelineEvent } from '../common/timelineEvent'; import { fromPRUri, Schemes } from '../common/uri'; @@ -2161,6 +2161,11 @@ export class FolderRepositoryManager implements vscode.Disposable { return; } + // respect the git setting to fetch before checkout + if (vscode.workspace.getConfiguration(GIT).get(PULL_BEFORE_CHECKOUT, false) && branchObj.upstream) { + await this.repository.fetch({ remote: branchObj.upstream.remote, ref: `${branchObj.upstream.name}:${branchObj.name}` }); + } + if (branchObj.upstream && branch === branchObj.upstream.name) { await this.repository.checkout(branch); } else {