Skip to content

Commit 988c7db

Browse files
authored
Add support for multi root workspaces (#357)
* Add support for multi root workspaces * Update change log
1 parent 172ece8 commit 988c7db

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Version 0.4.6
22
- Handle cases where folder/file names conflicts with brancch names [#205](https://github.com/DonJayamanne/gitHistoryVSCode/issues/205), [#340](https://github.com/DonJayamanne/gitHistoryVSCode/issues/340)
3+
- Adds support for multi-root workspace folders [#346](https://github.com/DonJayamanne/gitHistoryVSCode/issues/346)
34

45
## Version 0.4.5
56
- Make search case-insensitive PR [#334](https://github.com/DonJayamanne/gitHistoryVSCode/pull/334)

src/common/uiService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ export class UiService implements IUiService {
3030
return modeChoice.label === allBranches ? BranchSelection.All : BranchSelection.Current;
3131
}
3232
public async getWorkspaceFolder(uri?: Uri): Promise<WorkspaceGitRoot | undefined> {
33-
let workspaceFolder: string | undefined;
33+
let workspaceFolder: Uri | undefined;
3434
const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
3535
if (uri) {
3636
const workspaceFolderUri = workspaceService.getWorkspaceFolder(uri);
3737
if (workspaceFolderUri) {
38-
workspaceFolder = workspaceFolderUri.uri.fsPath;
38+
workspaceFolder = workspaceFolderUri.uri;
3939
}
4040
}
4141
if (!Array.isArray(workspaceService.workspaceFolders) || workspaceService.workspaceFolders.length === 0) {
4242
this.serviceContainer.get<IApplicationShell>(IApplicationShell).showInformationMessage('Please open a workspace folder');
4343
return;
4444
}
4545

46-
const firstWorkspaceFolder = workspaceService.workspaceFolders[0]!.uri.fsPath;
47-
const gitService = await this.serviceContainer.get<IGitServiceFactory>(IGitServiceFactory).createGitService(firstWorkspaceFolder, firstWorkspaceFolder);
48-
const gitRoots = await gitService.getGitRoots(workspaceFolder);
46+
const firstWorkspaceFolder = workspaceService.workspaceFolders[0].uri.fsPath;
47+
const folders = workspaceFolder ? [workspaceFolder] : workspaceService.workspaceFolders.map(item => item.uri);
48+
const gitServices = await Promise.all(folders.map(async folder => {
49+
const gitService = await this.serviceContainer.get<IGitServiceFactory>(IGitServiceFactory).createGitService(folder.fsPath, folder);
50+
return gitService.getGitRoots(folder.fsPath);
51+
}));
52+
const flattendGitServices = gitServices.reduce((a, b) => a.concat(b), []);
4953
// Filter to get only those that belong to a workspace folder
50-
const filteredGitRoots = gitRoots
54+
const filteredGitRoots = flattendGitServices
5155
.map(gitRoot => {
5256
const workspaceFolderUri = workspaceService.getWorkspaceFolder(Uri.file(gitRoot));
5357
if (workspaceFolderUri) {

0 commit comments

Comments
 (0)