Skip to content

Commit 779faa3

Browse files
committed
Improve heuristic and comments
1 parent f23bc81 commit 779faa3

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ async function findRepositoryForWorkspaceFolder(
6060
*
6161
* If none of these are found, undefined is returned.
6262
*
63+
* This is just a heuristic. We may not find the correct remote in all cases,
64+
* for example when the user has defined an alias in their SSH or Git config.
65+
*
6366
* @param repository The repository to find the remote for.
6467
*/
6568
async function findRemote(repository: Repository): Promise<string | undefined> {
@@ -70,13 +73,25 @@ async function findRemote(repository: Repository): Promise<string | undefined> {
7073
// filesystem is ready.
7174
for (let count = 0; count < 5; count++) {
7275
const remoteName = repository.state.HEAD?.upstream?.remote ?? "origin";
73-
const originRemoteUrl = repository.state.remotes.find(
76+
const upstreamRemoteUrl = repository.state.remotes.find(
7477
(remote) => remote.name === remoteName,
7578
)?.fetchUrl;
76-
if (originRemoteUrl) {
77-
return originRemoteUrl;
79+
if (upstreamRemoteUrl) {
80+
return upstreamRemoteUrl;
81+
}
82+
83+
if (remoteName !== "origin") {
84+
const originRemoteUrl = repository.state.remotes.find(
85+
(remote) => remote.name === "origin",
86+
)?.fetchUrl;
87+
88+
if (originRemoteUrl) {
89+
return originRemoteUrl;
90+
}
7891
}
7992

93+
// Maybe they have a different remote that is not named origin and is not the
94+
// upstream of the current branch. If so, just select the first one.
8095
const firstRemoteUrl = repository.state.remotes[0]?.fetchUrl;
8196
if (firstRemoteUrl) {
8297
return firstRemoteUrl;

0 commit comments

Comments
 (0)