Browse Source

Adds prompt option for patch repo location

main
Ramin Tadayon 1 year ago
parent
commit
4e97deefda
No known key found for this signature in database GPG Key ID: 79D60DDE3DFB95F5
2 changed files with 67 additions and 5 deletions
  1. +67
    -3
      src/plus/repos/repositoryIdentityService.ts
  2. +0
    -2
      src/uris/deepLinks/deepLinkService.ts

+ 67
- 3
src/plus/repos/repositoryIdentityService.ts View File

@ -1,7 +1,8 @@
import type { Disposable } from 'vscode';
import { Uri } from 'vscode';
import { Uri, window } from 'vscode';
import type { Container } from '../../container';
import { shortenRevision } from '../../git/models/reference';
import { RemoteResourceType } from '../../git/models/remoteResource';
import type { Repository } from '../../git/models/repository';
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
import { getRemoteProviderMatcher } from '../../git/remotes/remoteProviders';
@ -34,7 +35,7 @@ export class RepositoryIdentityService implements Disposable {
@log()
getRepository(
idOrIdentity: GkRepositoryId | RepositoryIdentity,
options?: { openIfNeeded?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean },
): Promise<Repository | undefined> {
return this.locateRepository(idOrIdentity, options);
}
@ -122,7 +123,41 @@ export class RepositoryIdentityService implements Disposable {
}
if (foundRepo == null && options?.prompt) {
// TODO@eamodio prompt the user here if we pass in
const locate = { title: 'Locate Repository' };
const cancel = { title: 'Cancel', isCloseAffordance: true };
const decision = await window.showInformationMessage(
`Unable to locate a repository for ${identity.name}`,
{ modal: true },
locate,
cancel,
);
if (decision !== locate) return undefined;
const repoLocatedUri = (
await window.showOpenDialog({
title: `Choose a location for ${identity.name}`,
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
})
)?.[0];
if (repoLocatedUri == null) return undefined;
const locatedRepo = await this.container.git.getOrOpenRepository(repoLocatedUri, {
closeOnOpen: true,
detectNested: false,
});
if (locatedRepo == null) return undefined;
if (
identity.initialCommitSha == null ||
(await this.container.git.validateReference(locatedRepo.uri, identity.initialCommitSha))
) {
foundRepo = locatedRepo;
await this.addFoundRepositoryToMap(foundRepo, identity);
}
}
return foundRepo;
@ -160,4 +195,33 @@ export class RepositoryIdentityService implements Disposable {
provider: data.provider,
};
}
private async addFoundRepositoryToMap(repo: Repository, identity?: RepositoryIdentity) {
const repoPath = repo.uri.fsPath;
const remotes = await repo.getRemotes();
for (const remote of remotes) {
const remoteUrl = remote.provider?.url({ type: RemoteResourceType.Repo });
if (remoteUrl != null) {
await this.container.repositoryPathMapping.writeLocalRepoPath({ remoteUrl: remoteUrl }, repoPath);
}
}
if (
identity?.provider?.id != null &&
identity?.provider?.repoDomain != null &&
identity?.provider?.repoName != null
) {
await this.container.repositoryPathMapping.writeLocalRepoPath(
{
repoInfo: {
provider: identity.provider.id,
owner: identity.provider.repoDomain,
repoName: identity.provider.repoName,
},
},
repoPath,
);
}
}
}

+ 0
- 2
src/uris/deepLinks/deepLinkService.ts View File

@ -5,8 +5,6 @@ import type { Container } from '../../container';
import { getBranchNameWithoutRemote } from '../../git/models/branch';
import type { GitReference } from '../../git/models/reference';
import { createReference, isSha } from '../../git/models/reference';
import type { Repository } from '../../git/models/repository';
import { isRepository } from '../../git/models/repository';
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
import type { RepositoryIdentity } from '../../gk/models/repositoryIdentities';
import { missingRepositoryId } from '../../gk/models/repositoryIdentities';

Loading…
Cancel
Save