Skip to content

Commit

Permalink
Removes "Comparing" from branch compare node
Browse files Browse the repository at this point in the history
Changes upstream arrows
  • Loading branch information
eamodio committed May 22, 2019
1 parent 4f12def commit da7a95e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/commands/openBranchInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
if (isCommandViewContextWithBranch(context)) {
args = { ...args };
args.branch = context.node.branch.name;
args.remote = context.node.branch.getRemote();
args.remote = context.node.branch.getRemoteName();
}

return this.execute(context.editor, context.uri, args);
Expand Down
15 changes: 13 additions & 2 deletions src/git/models/branch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { StarredBranches, WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { Git } from '../git';
import { Git, GitRemote } from '../git';
import { GitStatus } from './status';
import { memoize } from '../../system';

Expand Down Expand Up @@ -58,7 +58,18 @@ export class GitBranch {
}

@memoize()
getRemote(): string | undefined {
async getRemote(): Promise<GitRemote | undefined> {
const remoteName = this.getRemoteName();
if (remoteName === undefined) return undefined;

const remotes = await Container.git.getRemotes(this.repoPath);
if (remotes.length === 0) return undefined;

return remotes.find(r => r.name === remoteName);
}

@memoize()
getRemoteName(): string | undefined {
if (this.remote) return GitBranch.getRemote(this.name);
if (this.tracking !== undefined) return GitBranch.getRemote(this.tracking);

Expand Down
2 changes: 1 addition & 1 deletion src/quickpicks/repoStatusQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class RepoStatusQuickPick {
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `status of ${status.branch}${
status.upstream ? ` ${Strings.pad(GlyphChars.ArrowLeftRightLong, 1, 1)} ${status.upstream}` : ''
status.upstream ? ` ${Strings.pad(GlyphChars.ArrowsRightLeft, 1, 1)} ${status.upstream}` : ''
}`,
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Expand Down
40 changes: 35 additions & 5 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitBranch, GitUri } from '../../git/gitService';
import { GitBranch, GitRemoteType, GitUri } from '../../git/gitService';
import { debug, gate, Iterables, log } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
Expand Down Expand Up @@ -104,17 +104,47 @@ export class BranchNode extends ViewRefNode<RepositoriesView> implements Pageabl
return this._children;
}

getTreeItem(): TreeItem {
async getTreeItem(): Promise<TreeItem> {
const name = this.label;
let tooltip = `${this.branch.getName()}${this.current ? ' (current)' : ''}`;
let iconSuffix = '';

let description;
if (!this.branch.remote && this.branch.tracking !== undefined) {
if (this.view.config.showTrackingBranch) {
description = `${this.branch.getTrackingStatus({ suffix: `${GlyphChars.Space} ` })}${
GlyphChars.ArrowLeftRightLong
}${GlyphChars.Space} ${this.branch.tracking}`;
let arrows = GlyphChars.Dash;

const remote = await this.branch.getRemote();
if (remote !== undefined) {
let left;
let right;
for (const { type } of remote.types) {
if (type === GitRemoteType.Fetch) {
left = true;

if (right) break;
}
else if (type === GitRemoteType.Push) {
right = true;

if (left) break;
}
}

if (left && right) {
arrows = GlyphChars.ArrowsRightLeft;
}
else if (right) {
arrows = GlyphChars.ArrowRight;
}
else if (left) {
arrows = GlyphChars.ArrowLeft;
}
}

description = `${this.branch.getTrackingStatus({ suffix: `${GlyphChars.Space} ` })}${arrows}${
GlyphChars.Space
} ${this.branch.tracking}`;
}
tooltip += ` is tracking ${this.branch.tracking}\n${this.branch.getTrackingStatus({
empty: 'up-to-date',
Expand Down
7 changes: 6 additions & 1 deletion src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {
getTreeItem(): TreeItem {
let state: TreeItemCollapsibleState;
let label;
let description;
if (this._compareWith === undefined) {
label = `Compare ${this.branch.name} with <branch, tag, or ref>`;
state = TreeItemCollapsibleState.None;
}
else {
label = `Comparing ${this.branch.name} to ${GitService.shortenSha(this._compareWith, {
label = `${this.branch.name}`;
description = `${GlyphChars.ArrowLeftRightLong}${
GlyphChars.Space
} ${GitService.shortenSha(this._compareWith, {
working: 'Working Tree'
})}`;
state = TreeItemCollapsibleState.Collapsed;
Expand All @@ -71,6 +75,7 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {
arguments: [() => this.compareWith()]
};
item.contextValue = ResourceType.CompareBranch;
item.description = description;
item.iconPath = {
dark: Container.context.asAbsolutePath('images/dark/icon-compare-refs.svg'),
light: Container.context.asAbsolutePath('images/light/icon-compare-refs.svg')
Expand Down
34 changes: 23 additions & 11 deletions src/views/nodes/remoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,40 @@ export class RemoteNode extends ViewNode<RepositoriesView> {
}

getTreeItem(): TreeItem {
const fetch = this.remote.types.find(rt => rt.type === GitRemoteType.Fetch);
const push = this.remote.types.find(rt => rt.type === GitRemoteType.Push);
let arrows;
let left;
let right;
for (const { type } of this.remote.types) {
if (type === GitRemoteType.Fetch) {
left = true;

if (right) break;
}
else if (type === GitRemoteType.Push) {
right = true;

if (left) break;
}
}

let separator;
if (fetch && push) {
separator = GlyphChars.ArrowLeftRightLong;
if (left && right) {
arrows = GlyphChars.ArrowsRightLeft;
}
else if (fetch) {
separator = GlyphChars.ArrowLeft;
else if (right) {
arrows = GlyphChars.ArrowRight;
}
else if (push) {
separator = GlyphChars.ArrowRight;
else if (left) {
arrows = GlyphChars.ArrowLeft;
}
else {
separator = GlyphChars.Dash;
arrows = GlyphChars.Dash;
}

const item = new TreeItem(
`${this.remote.default ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${this.remote.name}`,
TreeItemCollapsibleState.Collapsed
);
item.description = `${separator}${GlyphChars.Space} ${
item.description = `${arrows}${GlyphChars.Space} ${
this.remote.provider !== undefined ? this.remote.provider.name : this.remote.domain
} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${
this.remote.provider !== undefined ? this.remote.provider.displayPath : this.remote.path
Expand Down
4 changes: 2 additions & 2 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export class ViewCommands implements Disposable {
if (!(node instanceof BranchNode)) return;

if (node.branch.remote) {
this.sendTerminalCommand('push', `${node.branch.getRemote()} :${node.branch.getName()}`, node.repoPath);
this.sendTerminalCommand('push', `${node.branch.getRemoteName()} :${node.branch.getName()}`, node.repoPath);
}
else {
this.sendTerminalCommand('branch', `-d ${node.ref}`, node.repoPath);
Expand Down Expand Up @@ -679,7 +679,7 @@ export class ViewCommands implements Disposable {
const branch = node.branch || (await Container.git.getBranch(node.repoPath));
if (branch === undefined) return;

this.sendTerminalCommand('push', `${branch.getRemote()} ${node.ref}:${branch.getName()}`, node.repoPath);
this.sendTerminalCommand('push', `${branch.getRemoteName()} ${node.ref}:${branch.getName()}`, node.repoPath);
}

terminalRebaseCommit(node: CommitNode) {
Expand Down

0 comments on commit da7a95e

Please sign in to comment.