Skip to content

Commit 766d8a0

Browse files
Copilotalexr00
andcommitted
fix: start progress before fetch operation, include fetch in progress scope
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 3e1c44e commit 766d8a0

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/commands.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -859,32 +859,19 @@ export function registerCommands(
859859
*/
860860
telemetry.sendTelemetryEvent('pr.checkoutInWorktree');
861861

862-
// Prepare for parallel operations
862+
// Prepare for operations
863863
const repoRootPath = repositoryToUse.rootUri.fsPath;
864864
const parentDir = pathLib.dirname(repoRootPath);
865865
const defaultWorktreePath = pathLib.join(parentDir, `pr-${pullRequestModel.number}`);
866866
const branchName = prHead.ref;
867867
const remoteName = pullRequestModel.remote.remoteName;
868868

869-
// Run fetch and worktree location selection in parallel
870-
const [, worktreeUri] = await Promise.all([
871-
// Fetch the PR branch
872-
(async () => {
873-
try {
874-
await repositoryToUse.fetch({ remote: remoteName, ref: branchName });
875-
} catch (e) {
876-
const errorMessage = e instanceof Error ? e.message : String(e);
877-
Logger.appendLine(`Failed to fetch branch ${branchName}: ${errorMessage}`, logId);
878-
// Continue even if fetch fails - the branch might already be available locally
879-
}
880-
})(),
881-
// Ask user for worktree location
882-
vscode.window.showSaveDialog({
883-
defaultUri: vscode.Uri.file(defaultWorktreePath),
884-
title: vscode.l10n.t('Select Worktree Location'),
885-
saveLabel: vscode.l10n.t('Create Worktree'),
886-
})
887-
]);
869+
// Ask user for worktree location first (not in progress)
870+
const worktreeUri = await vscode.window.showSaveDialog({
871+
defaultUri: vscode.Uri.file(defaultWorktreePath),
872+
title: vscode.l10n.t('Select Worktree Location'),
873+
saveLabel: vscode.l10n.t('Create Worktree'),
874+
});
888875

889876
if (!worktreeUri) {
890877
return; // User cancelled
@@ -899,13 +886,22 @@ export function registerCommands(
899886
throw new Error(vscode.l10n.t('Git worktree API is not available. Please update VS Code to the latest version.'));
900887
}
901888

902-
// Create the worktree with progress
889+
// Start progress for fetch and worktree creation
903890
await vscode.window.withProgress(
904891
{
905892
location: vscode.ProgressLocation.Notification,
906893
title: vscode.l10n.t('Creating worktree for Pull Request #{0}...', pullRequestModel.number),
907894
},
908895
async () => {
896+
// Fetch the PR branch first
897+
try {
898+
await repositoryToUse.fetch({ remote: remoteName, ref: branchName });
899+
} catch (e) {
900+
const errorMessage = e instanceof Error ? e.message : String(e);
901+
Logger.appendLine(`Failed to fetch branch ${branchName}: ${errorMessage}`, logId);
902+
// Continue even if fetch fails - the branch might already be available locally
903+
}
904+
909905
// Use the git extension's createWorktree API
910906
await repositoryToUse.createWorktree!({
911907
path: worktreePath,

0 commit comments

Comments
 (0)