Skip to content

Commit

Permalink
Adds add new remote support
Browse files Browse the repository at this point in the history
  • Loading branch information
zaboyle authored and eamodio committed Aug 6, 2019
1 parent c27681d commit e28db74
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,15 @@
"light": "images/light/icon-checkout.svg"
}
},
{
"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",
Expand Down Expand Up @@ -4257,6 +4266,11 @@
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
"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)/",
Expand Down
4 changes: 4 additions & 0 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ export class Git {
return git<string>({ cwd: repoPath }, ...params);
}

static addRemote(repoPath: string, branchName: string, remoteUrl: string) {
return git<string>({ cwd: repoPath },'remote', 'add', branchName, remoteUrl);
}

static async config__get(key: string, repoPath?: string, options: { local?: boolean } = {}) {
const data = await git<string>(
{ cwd: repoPath || emptyStr, errors: GitErrorHandling.Ignore, local: options.local },
Expand Down
6 changes: 6 additions & 0 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,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 } = {}) {
Expand Down
21 changes: 21 additions & 0 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit e28db74

Please sign in to comment.