Skip to content

Commit 0323325

Browse files
committed
Improve comments on findRemote
1 parent 019195b commit 0323325

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

extensions/ql-vscode/src/databases/github-repository-finder.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,24 @@ async function findRepositoryForWorkspaceFolder(
3939
);
4040
}
4141

42+
/**
43+
* Finds the primary remote fetch URL for a repository.
44+
*
45+
* The priority is:
46+
* 1. The remote associated with the current branch
47+
* 2. The remote named "origin"
48+
* 3. The first remote
49+
*
50+
* If none of these are found, undefined is returned.
51+
*
52+
* @param repository The repository to find the remote for.
53+
*/
4254
async function findRemote(repository: Repository): Promise<string | undefined> {
4355
// Try to retrieve the remote 5 times with a 5 second delay between each attempt.
44-
// This is to account for the case where the Git extension is still initializing.
56+
// This is to account for the case where the Git extension has not yet retrieved
57+
// the state for all Git repositories.
58+
// This can happen on Codespaces where the Git extension is initialized before the
59+
// filesystem is ready.
4560
for (let count = 0; count < 5; count++) {
4661
const remoteName = repository.state.HEAD?.upstream?.remote ?? "origin";
4762
const originRemoteUrl = repository.state.remotes.find(
@@ -56,7 +71,7 @@ async function findRemote(repository: Repository): Promise<string | undefined> {
5671
return firstRemoteUrl;
5772
}
5873

59-
// Wait for Git to initialize.
74+
// Wait for 5 seconds before trying again.
6075
await new Promise((resolve) => setTimeout(resolve, 5000));
6176
}
6277

0 commit comments

Comments
 (0)