From e28db743ece663626bef7fbf3b1e8c69243d738a Mon Sep 17 00:00:00 2001 From: zboyle Date: Sat, 27 Jul 2019 00:51:33 -0400 Subject: [PATCH] Adds add new remote support --- package.json | 14 ++++++++++++++ src/git/git.ts | 4 ++++ src/git/gitService.ts | 6 ++++++ src/views/viewCommands.ts | 21 +++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/package.json b/package.json index 34237f1..019ddf5 100644 --- a/package.json +++ b/package.json @@ -2374,6 +2374,15 @@ } }, { + "command": "gitlens.views.addRemote", + "title": "Add Remote", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-add.svg", + "light": "images/light/icon-add.svg" + } + }, + { "command": "gitlens.views.fetch", "title": "Fetch", "category": "GitLens", @@ -4258,6 +4267,11 @@ "group": "inline@10" }, { + "command": "gitlens.views.addRemote", + "when": "viewItem =~ /gitlens:remotes\\b/", + "group": "inline@10" + }, + { "command": "gitlens.views.compareWithRemote", "when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)/", "group": "inline@96" diff --git a/src/git/git.ts b/src/git/git.ts index c56716e..07f1311 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -471,6 +471,10 @@ export class Git { return git({ cwd: repoPath }, ...params); } + static addRemote(repoPath: string, branchName: string, remoteUrl: string) { + return git({ cwd: repoPath },'remote', 'add', branchName, remoteUrl); + } + static async config__get(key: string, repoPath?: string, options: { local?: boolean } = {}) { const data = await git( { cwd: repoPath || emptyStr, errors: GitErrorHandling.Ignore, local: options.local }, diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 6402991..4568158 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -522,6 +522,12 @@ export class GitService implements Disposable { @gate() @log() + addRemote(repoPath: string, branchName: string, remoteUrl: string) { + return Git.addRemote(repoPath, branchName, remoteUrl); + } + + @gate() + @log() fetch(repoPath: string, options: { all?: boolean; prune?: boolean; remote?: string } = {}) { return Git.fetch(repoPath, options); } diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 9405740..219cdff 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -114,6 +114,7 @@ export class ViewCommands { commands.registerCommand('gitlens.views.openChangedFileRevisions', this.openChangedFileRevisions, this); commands.registerCommand('gitlens.views.applyChanges', this.applyChanges, this); commands.registerCommand('gitlens.views.checkout', this.checkout, this); + commands.registerCommand('gitlens.views.addRemote', this.addRemote, this); commands.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this); commands.registerCommand('gitlens.views.stageFile', this.stageFile, this); @@ -285,6 +286,26 @@ export class ViewCommands { return Container.git.checkout(node.repoPath, node.ref); } + private async addRemote(node: RemoteNode) { + const branchName = await window.showInputBox({ + prompt: "Please provide a name for the remote branch (Press 'Enter' to confirm or 'Escape' to cancel)", + placeHolder: 'Remote branch name', + value: undefined + }); + + if( branchName === undefined || branchName.length === 0) return undefined; + + const remoteUrl = await window.showInputBox({ + prompt: "Please provide a url for the remote branch (Press 'Enter' to confirm or 'Escape' to cancel)", + placeHolder: 'Remote branch url', + value: undefined + }); + + if (remoteUrl === undefined || remoteUrl.length === 0) return undefined; + + return Container.git.addRemote(node.repo.path, branchName, remoteUrl); + } + private closeRepository(node: RepositoryNode) { if (!(node instanceof RepositoryNode)) return;