Procházet zdrojové kódy

Adds better remote visibility checking

main
Eric Amodio před 2 roky
rodič
revize
d6d1243377
3 změnil soubory, kde provedl 19 přidání a 21 odebrání
  1. +12
    -16
      src/env/node/git/localGitProvider.ts
  2. +1
    -0
      src/git/models/remote.ts
  3. +6
    -5
      src/plus/github/githubGitProvider.ts

+ 12
- 16
src/env/node/git/localGitProvider.ts Zobrazit soubor

@ -475,19 +475,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
async visibility(repoPath: string): Promise<RepositoryVisibility> {
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<LocalGitProvider['getRemoteVisibility']>({ args: { 0: r => r.url } })
private async getRemoteVisibility(
remote: GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
): Promise<RepositoryVisibility> {
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:

+ 1
- 0
src/git/models/remote.ts Zobrazit soubor

@ -46,6 +46,7 @@ export class GitRemote
(a, b) =>
(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),
);
}

+ 6
- 5
src/plus/github/githubGitProvider.ts Zobrazit soubor

@ -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<RepositoryVisibility> {
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;

Načítá se…
Zrušit
Uložit