Skip to content

Commit

Permalink
Avoids extra lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 11, 2025
1 parent 600c7dd commit 5abb804
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/commands/git/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
if (state.addRemote != null) {
await state.repo.git
.remotes()
.addRemoteWithResult?.(state.addRemote.name, state.addRemote.url, { fetch: true });
.addRemote?.(state.addRemote.name, state.addRemote.url, { fetch: true });
}

worktree = await state.repo.git.worktrees()?.createWorktreeWithResult(uri.fsPath, {
Expand Down
34 changes: 14 additions & 20 deletions src/uris/deepLinks/deepLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,21 +924,19 @@ export class DeepLinkService implements Disposable {

if (remoteName) {
try {
await repo.git.remotes().addRemoteWithResult?.(remoteName, remoteUrl, { fetch: true });
this._context.remote = await repo.git
.remotes()
.addRemoteWithResult?.(remoteName, remoteUrl, { fetch: true });
if (!this._context.remote) {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}
} catch {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}

[this._context.remote] = await repo.git
.remotes()
.getRemotes({ filter: r => r.url === remoteUrl });
if (!this._context.remote) {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}
} else {
action = DeepLinkServiceAction.DeepLinkCancelled;
break;
Expand All @@ -953,23 +951,19 @@ export class DeepLinkService implements Disposable {

if (secondaryRemoteName) {
try {
await repo.git
this._context.secondaryRemote = await repo.git
.remotes()
.addRemoteWithResult?.(secondaryRemoteName, secondaryRemoteUrl, { fetch: true });
if (!this._context.secondaryRemote) {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}
} catch {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}

[this._context.secondaryRemote] = await repo.git.remotes().getRemotes({
filter: r => r.url === secondaryRemoteUrl,
});
if (!this._context.secondaryRemote) {
action = DeepLinkServiceAction.DeepLinkErrored;
message = 'Failed to add remote.';
break;
}
} else {
action = DeepLinkServiceAction.DeepLinkCancelled;
break;
Expand Down

0 comments on commit 5abb804

Please sign in to comment.