diff --git a/src/commands/ghpr/createWorktree.ts b/src/commands/ghpr/createWorktree.ts index 8cc9e09..42c2ad4 100644 --- a/src/commands/ghpr/createWorktree.ts +++ b/src/commands/ghpr/createWorktree.ts @@ -90,7 +90,7 @@ export class CreateWorktreeCommand extends Command { ); if (result?.title !== 'Yes') return; - await GitActions.Remote.add(repo, remoteOwner, remoteUrl, { confirm: false, fetch: true }); + await GitActions.Remote.add(repo, remoteOwner, remoteUrl, { confirm: false, fetch: true, reveal: false }); [remote] = await repo.getRemotes({ filter: r => r.url === remoteUrl }); if (remote == null) return; } else { @@ -110,16 +110,17 @@ export class CreateWorktreeCommand extends Command { }), ); + // Ensure that the worktree was created + const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === ref); + if (worktree == null) return; + // Save the PR number in the branch config - const cfg = await this.container.git.getConfig(repo.path, `branch.${ref}.remote`); - if (cfg != null) { - // https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18 - void this.container.git.setConfig( - repo.path, - `branch.${ref}.github-pr-owner-number`, - `${rootOwner}#${rootRepository}#${number}`, - ); - } + // https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18 + void this.container.git.setConfig( + repo.path, + `branch.${ref}.github-pr-owner-number`, + `${rootOwner}#${rootRepository}#${number}`, + ); } catch (ex) { Logger.error(ex, 'CreateWorktreeCommand', 'Unable to create worktree'); void window.showErrorMessage(`Unable to create worktree for ${ref}`); diff --git a/src/commands/git/remote.ts b/src/commands/git/remote.ts index 80f2d24..a8537a3 100644 --- a/src/commands/git/remote.ts +++ b/src/commands/git/remote.ts @@ -42,6 +42,8 @@ interface AddState { name: string; url: string; flags: AddFlags[]; + + reveal?: boolean; } interface RemoveState { @@ -315,18 +317,14 @@ export class RemoteGitCommand extends QuickCommand { } QuickCommand.endSteps(state); - const remote = await state.repo.addRemote( - state.name, - state.url, - state.flags.includes('-f') ? { fetch: true } : undefined, - ); - queueMicrotask( - () => - void GitActions.Remote.reveal(remote, { - focus: true, - select: true, - }), - ); + + await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined); + if (state.reveal !== false) { + void GitActions.Remote.reveal(undefined, { + focus: true, + select: true, + }); + } } } diff --git a/src/commands/git/worktree.ts b/src/commands/git/worktree.ts index de56a97..f186591 100644 --- a/src/commands/git/worktree.ts +++ b/src/commands/git/worktree.ts @@ -64,6 +64,8 @@ interface CreateState { reference?: GitReference; createBranch: string; flags: CreateFlags[]; + + reveal?: boolean; } type DeleteFlags = '--force'; @@ -383,10 +385,12 @@ export class WorktreeGitCommand extends QuickCommand { force: state.flags.includes('--force'), }); - void GitActions.Worktree.reveal(worktree, { - select: true, - focus: true, - }); + if (state.reveal !== false) { + void GitActions.Worktree.reveal(undefined, { + select: true, + focus: true, + }); + } if (worktree == null) return; diff --git a/src/commands/gitCommands.actions.ts b/src/commands/gitCommands.actions.ts index a76c342..fa7ffb0 100644 --- a/src/commands/gitCommands.actions.ts +++ b/src/commands/gitCommands.actions.ts @@ -826,7 +826,7 @@ export namespace GitActions { repo?: string | Repository, name?: string, url?: string, - options?: { confirm?: boolean; fetch?: boolean }, + options?: { confirm?: boolean; fetch?: boolean; reveal?: boolean }, ) { return executeGitCommand({ command: 'remote', @@ -837,6 +837,7 @@ export namespace GitActions { name: name, url: url, flags: options?.fetch ? ['-f'] : undefined, + reveal: options?.reveal, }, }); } @@ -1013,10 +1014,15 @@ export namespace GitActions { } export namespace Worktree { - export function create(repo?: string | Repository, uri?: Uri, ref?: GitReference) { + export function create( + repo?: string | Repository, + uri?: Uri, + ref?: GitReference, + options?: { reveal?: boolean }, + ) { return executeGitCommand({ command: 'worktree', - state: { subcommand: 'create', repo: repo, uri: uri, reference: ref }, + state: { subcommand: 'create', repo: repo, uri: uri, reference: ref, reveal: options?.reveal }, }); }