@@ -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 */
6568async 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