diff --git a/package.json b/package.json index d3c523c..9d6903d 100644 --- a/package.json +++ b/package.json @@ -6359,6 +6359,11 @@ "group": "5_gitlens@0" }, { + "command": "gitlens.views.addRemote", + "when": "!gitlens:readonly && view =~ /gitlens\\.views\\.remotes/", + "group": "navigation@1" + }, + { "command": "gitlens.views.remotes.setLayoutToList", "when": "view =~ /gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.branches.layout == tree", "group": "navigation@50" diff --git a/src/commands/gitCommands.actions.ts b/src/commands/gitCommands.actions.ts index 3f1e713..290933f 100644 --- a/src/commands/gitCommands.actions.ts +++ b/src/commands/gitCommands.actions.ts @@ -27,6 +27,7 @@ import { Repository, } from '../git/git'; import { GitUri } from '../git/gitUri'; +import { RepositoryPicker } from '../quickpicks'; import { ResetGitCommandArgs } from './git/reset'; export async function executeGitCommand(args: GitCommandsCommandArgs): Promise { @@ -758,7 +759,17 @@ export namespace GitActions { } export namespace Remote { - export async function add(repo: string | Repository) { + export async function add(repo?: string | Repository) { + if (repo == null) { + repo = Container.git.getHighlanderRepoPath(); + + if (repo == null) { + const pick = await RepositoryPicker.show(undefined, 'Choose a repository to add a remote to'); + repo = pick?.item; + if (repo == null) return undefined; + } + } + const name = await window.showInputBox({ prompt: 'Please provide a name for the remote', placeHolder: 'Remote name', diff --git a/src/views/nodes/remotesNode.ts b/src/views/nodes/remotesNode.ts index c5640de..5219a20 100644 --- a/src/views/nodes/remotesNode.ts +++ b/src/views/nodes/remotesNode.ts @@ -26,6 +26,10 @@ export class RemotesNode extends ViewNode { return RemotesNode.getId(this.repo.path); } + get repoPath(): string { + return this.repo.path; + } + async getChildren(): Promise { if (this._children == null) { const remotes = await this.repo.getRemotes({ sort: true }); diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 1598c10..d9d568c 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -33,6 +33,7 @@ import { PagerNode, PullRequestNode, RemoteNode, + RemotesNode, RepositoryFolderNode, RepositoryNode, ResultsFileNode, @@ -220,10 +221,8 @@ export class ViewCommands { } @debug() - private addRemote(node: RemoteNode) { - if (!(node instanceof RemoteNode)) return Promise.resolve(); - - return GitActions.Remote.add(node.repo); + private addRemote(node?: RemotesNode) { + return GitActions.Remote.add(node?.repoPath); } @debug()