diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 3114cfb..b826749 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -475,19 +475,9 @@ export class LocalGitProvider implements GitProvider, Disposable { } async visibility(repoPath: string): Promise { - const remotes = await this.getRemotes(repoPath); + const remotes = await this.getRemotes(repoPath, { sort: true }); if (remotes.length === 0) return RepositoryVisibility.Local; - const origin = remotes.find(r => r.name === 'origin'); - if (origin != null) { - return this.getRemoteVisibility(origin); - } - - const upstream = remotes.find(r => r.name === 'upstream'); - if (upstream != null) { - return this.getRemoteVisibility(upstream); - } - for await (const result of fastestSettled(remotes.map(r => this.getRemoteVisibility(r)))) { if (result.status !== 'fulfilled') continue; @@ -497,9 +487,12 @@ export class LocalGitProvider implements GitProvider, Disposable { return RepositoryVisibility.Private; } + @debug({ args: { 0: r => r.url } }) private async getRemoteVisibility( remote: GitRemote, ): Promise { + const scope = getLogScope(); + switch (remote.provider?.id) { case 'github': case 'gitlab': @@ -513,11 +506,14 @@ export class LocalGitProvider implements GitProvider, Disposable { // Check if the url returns a 200 status code try { - const response = await fetch(url, { method: 'HEAD', agent: getProxyAgent() }); - if (response.status === 200) { - return RepositoryVisibility.Public; - } - } catch {} + const rsp = await fetch(url, { method: 'HEAD', agent: getProxyAgent() }); + if (rsp.ok) return RepositoryVisibility.Public; + + Logger.debug(scope, `Response=${rsp.status}`); + } catch (ex) { + debugger; + Logger.error(ex, scope); + } return RepositoryVisibility.Private; } default: diff --git a/src/git/models/remote.ts b/src/git/models/remote.ts index a40adbf..d3ae58e 100644 --- a/src/git/models/remote.ts +++ b/src/git/models/remote.ts @@ -46,6 +46,7 @@ export class GitRemote (a.default ? -1 : 1) - (b.default ? -1 : 1) || (a.name === 'origin' ? -1 : 1) - (b.name === 'origin' ? -1 : 1) || + (a.name === 'upstream' ? -1 : 1) - (b.name === 'upstream' ? -1 : 1) || sortCompare(a.name, b.name), ); } diff --git a/src/plus/github/githubGitProvider.ts b/src/plus/github/githubGitProvider.ts index b25d4a3..80387c9 100644 --- a/src/plus/github/githubGitProvider.ts +++ b/src/plus/github/githubGitProvider.ts @@ -83,7 +83,7 @@ import { gate } from '../../system/decorators/gate'; import { debug, getLogScope, log } from '../../system/decorators/log'; import { filterMap, first, last, some } from '../../system/iterable'; import { isAbsolute, isFolderGlob, maybeUri, normalizePath, relative } from '../../system/path'; -import { getSettledValue } from '../../system/promise'; +import { fastestSettled, getSettledValue } from '../../system/promise'; import { serializeWebviewItemContext } from '../../system/webview'; import type { CachedBlame, CachedLog } from '../../trackers/gitDocumentTracker'; import { GitDocumentState } from '../../trackers/gitDocumentTracker'; @@ -217,12 +217,13 @@ export class GitHubGitProvider implements GitProvider, Disposable { } async visibility(repoPath: string): Promise { - const remotes = await this.getRemotes(repoPath); + const remotes = await this.getRemotes(repoPath, { sort: true }); if (remotes.length === 0) return RepositoryVisibility.Local; - const origin = remotes.find(r => r.name === 'origin'); - if (origin != null) { - return this.getRemoteVisibility(origin); + for await (const result of fastestSettled(remotes.map(r => this.getRemoteVisibility(r)))) { + if (result.status !== 'fulfilled') continue; + + if (result.value === RepositoryVisibility.Public) return RepositoryVisibility.Public; } return RepositoryVisibility.Private;