Browse Source

Ensures `HEAD` gets remapped to proper revision

Adds types for comparison uri methods
main
Eric Amodio 2 years ago
parent
commit
86a30ae17a
4 changed files with 56 additions and 21 deletions
  1. +6
    -3
      src/env/node/git/localGitProvider.ts
  2. +18
    -3
      src/git/gitProvider.ts
  3. +13
    -4
      src/git/gitProviderService.ts
  4. +19
    -11
      src/premium/github/githubGitProvider.ts

+ 6
- 3
src/env/node/git/localGitProvider.ts View File

@ -30,7 +30,10 @@ import {
GitProvider, GitProvider,
GitProviderDescriptor, GitProviderDescriptor,
GitProviderId, GitProviderId,
NextComparisionUrisResult,
PagedResult, PagedResult,
PreviousComparisionUrisResult,
PreviousLineComparisionUrisResult,
RepositoryCloseEvent, RepositoryCloseEvent,
RepositoryInitWatcher, RepositoryInitWatcher,
RepositoryOpenEvent, RepositoryOpenEvent,
@ -2677,7 +2680,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
uri: Uri, uri: Uri,
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; next: GitUri | undefined; deleted?: boolean } | undefined> {
): Promise<NextComparisionUrisResult | undefined> {
// If we have no ref (or staged ref) there is no next commit // If we have no ref (or staged ref) there is no next commit
if (!ref) return undefined; if (!ref) return undefined;
@ -2781,7 +2784,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
firstParent: boolean = false, firstParent: boolean = false,
): Promise<{ current: GitUri; previous: GitUri | undefined } | undefined> {
): Promise<PreviousComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return undefined; if (ref === GitRevision.deletedOrMissing) return undefined;
const relativePath = this.getRelativePath(uri, repoPath); const relativePath = this.getRelativePath(uri, repoPath);
@ -2858,7 +2861,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
editorLine: number, // 0-based, Git is 1-based editorLine: number, // 0-based, Git is 1-based
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; previous: GitUri | undefined; line: number } | undefined> {
): Promise<PreviousLineComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return undefined; if (ref === GitRevision.deletedOrMissing) return undefined;
let relativePath = this.getRelativePath(uri, repoPath); let relativePath = this.getRelativePath(uri, repoPath);

+ 18
- 3
src/git/gitProvider.ts View File

