Skip to content

Commit

Permalink
Polishes new add remote support
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Aug 6, 2019
1 parent e28db74 commit 5d3a218
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- Adds an _Add Remote_ command to the _Remotes_ node of the _Repositories_ view — closes [#694](https://github.com/eamodio/vscode-gitlens/issues/694) thanks to [PR #802](https://github.com/eamodio/vscode-gitlens/pull/802) by Zach Boyle ([@zaboyle](https://github.com/zaboyle))

### Changed

- Reverses the order of comparisons in the _Compare_ view for consistent comparisons results
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ Add [`"gitlens.insiders": true`](#general-settings- 'Jump to GitLens settings')
A big thanks to the people that have contributed to this project:

- Loris Bettazza ([@Pustur](https://github.com/Pustur)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Pustur)
- Zach Boyle ([@zaboyle](https://github.com/zaboyle)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zaboyle)
- Tony Brix ([@UziTech](https://github.com/UziTech)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=UziTech)
- Amanda Cameron ([@AmandaCameron](https://github.com/AmandaCameron)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=AmandaCameron)
- Brett Cannon ([@brettcannon](https://github.com/brettcannon)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=brettcannon)
Expand Down
35 changes: 22 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2365,21 +2365,21 @@
}
},
{
"command": "gitlens.views.checkout",
"title": "Checkout",
"command": "gitlens.views.addRemote",
"title": "Add Remote",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-checkout.svg",
"light": "images/light/icon-checkout.svg"
"dark": "images/dark/icon-add.svg",
"light": "images/light/icon-add.svg"
}
},
{
"command": "gitlens.views.addRemote",
"title": "Add Remote",
"command": "gitlens.views.checkout",
"title": "Checkout",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-add.svg",
"light": "images/light/icon-add.svg"
"dark": "images/dark/icon-checkout.svg",
"light": "images/light/icon-checkout.svg"
}
},
{
Expand Down Expand Up @@ -3351,6 +3351,10 @@
"command": "gitlens.pushRepositories",
"when": "gitlens:hasRemotes && !gitlens:readonly"
},
{
"command": "gitlens.views.addRemote",
"when": "false"
},
{
"command": "gitlens.views.checkout",
"when": "false"
Expand Down Expand Up @@ -4266,11 +4270,6 @@
"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 Expand Up @@ -4641,6 +4640,16 @@
"when": "viewItem =~ /gitlens:file\\b/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.addRemote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remotes\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.addRemote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remotes\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.fetch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remote\\b/",
Expand Down
8 changes: 4 additions & 4 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,6 @@ 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 Expand Up @@ -865,6 +861,10 @@ export class Git {
return git<string>({ cwd: repoPath }, 'remote', '-v');
}

static remote__add(repoPath: string, name: string, url: string) {
return git<string>({ cwd: repoPath }, 'remote', 'add', name, url);
}

static remote__get_url(repoPath: string, remote: string): Promise<string> {
return git<string>({ cwd: repoPath }, 'remote', 'get-url', remote);
}
Expand Down
11 changes: 5 additions & 6 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ export class GitService implements Disposable {
this._onDidChangeRepositories.fire();
}

@log()
addRemote(repoPath: string, name: string, url: string) {
return Git.remote__add(repoPath, name, url);
}

@log()
async applyChangesToWorkingFile(uri: GitUri, ref1?: string, ref2?: string) {
const cc = Logger.getCorrelationContext();
Expand Down Expand Up @@ -520,12 +525,6 @@ 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
49 changes: 27 additions & 22 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ export class ViewCommands {
}

const name = await window.showInputBox({
prompt:
"Please provide a name for the local branch (Press 'Enter' to confirm or 'Escape' to cancel)",
prompt: 'Please provide a name for the local branch',
placeHolder: 'Local branch name',
value: branch.getName()
value: branch.getName(),
ignoreFocusOut: true
});
if (name === undefined || name.length === 0) return undefined;

Expand All @@ -287,23 +287,26 @@ export class ViewCommands {
}

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
const name = await window.showInputBox({
prompt: 'Please provide a name for the remote',
placeHolder: 'Remote name',
value: undefined,
ignoreFocusOut: true
});
if (name === undefined || name.length === 0) return 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
const url = await window.showInputBox({
prompt: 'Please provide the repository url for the remote',
placeHolder: 'Remote repository url',
value: undefined,
ignoreFocusOut: true
});
if (url === undefined || url.length === 0) return undefined;

if (remoteUrl === undefined || remoteUrl.length === 0) return undefined;
void (await Container.git.addRemote(node.repo.path, name, url));
void (await node.repo.fetch({ remote: name }));

return Container.git.addRemote(node.repo.path, branchName, remoteUrl);
return name;
}

private closeRepository(node: RepositoryNode) {
Expand Down Expand Up @@ -783,9 +786,10 @@ export class ViewCommands {
}

const name = await window.showInputBox({
prompt: "Please provide a branch name (Press 'Enter' to confirm or 'Escape' to cancel)",
prompt: 'Please provide a branch name',
placeHolder: 'Branch name',
value: value
value: value,
ignoreFocusOut: true
});
if (name === undefined || name.length === 0) return;

Expand Down Expand Up @@ -881,15 +885,16 @@ export class ViewCommands {
if (!(node instanceof ViewRefNode)) return;

const name = await window.showInputBox({
prompt: "Please provide a tag name (Press 'Enter' to confirm or 'Escape' to cancel)",
placeHolder: 'Tag name'
prompt: 'Please provide a tag name',
placeHolder: 'Tag name',
ignoreFocusOut: true
});
if (name === undefined || name.length === 0) return;

const message = await window.showInputBox({
prompt:
"Please provide an optional message to annotate the tag (Press 'Enter' to confirm or 'Escape' to cancel)",
placeHolder: 'Tag message'
prompt: 'Please provide an optional message to annotate the tag',
placeHolder: 'Tag message',
ignoreFocusOut: true
});
if (message === undefined) return;

Expand Down

0 comments on commit 5d3a218

Please sign in to comment.