diff --git a/src/commands/remoteProviders.ts b/src/commands/remoteProviders.ts index 7b0cfe8..6dc617b 100644 --- a/src/commands/remoteProviders.ts +++ b/src/commands/remoteProviders.ts @@ -39,12 +39,17 @@ export class ConnectRemoteProviderCommand extends Command { } async execute(args?: ConnectRemoteProviderCommandArgs): Promise { - if (args?.repoPath == null || args?.remote == null) return undefined; + if (args?.repoPath == null || args?.remote == null) return false; - const remote = (await Container.git.getRemotes(args.repoPath)).find(r => args.remote); - if (!remote?.provider?.hasApi()) return undefined; + const remotes = await Container.git.getRemotes(args.repoPath); + const remote = remotes.find(r => args.remote); + if (!remote?.provider?.hasApi()) return false; - return remote.provider.connect(); + const connected = await remote.provider.connect(); + if (connected && !remotes.some(r => r.default)) { + await remote.setAsDefault(true); + } + return connected; } } diff --git a/src/git/remotes/github.ts b/src/git/remotes/github.ts index 787578b..939406f 100644 --- a/src/git/remotes/github.ts +++ b/src/git/remotes/github.ts @@ -101,9 +101,10 @@ export class GitHubRemote extends RemoteProviderWithApi<{ token: string }> { disposable?.dispose(); } - if (token == null || token.length === 0) return; + if (token == null || token.length === 0) return false; - this.saveCredentials({ token: token }); + await this.saveCredentials({ token: token }); + return true; } protected getUrlForBranches(): string { diff --git a/src/git/remotes/provider.ts b/src/git/remotes/provider.ts index 937b4b3..1337f31 100644 --- a/src/git/remotes/provider.ts +++ b/src/git/remotes/provider.ts @@ -223,7 +223,7 @@ export abstract class RemoteProviderWithApi extends abstract get apiBaseUrl(): string; - abstract async connect(): Promise; + abstract async connect(): Promise; disconnect(): Promise { this._prsByCommit.clear();