Skip to content

Commit

Permalink
Fixes #863 - tells built-in git about found repos
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 21, 2021
1 parent 5060c2c commit 1d7be10
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes [#863](https://github.com/eamodio/vscode-gitlens/issues/863) - Pulling all repositories doesn't work unless built-in Git knows about the repo (requires VS Code v1.53 or later)
- Fixes [#1332](https://github.com/eamodio/vscode-gitlens/issues/1332) - Stashes created with command line don't show up in the "Stashes" section
- Fixes [#1045](https://github.com/eamodio/vscode-gitlens/issues/1045) - View File History not working - absolute path used — thanks to [PR #1334](https://github.com/eamodio/vscode-gitlens/pull/1334) by egfx-notifications ([@egfx-notifications](https://github.com/egfx-notifications))
- Fixes [#1323](https://github.com/eamodio/vscode-gitlens/issues/1323) - Interactive rebase hangs
Expand Down
1 change: 1 addition & 0 deletions src/@types/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export interface API {
toGitUri(uri: Uri, ref: string): Uri;
getRepository(uri: Uri): Repository | null;
init(root: Uri): Promise<Repository | null>;
openRepository?(root: Uri): Promise<Repository | null>

registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/git/coauthors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class CoAuthorsGitCommand extends QuickCommand<State> {
}

async execute(state: CoAuthorStepState) {
const repo = await GitService.getBuiltInGitRepository(state.repo.path);
const repo = await GitService.getOrOpenBuiltInGitRepository(state.repo.path);
if (repo == null) return;

let message = repo.inputBox.value;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/quickCommand.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ export async function* pickContributorsStep<
context: Context,
placeholder: string = 'Choose contributors',
): AsyncStepResultGenerator<GitContributor[]> {
const message = (await GitService.getBuiltInGitRepository(state.repo.path))?.inputBox.value;
const message = (await GitService.getOrOpenBuiltInGitRepository(state.repo.path))?.inputBox.value;

const step = QuickCommand.createPickStep<ContributorQuickPickItem>({
title: appendReposToTitle(context.title, state, context),
Expand Down
22 changes: 14 additions & 8 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ export class GitService implements Disposable {
if (!this._repositoryTree.has(r.path)) {
this._repositoryTree.set(r.path, r);
}

void GitService.openBuiltInGitRepository(r.path);
}
}
}
Expand Down Expand Up @@ -520,6 +522,8 @@ export class GitService implements Disposable {
if (!this._repositoryTree.has(r.path)) {
this._repositoryTree.set(r.path, r);
}

void GitService.openBuiltInGitRepository(r.path);
}

await this.updateContext(this._repositoryTree);
Expand Down Expand Up @@ -4006,17 +4010,19 @@ export class GitService implements Disposable {
}

@log()
static async getBuiltInGitRepository(repoPath: string): Promise<BuiltInGitRepository | undefined> {
static async getOrOpenBuiltInGitRepository(repoPath: string): Promise<BuiltInGitRepository | undefined> {
const gitApi = await GitService.getBuiltInGitApi();
if (gitApi == null) return undefined;

const normalizedPath = Strings.normalizePath(repoPath, { stripTrailingSlash: true }).toLowerCase();
if (gitApi?.openRepository != null) {
return (await gitApi?.openRepository?.(Uri.file(repoPath))) ?? undefined;
}

const repo = gitApi.repositories.find(
r => Strings.normalizePath(r.rootUri.fsPath, { stripTrailingSlash: true }).toLowerCase() === normalizedPath,
);
return gitApi?.getRepository(Uri.file(repoPath)) ?? undefined;
}

return repo;
@log()
static async openBuiltInGitRepository(repoPath: string): Promise<BuiltInGitRepository | undefined> {
const gitApi = await GitService.getBuiltInGitApi();
return (await gitApi?.openRepository?.(Uri.file(repoPath))) ?? undefined;
}

static getEncoding(repoPath: string, fileName: string): string;
Expand Down
6 changes: 3 additions & 3 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ export class Repository implements Disposable {
) {
try {
if (GitReference.isBranch(options.reference)) {
const repo = await GitService.getBuiltInGitRepository(this.path);
const repo = await GitService.getOrOpenBuiltInGitRepository(this.path);
if (repo == null) return;

if (options.publish != null) {
Expand All @@ -750,7 +750,7 @@ export class Repository implements Disposable {
}
}
} else if (options.reference != null) {
const repo = await GitService.getBuiltInGitRepository(this.path);
const repo = await GitService.getOrOpenBuiltInGitRepository(this.path);
if (repo == null) return;

const branch = await this.getBranch();
Expand Down Expand Up @@ -1053,7 +1053,7 @@ export class Repository implements Disposable {
}

private async tryWatchingForChangesViaBuiltInApi() {
const repo = await GitService.getBuiltInGitRepository(this.path);
const repo = await GitService.getOrOpenBuiltInGitRepository(this.path);
if (repo != null) {
const internalRepo = (repo as any)._repository;
if (internalRepo != null && 'onDidChangeRepository' in internalRepo) {
Expand Down

0 comments on commit 1d7be10

Please sign in to comment.