Skip to content

Commit

Permalink
Closes #504 - adds set/unset as default to remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 2, 2019
1 parent 2b0673b commit d063337
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added

- Adds favoriting of repositories and branches in the _Repositories_ view to allow for better (user-customized) sorting
- Adds _Set as Default_ and _Unset as Default_ commands to remotes in the _Repositories_ view to specify the default remote selection when using the _Open \* in Remote_ commands — closes [#504](https://github.com/eamodio/vscode-gitlens/issues/504)
- Adds the ability to turn on file annotations (blame, heatmap, and recent changes) via user-defined modes — closes [#542](https://github.com/eamodio/vscode-gitlens/issues/542)

## [9.2.4] - 2018-12-26
Expand Down
40 changes: 34 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,16 @@
"light": "images/light/icon-push-force.svg"
}
},
{
"command": "gitlens.views.setAsDefault",
"title": "Set as Default",
"category": "GitLens"
},
{
"command": "gitlens.views.unsetAsDefault",
"title": "Unset as Default",
"category": "GitLens"
},
{
"command": "gitlens.views.stageFile",
"title": "Stage Changes",
Expand Down Expand Up @@ -3033,6 +3043,14 @@
"command": "gitlens.views.pushWithForce",
"when": "false"
},
{
"command": "gitlens.views.setAsDefault",
"when": "false"
},
{
"command": "gitlens.views.unsetAsDefault",
"when": "false"
},
{
"command": "gitlens.views.stageFile",
"when": "false"
Expand Down Expand Up @@ -4163,32 +4181,42 @@
},
{
"command": "gitlens.views.fetch",
"when": "!gitlens:readonly && viewItem == gitlens:remote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remote\\b/",
"group": "inline@97"
},
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem == gitlens:remote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "inline@98"
},
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem == gitlens:remote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem == gitlens:remote",
"when": "viewItem =~ /gitlens:remote\\b/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.fetch",
"when": "!gitlens:readonly && viewItem == gitlens:remote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remote\\b/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.views.setAsDefault",
"when": "viewItem =~ /gitlens:remote\\b(?!.*?\\+default\\b.*?)/",
"group": "3_gitlens@1"
},
{
"command": "gitlens.views.unsetAsDefault",
"when": "viewItem =~ /gitlens:remote\\b.*?\\+default\\b.*?/",
"group": "3_gitlens@1"
},
{
"command": "gitlens.views.terminalRemoveRemote",
"when": "!gitlens:readonly && viewItem == gitlens:remote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:remote\\b/",
"group": "8_gitlens@1"
},
{
Expand Down
12 changes: 10 additions & 2 deletions src/commands/openInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ export class OpenInRemoteCommand extends ActiveEditorCommand {
}

try {
if (args.remotes.length === 1) {
let remote: GitRemote | undefined;
if (args.remotes.length > 1) {
remote = args.remotes.find(r => r.default);
}
else if (args.remotes.length === 1) {
remote = args.remotes[0];
}

if (remote != null) {
this.ensureRemoteBranchName(args);
const command = new OpenRemoteCommandQuickPickItem(args.remotes[0], args.resource, args.clipboard);
const command = new OpenRemoteCommandQuickPickItem(remote, args.resource, args.clipboard);
return await command.execute();
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface StarredRepositories {
}

export enum WorkspaceState {
DefaultRemote = 'gitlens:remote:default',
StarredBranches = 'gitlens:starred:branches',
StarredRepositories = 'gitlens:starred:repositories',
ViewsCompareKeepResults = 'gitlens:views:compare:keepResults',
Expand Down
12 changes: 12 additions & 0 deletions src/git/models/remote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { RemoteProvider } from '../remotes/factory';

export enum GitRemoteType {
Expand All @@ -9,11 +11,21 @@ export enum GitRemoteType {
export class GitRemote {
constructor(
public readonly repoPath: string,
public readonly id: string,
public readonly name: string,
public readonly scheme: string,
public readonly domain: string,
public readonly path: string,
public readonly provider: RemoteProvider | undefined,
public readonly types: { type: GitRemoteType; url: string }[]
) {}

get default() {
const defaultRemote = Container.context.workspaceState.get<string>(WorkspaceState.DefaultRemote);
return this.id === defaultRemote;
}

setAsDefault(state: boolean = true) {
return Container.context.workspaceState.update(WorkspaceState.DefaultRemote, state ? this.id : undefined);
}
}
1 change: 1 addition & 0 deletions src/git/parsers/remoteParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class GitRemoteParser {
if (remote === undefined) {
remote = new GitRemote(
repoPath,
uniqueness,
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
(' ' + match[1]).substr(1),
scheme,
Expand Down
15 changes: 12 additions & 3 deletions src/quickpicks/remotesQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
break;
}

const remote = remotes[0];
if (remotes.length === 1) {
let remote: GitRemote | undefined;
if (remotes.length > 1) {
remote = remotes.find(r => r.default);
}
else if (remotes.length === 1) {
remote = remotes[0];
}

if (remote != null) {
super(
{
label: `$(link-external) Open ${name} on ${remote.provider!.name}`,
Expand All @@ -125,7 +132,9 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
return;
}

const provider = remotes.every(r => r.provider !== undefined && r.provider.name === remote.provider!.name)
remote = remotes[0];
// Use the real provider name if there is only 1 provider
const provider = remotes.every(r => r.provider !== undefined && r.provider.name === remote!.provider!.name)
? remote.provider!.name
: 'Remote';

Expand Down
22 changes: 18 additions & 4 deletions src/views/nodes/remoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ export class RemoteNode extends ViewNode<RepositoriesView> {
separator = GlyphChars.Dash;
}

const item = new TreeItem(this.remote.name, TreeItemCollapsibleState.Collapsed);
const item = new TreeItem(
`${this.remote.default ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${this.remote.name}`,
TreeItemCollapsibleState.Collapsed
);
item.description = `${separator}${GlyphChars.Space} ${
this.remote.provider !== undefined ? this.remote.provider.name : this.remote.domain
} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${this.remote.path}`;
item.contextValue = ResourceType.Remote;
item.id = this.id;
item.tooltip = `${this.remote.name}
${this.remote.path} (${this.remote.provider !== undefined ? this.remote.provider.name : this.remote.domain})`;
if (this.remote.default) {
item.contextValue += '+default';
}

if (this.remote.provider !== undefined) {
item.iconPath = {
Expand All @@ -106,11 +109,22 @@ ${this.remote.path} (${this.remote.provider !== undefined ? this.remote.provider
};
}

item.id = this.id;
item.tooltip = `${this.remote.name}\n${this.remote.path} (${
this.remote.provider !== undefined ? this.remote.provider.name : this.remote.domain
})`;

return item;
}

@log()
fetch(options: { progress?: boolean } = {}) {
return this.repo.fetch({ ...options, remote: this.remote.name });
}

@log()
async setAsDefault(state: boolean = true) {
void (await this.remote.setAsDefault(state));
void this.parent!.triggerChange();
}
}
13 changes: 13 additions & 0 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export class ViewCommands implements Disposable {
commands.registerCommand('gitlens.views.pushWithForce', n => this.push(n, true), this);
commands.registerCommand('gitlens.views.closeRepository', this.closeRepository, this);

commands.registerCommand('gitlens.views.setAsDefault', this.setAsDefault, this);
commands.registerCommand('gitlens.views.unsetAsDefault', this.unsetAsDefault, this);

commands.registerCommand('gitlens.views.star', this.star, this);
commands.registerCommand('gitlens.views.unstar', this.unstar, this);

Expand Down Expand Up @@ -451,6 +454,16 @@ export class ViewCommands implements Disposable {
} as OpenFileInRemoteCommandArgs);
}

private setAsDefault(node: RemoteNode) {
if (node instanceof RemoteNode) return node.setAsDefault();
return;
}

private unsetAsDefault(node: RemoteNode) {
if (node instanceof RemoteNode) return node.setAsDefault(false);
return;
}

private async stageFile(node: CommitFileNode | StatusFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;

Expand Down

0 comments on commit d063337

Please sign in to comment.