From a34f4404eaf6f791e7cd3de9ee58eb1153d7185d Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 19 Apr 2023 14:27:46 +0200 Subject: [PATCH] Respect git's pullBeforeCheckout setting for checking out default branch (#4744) Fixes #4450 --- src/common/settingKeys.ts | 1 + src/github/folderRepositoryManager.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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 f7af70de98..b63fbd3481 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'; @@ -2167,6 +2167,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 {