(forDirectory: vscode.Uri)
| 543 | private static secondsToWaitForGitToLoad = |
| 544 | process.env.NODE_ENV === "test" ? 1 : 20; |
| 545 | async getRepo(forDirectory: vscode.Uri): Promise<Repository | undefined> { |
| 546 | const workspaceDirs = this.getWorkspaceDirectories().map((dir) => |
| 547 | dir.toString(), |
| 548 | ); |
| 549 | const { foundInDir } = findUriInDirs( |
| 550 | forDirectory.toString(), |
| 551 | workspaceDirs, |
| 552 | ); |
| 553 | if (foundInDir) { |
| 554 | // Check if the repository is already cached |
| 555 | const cachedRepo = this.repoCache.get(foundInDir); |
| 556 | if (cachedRepo) { |
| 557 | return cachedRepo; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | let repo = await this._getRepo(forDirectory); |
| 562 | |
| 563 | let i = 0; |
| 564 | while (!repo?.state?.HEAD?.name) { |
| 565 | if (this._repoWasNone) { |
| 566 | return undefined; |
| 567 | } |
| 568 | |
| 569 | await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 570 | i++; |
| 571 | if (i >= VsCodeIdeUtils.secondsToWaitForGitToLoad) { |
| 572 | this._repoWasNone = true; |
| 573 | return undefined; |
| 574 | } |
| 575 | repo = await this._getRepo(forDirectory); |
| 576 | } |
| 577 | |
| 578 | if (foundInDir) { |
| 579 | // Cache the repository for the parent directory |
| 580 | this.repoCache.set(foundInDir, repo); |
| 581 | } |
| 582 | |
| 583 | return repo; |
| 584 | } |
| 585 | |
| 586 | async getGitRoot(forDirectory: vscode.Uri): Promise<vscode.Uri | undefined> { |
| 587 | const repo = await this.getRepo(forDirectory); |
no test coverage detected