Browse Source

Adds an overload for better perf optimization

main
Eric Amodio 1 year ago
parent
commit
bc99003bf5
2 changed files with 11 additions and 5 deletions
  1. +3
    -1
      src/commands/ghpr/createWorktree.ts
  2. +8
    -4
      src/git/models/remote.ts

+ 3
- 1
src/commands/ghpr/createWorktree.ts View File

@ -6,6 +6,7 @@ import { add as addRemote } from '../../git/actions/remote';
import { create as createWorktree } from '../../git/actions/worktree'; import { create as createWorktree } from '../../git/actions/worktree';
import { GitReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference';
import type { GitRemote } from '../../git/models/remote'; import type { GitRemote } from '../../git/models/remote';
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
import { Logger } from '../../logger'; import { Logger } from '../../logger';
import { command } from '../../system/command'; import { command } from '../../system/command';
import { waitUntilNextTick } from '../../system/promise'; import { waitUntilNextTick } from '../../system/promise';
@ -79,9 +80,10 @@ export class CreateWorktreeCommand extends Command {
} }
const remoteUrl = remoteUri.toString(); const remoteUrl = remoteUri.toString();
const [, remoteDomain, remotePath] = parseGitRemoteUrl(remoteUrl);
let remote: GitRemote | undefined; let remote: GitRemote | undefined;
[remote] = await repo.getRemotes({ filter: r => r.matches(remoteUrl) });
[remote] = await repo.getRemotes({ filter: r => r.matches(remoteDomain, remotePath) });
if (remote == null) { if (remote == null) {
const result = await window.showInformationMessage( const result = await window.showInformationMessage(
`Unable to find a remote for '${remoteUrl}'. Would you like to add a new remote?`, `Unable to find a remote for '${remoteUrl}'. Would you like to add a new remote?`,

+ 8
- 4
src/git/models/remote.ts View File

@ -90,11 +90,15 @@ export class GitRemote
return this.provider?.hasRichIntegration() ?? false; return this.provider?.hasRichIntegration() ?? false;
} }
matches(url: string): boolean {
if (equalsIgnoreCase(url, this.url)) return true;
matches(url: string): boolean;
matches(domain: string, path: string): boolean;
matches(urlOrDomain: string, path?: string): boolean {
if (path == null) {
if (equalsIgnoreCase(urlOrDomain, this.url)) return true;
[, urlOrDomain, path] = parseGitRemoteUrl(urlOrDomain);
}
const [, domain, path] = parseGitRemoteUrl(url);
return equalsIgnoreCase(domain, this.domain) && equalsIgnoreCase(path, this.path);
return equalsIgnoreCase(urlOrDomain, this.domain) && equalsIgnoreCase(path, this.path);
} }
async setAsDefault(value: boolean = true) { async setAsDefault(value: boolean = true) {

Loading…
Cancel
Save