Skip to content

Commit 5d3a218

Browse files
committed
Polishes new add remote support
1 parent e28db74 commit 5d3a218

File tree

6 files changed

+63
-45
lines changed

6 files changed

+63
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- 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))
12+
913
### Changed
1014

1115
- Reverses the order of comparisons in the _Compare_ view for consistent comparisons results

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ Add [`"gitlens.insiders": true`](#general-settings- 'Jump to GitLens settings')
922922
A big thanks to the people that have contributed to this project:
923923

924924
- Loris Bettazza ([@Pustur](https://github.com/Pustur)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Pustur)
925+
- Zach Boyle ([@zaboyle](https://github.com/zaboyle)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zaboyle)
925926
- Tony Brix ([@UziTech](https://github.com/UziTech)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=UziTech)
926927
- Amanda Cameron ([@AmandaCameron](https://github.com/AmandaCameron)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=AmandaCameron)
927928
- Brett Cannon ([@brettcannon](https://github.com/brettcannon)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=brettcannon)

package.json

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,21 +2365,21 @@
23652365
}
23662366
},
23672367
{
2368-
"command": "gitlens.views.checkout",
2369-
"title": "Checkout",
2368+
"command": "gitlens.views.addRemote",
2369+
"title": "Add Remote",
23702370
"category": "GitLens",
23712371
"icon": {
2372-
"dark": "images/dark/icon-checkout.svg",
2373-
"light": "images/light/icon-checkout.svg"
2372+
"dark": "images/dark/icon-add.svg",
2373+
"light": "images/light/icon-add.svg"
23742374
}
23752375
},
23762376
{
2377-
"command": "gitlens.views.addRemote",
2378-
"title": "Add Remote",
2377+
"command": "gitlens.views.checkout",
2378+
"title": "Checkout",
23792379
"category": "GitLens",
23802380
"icon": {
2381-
"dark": "images/dark/icon-add.svg",
2382-
"light": "images/light/icon-add.svg"
2381+
"dark": "images/dark/icon-checkout.svg",
2382+
"light": "images/light/icon-checkout.svg"
23832383
}
23842384
},
23852385
{
@@ -3351,6 +3351,10 @@
33513351
"command": "gitlens.pushRepositories",
33523352
"when": "gitlens:hasRemotes && !gitlens:readonly"
33533353
},
3354+
{
3355+
"command": "gitlens.views.addRemote",
3356+
"when": "false"
3357+
},
33543358
{
33553359
"command": "gitlens.views.checkout",
33563360
"when": "false"
@@ -4266,11 +4270,6 @@
42664270
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
42674271
"group": "inline@10"
42684272
},
4269-
{
4270-
"command": "gitlens.views.addRemote",
4271-
"when": "viewItem =~ /gitlens:remotes\\b/",
4272-
"group": "inline@10"
4273-
},
42744273
{
42754274
"command": "gitlens.views.compareWithRemote",
42764275
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)/",
@@ -4641,6 +4640,16 @@
46414640
"when": "viewItem =~ /gitlens:file\\b/",
46424641
"group": "8_gitlens@2"
46434642
},
4643+
{
4644+
"command": "gitlens.views.addRemote",
4645+
"when": "!gitlens:readonly && viewItem =~ /gitlens:remotes\\b/",
4646+
"group": "inline@1"
4647+
},
4648+
{
4649+
"command": "gitlens.views.addRemote",
4650+
"when": "!gitlens:readonly && viewItem =~ /gitlens:remotes\\b/",
4651+
"group": "1_gitlens@1"
4652+
},
46444653
{
46454654
"command": "gitlens.views.fetch",
46464655
"when": "!gitlens:readonly && viewItem =~ /gitlens:remote\\b/",

src/git/git.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,6 @@ 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-
478474
static async config__get(key: string, repoPath?: string, options: { local?: boolean } = {}) {
479475
const data = await git<string>(
480476
{ cwd: repoPath || emptyStr, errors: GitErrorHandling.Ignore, local: options.local },
@@ -865,6 +861,10 @@ export class Git {
865861
return git<string>({ cwd: repoPath }, 'remote', '-v');
866862
}
867863

864+
static remote__add(repoPath: string, name: string, url: string) {
865+
return git<string>({ cwd: repoPath }, 'remote', 'add', name, url);
866+
}
867+
868868
static remote__get_url(repoPath: string, remote: string): Promise<string> {
869869
return git<string>({ cwd: repoPath }, 'remote', 'get-url', remote);
870870
}

src/git/gitService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ export class GitService implements Disposable {
453453
this._onDidChangeRepositories.fire();
454454
}
455455

456+
@log()
457+
addRemote(repoPath: string, name: string, url: string) {
458+
return Git.remote__add(repoPath, name, url);
459+
}
460+
456461
@log()
457462
async applyChangesToWorkingFile(uri: GitUri, ref1?: string, ref2?: string) {
458463
const cc = Logger.getCorrelationContext();
@@ -520,12 +525,6 @@ export class GitService implements Disposable {
520525
}
521526
}
522527

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

src/views/viewCommands.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ export class ViewCommands {
270270
}
271271

272272
const name = await window.showInputBox({
273-
prompt:
274-
"Please provide a name for the local branch (Press 'Enter' to confirm or 'Escape' to cancel)",
273+
prompt: 'Please provide a name for the local branch',
275274
placeHolder: 'Local branch name',
276-
value: branch.getName()
275+
value: branch.getName(),
276+
ignoreFocusOut: true
277277
});
278278
if (name === undefined || name.length === 0) return undefined;
279279

@@ -287,23 +287,26 @@ export class ViewCommands {
287287
}
288288

289289
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
290+
const name = await window.showInputBox({
291+
prompt: 'Please provide a name for the remote',
292+
placeHolder: 'Remote name',
293+
value: undefined,
294+
ignoreFocusOut: true
294295
});
296+
if (name === undefined || name.length === 0) return undefined;
295297

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
298+
const url = await window.showInputBox({
299+
prompt: 'Please provide the repository url for the remote',
300+
placeHolder: 'Remote repository url',
301+
value: undefined,
302+
ignoreFocusOut: true
302303
});
304+
if (url === undefined || url.length === 0) return undefined;
303305

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

306-
return Container.git.addRemote(node.repo.path, branchName, remoteUrl);
309+
return name;
307310
}
308311

309312
private closeRepository(node: RepositoryNode) {
@@ -783,9 +786,10 @@ export class ViewCommands {
783786
}
784787

785788
const name = await window.showInputBox({
786-
prompt: "Please provide a branch name (Press 'Enter' to confirm or 'Escape' to cancel)",
789+
prompt: 'Please provide a branch name',
787790
placeHolder: 'Branch name',
788-
value: value
791+
value: value,
792+
ignoreFocusOut: true
789793
});
790794
if (name === undefined || name.length === 0) return;
791795

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

883887
const name = await window.showInputBox({
884-
prompt: "Please provide a tag name (Press 'Enter' to confirm or 'Escape' to cancel)",
885-
placeHolder: 'Tag name'
888+
prompt: 'Please provide a tag name',
889+
placeHolder: 'Tag name',
890+
ignoreFocusOut: true
886891
});
887892
if (name === undefined || name.length === 0) return;
888893

889894
const message = await window.showInputBox({
890-
prompt:
891-
"Please provide an optional message to annotate the tag (Press 'Enter' to confirm or 'Escape' to cancel)",
892-
placeHolder: 'Tag message'
895+
prompt: 'Please provide an optional message to annotate the tag',
896+
placeHolder: 'Tag message',
897+
ignoreFocusOut: true
893898
});
894899
if (message === undefined) return;
895900

0 commit comments

Comments
 (0)