Skip to content

Commit

Permalink
fixup! Simplify scm/git data flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Jun 3, 2019
1 parent 851d050 commit 8fc137c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/git/src/browser/git-repository-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface GitRefreshOptions {
@injectable()
export class GitRepositoryProvider {

protected readonly onDidChangeRepositoryEmitter = new Emitter<Repository | undefined>();

constructor(
@inject(Git) protected readonly git: Git,
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService,
Expand All @@ -53,6 +55,12 @@ export class GitRepositoryProvider {

protected readonly toDisposeOnWorkspaceChange = new DisposableCollection();
protected async initialize(): Promise<void> {
this.scmService.onDidChangeSelectedRepositories(scmRepository => {
if (scmRepository && scmRepository.provider.contextValue === 'Git') {
this.onDidChangeRepositoryEmitter.fire({ localUri: scmRepository.provider.rootUri });
}
});

/*
* Listen for changes to the list of workspaces. This will not be fired when changes
* are made inside a workspace.
Expand Down Expand Up @@ -92,6 +100,21 @@ export class GitRepositoryProvider {
}
}

/**
* Sets or un-sets the repository.
*/
set selectedRepository(repository: Repository | undefined) {
if (repository) {
this.scmService.selectedRepository = this.scmService.repositories.find(scmRepository => scmRepository.provider.rootUri === repository.localUri);
} else {
this.scmService.selectedRepository = undefined;
}
}

get onDidChangeRepository(): Event<Repository | undefined> {
return this.onDidChangeRepositoryEmitter.event;
}

/**
* Returns with all know repositories.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/git/src/browser/git-repository-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class GitRepositoryTracker {
this.scmService.onDidChangeSelectedRepositories(async repository => {
this.workingDirectoryStatus = undefined;
this.toDispose.dispose();
if (repository && repository.provider.rootUri) {
if (repository && repository.provider.contextValue === 'Git') {
const gitRepository = { localUri: repository.provider.rootUri };
this.toDispose.push(await this.gitWatcher.watchGitChanges(gitRepository));
this.toDispose.push(this.gitWatcher.onGitEvent((event: GitStatusChangeEvent) => {
Expand Down

0 comments on commit 8fc137c

Please sign in to comment.