diff --git a/src/__mocks__/vscode.js b/src/__mocks__/vscode.js index 5e7d203605aa56fd4ad16c0a0ad592b299ebf3b9..2f7ae4e87146e0f0faf8692251862ff5f4b4b3e5 100644 --- a/src/__mocks__/vscode.js +++ b/src/__mocks__/vscode.js @@ -21,6 +21,7 @@ module.exports = { showWarningMessage: jest.fn(), showErrorMessage: jest.fn(), createStatusBarItem: jest.fn(), + withProgress: jest.fn(), }, commands: { executeCommand: jest.fn(), @@ -43,4 +44,7 @@ module.exports = { }, CancellationTokenSource: jest.fn(), ThemeColor: jest.fn(color => color), + ProgressLocation: { + Notification: 'Notification', + }, }; diff --git a/src/commands/checkout_mr_branch.test.ts b/src/commands/checkout_mr_branch.test.ts index b8a30248750d24ba0595095ebe6fd745e37979b5..f88e6c31b6a90a71ca062b7d979494ce6186e09e 100644 --- a/src/commands/checkout_mr_branch.test.ts +++ b/src/commands/checkout_mr_branch.test.ts @@ -17,6 +17,7 @@ describe('checkout MR branch', () => { lastCommitSha: mr.sha, }; wrappedRepository = mockRepository as WrappedRepository; + (vscode.window.withProgress as jest.Mock).mockImplementation((_, task) => task()); }); afterEach(() => { diff --git a/src/commands/checkout_mr_branch.ts b/src/commands/checkout_mr_branch.ts index b578f767e316cb161b94a504a218b31128345e98..ff6a4acf91f52955fef6dbaa077c3d3277863ceb 100644 --- a/src/commands/checkout_mr_branch.ts +++ b/src/commands/checkout_mr_branch.ts @@ -2,7 +2,6 @@ import * as vscode from 'vscode'; import * as assert from 'assert'; import { MrItemModel } from '../data_providers/items/mr_item_model'; import { VS_COMMANDS } from '../command_names'; -import { doNotAwait } from '../utils/do_not_await'; const handleGitError = async (e: { stderr: string }) => { const SEE_GIT_LOG = 'See Git Log'; @@ -22,9 +21,14 @@ export const checkoutMrBranch = async (mrItemModel: MrItemModel): Promise ); try { const { repository } = mrItemModel; - doNotAwait(vscode.window.showInformationMessage('Fetching branches...')); - await repository.fetch(); - await repository.checkout(mr.source_branch); + await vscode.window.withProgress( + { location: vscode.ProgressLocation.Notification, title: `Checking out ${mr.source_branch}` }, + async () => { + await repository.fetch(); + await repository.checkout(mr.source_branch); + }, + ); + if (repository.lastCommitSha !== mr.sha) { await vscode.window.showWarningMessage( `Branch changed to ${mr.source_branch}, but it's out of sync with the remote branch. Synchronize it by pushing or pulling.`,