Skip to content

Commit 88f873a

Browse files
committed
mhutchie#479 Additional RepoManager adjustments and improvements.
1 parent 31806ca commit 88f873a

File tree

3 files changed

+235
-36
lines changed

3 files changed

+235
-36
lines changed

src/repoManager.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export class RepoManager extends Disposable {
8686
this.stopWatchingFolder(path);
8787
}
8888
}
89-
changes = this.updateReposWorkspaceFolderIndex() || changes;
89+
if (this.updateReposWorkspaceFolderIndex()) {
90+
this.extensionState.saveRepos(this.repos);
91+
changes = true;
92+
}
9093

9194
if (changes) {
9295
this.sendRepos();
@@ -150,8 +153,13 @@ export class RepoManager extends Disposable {
150153
*/
151154
private async startupTasks() {
152155
this.removeReposNotInWorkspace();
153-
this.updateReposWorkspaceFolderIndex();
154-
if (!await this.checkReposExist()) this.sendRepos();
156+
if (this.updateReposWorkspaceFolderIndex()) {
157+
this.extensionState.saveRepos(this.repos);
158+
}
159+
if (!await this.checkReposExist()) {
160+
// On startup, ensure that sendRepo is called (even if no changes were made)
161+
this.sendRepos();
162+
}
155163
this.checkReposForNewConfig();
156164
await this.checkReposForNewSubmodules();
157165
await this.searchWorkspaceForRepos();
@@ -363,21 +371,22 @@ export class RepoManager extends Disposable {
363371
* @returns TRUE => At least one repository was removed or transferred, FALSE => No repositories were removed.
364372
*/
365373
public checkReposExist() {
366-
return new Promise<boolean>(resolve => {
367-
let repoPaths = Object.keys(this.repos), changes = false;
368-
evalPromises(repoPaths, 3, path => this.dataSource.repoRoot(path)).then(results => {
369-
for (let i = 0; i < repoPaths.length; i++) {
370-
if (results[i] === null) {
371-
this.removeRepo(repoPaths[i]);
372-
changes = true;
373-
} else if (repoPaths[i] !== results[i]) {
374-
this.transferRepoState(repoPaths[i], results[i]!);
375-
changes = true;
376-
}
374+
let repoPaths = Object.keys(this.repos), changes = false;
375+
return evalPromises(repoPaths, 3, (path) => this.dataSource.repoRoot(path)).then((results) => {
376+
for (let i = 0; i < repoPaths.length; i++) {
377+
if (results[i] === null) {
378+
this.removeRepo(repoPaths[i]);
379+
changes = true;
380+
} else if (repoPaths[i] !== results[i]) {
381+
this.transferRepoState(repoPaths[i], results[i]!);
382+
changes = true;
377383
}
378-
if (changes) this.sendRepos();
379-
resolve(changes);
380-
});
384+
}
385+
}).catch(() => { }).then(() => {
386+
if (changes) {
387+
this.sendRepos();
388+
}
389+
return changes;
381390
});
382391
}
383392

@@ -429,6 +438,7 @@ export class RepoManager extends Disposable {
429438
private transferRepoState(oldRepo: string, newRepo: string) {
430439
this.repos[newRepo] = this.repos[oldRepo];
431440
delete this.repos[oldRepo];
441+
this.updateReposWorkspaceFolderIndex(newRepo);
432442
this.extensionState.saveRepos(this.repos);
433443
this.extensionState.transferRepo(oldRepo, newRepo);
434444

0 commit comments

Comments
 (0)