@ -65,6 +65,21 @@ export interface PagedResult {
readonly values: NonNullable<T>[]; readonly values: NonNullable<T>[];
} }
export interface NextComparisionUrisResult {
current: GitUri;
next: GitUri | undefined;
deleted?: boolean | undefined;
}
export interface PreviousComparisionUrisResult {
current: GitUri;
previous: GitUri | undefined;
}
export interface PreviousLineComparisionUrisResult extends PreviousComparisionUrisResult {
line: number;
}
export interface RepositoryCloseEvent { export interface RepositoryCloseEvent {
readonly uri: Uri; readonly uri: Uri;
} }
@ -300,21 +315,21 @@ export interface GitProvider extends Disposable {
uri: Uri, uri: Uri,
ref: string | undefined, ref: string | undefined,
skip?: number, skip?: number,
): Promise<{ current: GitUri; next: GitUri | undefined; deleted?: boolean | undefined } | undefined>;
): Promise<NextComparisionUrisResult | undefined>;
getPreviousComparisonUris( getPreviousComparisonUris(
repoPath: string, repoPath: string,
uri: Uri, uri: Uri,
ref: string | undefined, ref: string | undefined,
skip?: number, skip?: number,
firstParent?: boolean, firstParent?: boolean,
): Promise<{ current: GitUri; previous: GitUri | undefined } | undefined>;
): Promise<PreviousComparisionUrisResult | undefined>;
getPreviousComparisonUrisForLine( getPreviousComparisonUrisForLine(
repoPath: string, repoPath: string,
uri: Uri, uri: Uri,
editorLine: number, editorLine: number,
ref: string | undefined, ref: string | undefined,
skip?: number, skip?: number,
): Promise<{ current: GitUri; previous: GitUri | undefined; line: number } | undefined>;
): Promise<PreviousLineComparisionUrisResult | undefined>;
getIncomingActivity( getIncomingActivity(
repoPath: string, repoPath: string,
options?: { options?: {

+ 13
- 4
src/git/gitProviderService.ts View File

@ -29,7 +29,16 @@ import { count, filter, first, flatMap, map } from '../system/iterable';
import { dirname, getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path'; import { dirname, getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path';
import { cancellable, isPromise, PromiseCancelledError } from '../system/promise'; import { cancellable, isPromise, PromiseCancelledError } from '../system/promise';
import { VisitedPathsTrie } from '../system/trie'; import { VisitedPathsTrie } from '../system/trie';
import { GitProvider, GitProviderDescriptor, GitProviderId, PagedResult, ScmRepository } from './gitProvider';
import {
GitProvider,
GitProviderDescriptor,
GitProviderId,
NextComparisionUrisResult,
PagedResult,
PreviousComparisionUrisResult,
PreviousLineComparisionUrisResult,
ScmRepository,
} from './gitProvider';
import { GitUri } from './gitUri'; import { GitUri } from './gitUri';
import { import {
BranchSortOptions, BranchSortOptions,
@ -1269,7 +1278,7 @@ export class GitProviderService implements Disposable {
uri: Uri, uri: Uri,
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; next: GitUri | undefined; deleted?: boolean } | undefined> {
): Promise<NextComparisionUrisResult | undefined> {
if (!ref) return Promise.resolve(undefined); if (!ref) return Promise.resolve(undefined);
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
@ -1283,7 +1292,7 @@ export class GitProviderService implements Disposable {
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
firstParent: boolean = false, firstParent: boolean = false,
): Promise<{ current: GitUri; previous: GitUri | undefined } | undefined> {
): Promise<PreviousComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return Promise.resolve(undefined); if (ref === GitRevision.deletedOrMissing) return Promise.resolve(undefined);
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
@ -1297,7 +1306,7 @@ export class GitProviderService implements Disposable {
editorLine: number, editorLine: number,
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; previous: GitUri | undefined; line: number } | undefined> {
): Promise<PreviousLineComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return Promise.resolve(undefined); if (ref === GitRevision.deletedOrMissing) return Promise.resolve(undefined);
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);

+ 19
- 11
src/premium/github/githubGitProvider.ts View File

@ -27,7 +27,10 @@ import {
import { import {
GitProvider, GitProvider,
GitProviderId, GitProviderId,
NextComparisionUrisResult,
PagedResult, PagedResult,
PreviousComparisionUrisResult,
PreviousLineComparisionUrisResult,
RepositoryCloseEvent, RepositoryCloseEvent,
RepositoryOpenEvent, RepositoryOpenEvent,
ScmRepository, ScmRepository,
@ -402,7 +405,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
// const sha = await this.resolveReferenceCore(uri.repoPath!, metadata, uri.sha); // const sha = await this.resolveReferenceCore(uri.repoPath!, metadata, uri.sha);
// if (sha == null) return undefined; // if (sha == null) return undefined;
const ref = uri.sha ?? (await metadata.getRevision()).revision;
const ref = !uri.sha || uri.sha === 'HEAD' ? (await metadata.getRevision()).revision : uri.sha;
const blame = await github.getBlame( const blame = await github.getBlame(
session?.accessToken, session?.accessToken,
metadata.repo.owner, metadata.repo.owner,
@ -539,7 +542,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const root = remotehub.getVirtualUri(remotehub.getProviderRootUri(uri)); const root = remotehub.getVirtualUri(remotehub.getProviderRootUri(uri));
const relativePath = this.getRelativePath(uri, root); const relativePath = this.getRelativePath(uri, root);
const ref = uri.sha ?? (await metadata.getRevision()).revision;
const ref = !uri.sha || uri.sha === 'HEAD' ? (await metadata.getRevision()).revision : uri.sha;
const blame = await github.getBlame( const blame = await github.getBlame(
session?.accessToken, session?.accessToken,
metadata.repo.owner, metadata.repo.owner,
@ -917,11 +920,12 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const file = this.getRelativePath(uri, remotehub.getProviderRootUri(uri)); const file = this.getRelativePath(uri, remotehub.getProviderRootUri(uri));
const ref = !options?.ref || options.ref === 'HEAD' ? (await metadata.getRevision()).revision : options.ref;
const commit = await github.getCommitForFile( const commit = await github.getCommitForFile(
session?.accessToken, session?.accessToken,
metadata.repo.owner, metadata.repo.owner,
metadata.repo.name, metadata.repo.name,
options?.ref ?? (await metadata.getRevision()).revision,
ref,
file, file,
); );
if (commit == null) return undefined; if (commit == null) return undefined;
@ -1138,7 +1142,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
try { try {
const { metadata, github, session } = await this.ensureRepositoryContext(repoPath); const { metadata, github, session } = await this.ensureRepositoryContext(repoPath);
const ref = options?.ref ?? (await metadata.getRevision()).revision;
const ref = !options?.ref || options.ref === 'HEAD' ? (await metadata.getRevision()).revision : options.ref;
const result = await github.getCommits(session?.accessToken, metadata.repo.owner, metadata.repo.name, ref, { const result = await github.getCommits(session?.accessToken, metadata.repo.owner, metadata.repo.name, ref, {
all: options?.all, all: options?.all,
authors: options?.authors, authors: options?.authors,
@ -1522,7 +1526,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
// range = new Range(range.end, range.start); // range = new Range(range.end, range.start);
// } // }
const ref = options?.ref ?? (await metadata.getRevision()).revision;
const ref = !options?.ref || options.ref === 'HEAD' ? (await metadata.getRevision()).revision : options.ref;
const result = await github.getCommits(session?.accessToken, metadata.repo.owner, metadata.repo.name, ref, { const result = await github.getCommits(session?.accessToken, metadata.repo.owner, metadata.repo.name, ref, {
all: options?.all, all: options?.all,
cursor: options?.cursor, cursor: options?.cursor,
@ -1719,7 +1723,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
uri: Uri, uri: Uri,
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; next: GitUri | undefined; deleted?: boolean } | undefined> {
): Promise<NextComparisionUrisResult | undefined> {
// If we have no ref there is no next commit // If we have no ref there is no next commit
if (!ref) return undefined; if (!ref) return undefined;
@ -1731,13 +1735,17 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const { metadata, github, remotehub, session } = context; const { metadata, github, remotehub, session } = context;
const relativePath = this.getRelativePath(uri, remotehub.getProviderRootUri(uri)); const relativePath = this.getRelativePath(uri, remotehub.getProviderRootUri(uri));
const revision = await metadata.getRevision();
const revision = (await metadata.getRevision()).revision;
if (ref === 'HEAD') {
ref = revision;
}
const refs = await github.getNextCommitRefs( const refs = await github.getNextCommitRefs(
session.accessToken, session.accessToken,
metadata.repo.owner, metadata.repo.owner,
metadata.repo.name, metadata.repo.name,
revision.revision,
revision,
relativePath, relativePath,
ref, ref,
); );
@ -1764,7 +1772,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
_firstParent: boolean = false, _firstParent: boolean = false,
): Promise<{ current: GitUri; previous: GitUri | undefined } | undefined> {
): Promise<PreviousComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return undefined; if (ref === GitRevision.deletedOrMissing) return undefined;
const cc = Logger.getCorrelationContext(); const cc = Logger.getCorrelationContext();
@ -1786,7 +1794,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
session.accessToken, session.accessToken,
metadata.repo.owner, metadata.repo.owner,
metadata.repo.name, metadata.repo.name,
ref ? ref : (await metadata.getRevision()).revision,
!ref || ref === 'HEAD' ? (await metadata.getRevision()).revision : ref,
{ {
path: relativePath, path: relativePath,
first: offset + skip + 1, first: offset + skip + 1,
@ -1832,7 +1840,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
editorLine: number, // 0-based, Git is 1-based editorLine: number, // 0-based, Git is 1-based
ref: string | undefined, ref: string | undefined,
skip: number = 0, skip: number = 0,
): Promise<{ current: GitUri; previous: GitUri | undefined; line: number } | undefined> {
): Promise<PreviousLineComparisionUrisResult | undefined> {
if (ref === GitRevision.deletedOrMissing) return undefined; if (ref === GitRevision.deletedOrMissing) return undefined;
const cc = Logger.getCorrelationContext(); const cc = Logger.getCorrelationContext();

Loading…
Cancel
Save