Skip to content

Commit e28db74

Browse files
zaboyleeamodio
authored andcommitted
Adds add new remote support
1 parent c27681d commit e28db74

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,15 @@
23732373
"light": "images/light/icon-checkout.svg"
23742374
}
23752375
},
2376+
{
2377+
"command": "gitlens.views.addRemote",
2378+
"title": "Add Remote",
2379+
"category": "GitLens",
2380+
"icon": {
2381+
"dark": "images/dark/icon-add.svg",
2382+
"light": "images/light/icon-add.svg"
2383+
}
2384+
},
23762385
{
23772386
"command": "gitlens.views.fetch",
23782387
"title": "Fetch",
@@ -4257,6 +4266,11 @@
42574266
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
42584267
"group": "inline@10"
42594268
},
4269+
{
4270+
"command": "gitlens.views.addRemote",
4271+
"when": "viewItem =~ /gitlens:remotes\\b/",
4272+
"group": "inline@10"
4273+
},
42604274
{
42614275
"command": "gitlens.views.compareWithRemote",
42624276
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)/",

src/git/git.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ export class Git {
471471
return git<string>({ cwd: repoPath }, ...params);
472472
}
473473

474+
static addRemote(repoPath: string, branchName: string, remoteUrl: string) {
475+
return git<string>({ cwd: repoPath },'remote', 'add', branchName, remoteUrl);
476+
}
477+
474478
static async config__get(key: string, repoPath?: string, options: { local?: boolean } = {}) {
475479
const data = await git<string>(
476480
{ cwd: repoPath || emptyStr, errors: GitErrorHandling.Ignore, local: options.local },

src/git/gitService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ export class GitService implements Disposable {
520520
}
521521
}
522522

523+
@gate()
524+
@log()
525+
addRemote(repoPath: string, branchName: string, remoteUrl: string) {
526+
return Git.addRemote(repoPath, branchName, remoteUrl);
527+
}
528+
523529
@gate()
524530
@log()
525531
fetch(repoPath: string, options: { all?: boolean; prune?: boolean; remote?: string } = {}) {

src/views/viewCommands.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class ViewCommands {
114114
commands.registerCommand('gitlens.views.openChangedFileRevisions', this.openChangedFileRevisions, this);
115115
commands.registerCommand('gitlens.views.applyChanges', this.applyChanges, this);
116116
commands.registerCommand('gitlens.views.checkout', this.checkout, this);
117+
commands.registerCommand('gitlens.views.addRemote', this.addRemote, this);
117118

118119
commands.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this);
119120
commands.registerCommand('gitlens.views.stageFile', this.stageFile, this);
@@ -285,6 +286,26 @@ export class ViewCommands {
285286
return Container.git.checkout(node.repoPath, node.ref);
286287
}
287288

289+
private async addRemote(node: RemoteNode) {
290+
const branchName = await window.showInputBox({
291+
prompt: "Please provide a name for the remote branch (Press 'Enter' to confirm or 'Escape' to cancel)",
292+
placeHolder: 'Remote branch name',
293+
value: undefined
294+
});
295+
296+
if( branchName === undefined || branchName.length === 0) return undefined;
297+
298+
const remoteUrl = await window.showInputBox({
299+
prompt: "Please provide a url for the remote branch (Press 'Enter' to confirm or 'Escape' to cancel)",
300+
placeHolder: 'Remote branch url',
301+
value: undefined
302+
});
303+
304+
if (remoteUrl === undefined || remoteUrl.length === 0) return undefined;
305+
306+
return Container.git.addRemote(node.repo.path, branchName, remoteUrl);
307+
}
308+
288309
private closeRepository(node: RepositoryNode) {
289310
if (!(node instanceof RepositoryNode)) return;
290311

0 commit comments

Comments
 (0)