Skip to content

Commit

Permalink
Fixes initial patch repo location state on cloud patch open
Browse files Browse the repository at this point in the history
  • Loading branch information
axosoft-ramint committed Nov 8, 2023
1 parent 9d4de01 commit 61b51c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/plus/drafts/draftsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ export class DraftService implements Disposable {

const [contentsResult, repositoryResult] = await Promise.allSettled([
this.getPatchContentsCore(patch.secureLink),
this.container.repositoryIdentity.getRepositoryOrIdentity(patch.gkRepositoryId),
this.container.repositoryIdentity.getRepositoryOrIdentity(patch.gkRepositoryId, {
openIfNeeded: true,
skipRefValidation: true,
}),
]);

const contents = getSettledValue(contentsResult)!;
Expand Down
22 changes: 13 additions & 9 deletions src/plus/repos/repositoryIdentityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,46 @@ export class RepositoryIdentityService implements Disposable {

getRepository(
id: GkRepositoryId,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined>;
getRepository(
identity: RepositoryIdentity,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined>;

@log()
getRepository(
idOrIdentity: GkRepositoryId | RepositoryIdentity,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined> {
return this.locateRepository(idOrIdentity, options);
}

@log()
async getRepositoryOrIdentity(
id: GkRepositoryId,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | RepositoryIdentity> {
const identity = await this.getRepositoryIdentity(id);
return (await this.locateRepository(identity, options)) ?? identity;
}

private async locateRepository(
id: GkRepositoryId,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined>;
private async locateRepository(
identity: RepositoryIdentity,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined>;
private async locateRepository(
idOrIdentity: GkRepositoryId | RepositoryIdentity,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined>;
@log()
private async locateRepository(
idOrIdentity: GkRepositoryId | RepositoryIdentity,
options?: { openIfNeeded?: boolean; prompt?: boolean },
options?: { openIfNeeded?: boolean; prompt?: boolean; skipRefValidation?: boolean },
): Promise<Repository | undefined> {
const identity =
typeof idOrIdentity === 'string' ? await this.getRepositoryIdentity(idOrIdentity) : idOrIdentity;
Expand Down Expand Up @@ -111,7 +111,11 @@ export class RepositoryIdentityService implements Disposable {
}
}

if (identity.initialCommitSha != null && identity.initialCommitSha !== missingRepositoryId) {
if (
!options?.skipRefValidation &&
identity.initialCommitSha != null &&
identity.initialCommitSha !== missingRepositoryId
) {
// Repo ID can be any valid SHA in the repo, though standard practice is to use the
// first commit SHA.
if (await this.container.git.validateReference(repo.uri, identity.initialCommitSha)) {
Expand Down

0 comments on commit 61b51c7

Please sign in to comment.