From da7a95e8c187a7628a20be1354bf2b59069c0878 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 22 May 2019 02:11:04 -0400 Subject: [PATCH] Removes "Comparing" from branch compare node Changes upstream arrows --- src/commands/openBranchInRemote.ts | 2 +- src/git/models/branch.ts | 15 +++++++++++-- src/quickpicks/repoStatusQuickPick.ts | 2 +- src/views/nodes/branchNode.ts | 40 ++++++++++++++++++++++++++++++----- src/views/nodes/compareBranchNode.ts | 7 +++++- src/views/nodes/remoteNode.ts | 34 +++++++++++++++++++---------- src/views/viewCommands.ts | 4 ++-- 7 files changed, 81 insertions(+), 23 deletions(-) diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index cae0df9..6001993 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -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); diff --git a/src/git/models/branch.ts b/src/git/models/branch.ts index 48901c9..ce18916 100644 --- a/src/git/models/branch.ts +++ b/src/git/models/branch.ts @@ -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'; @@ -58,7 +58,18 @@ export class GitBranch { } @memoize() - getRemote(): string | undefined { + async getRemote(): Promise { + 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); diff --git a/src/quickpicks/repoStatusQuickPick.ts b/src/quickpicks/repoStatusQuickPick.ts index c2e4422..a03b970 100644 --- a/src/quickpicks/repoStatusQuickPick.ts +++ b/src/quickpicks/repoStatusQuickPick.ts @@ -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) => { diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 2d713ff..07ff253 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -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'; @@ -104,7 +104,7 @@ export class BranchNode extends ViewRefNode implements Pageabl return this._children; } - getTreeItem(): TreeItem { + async getTreeItem(): Promise { const name = this.label; let tooltip = `${this.branch.getName()}${this.current ? ' (current)' : ''}`; let iconSuffix = ''; @@ -112,9 +112,39 @@ export class BranchNode extends ViewRefNode implements Pageabl 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', diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index cb5051c..381a0a4 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -53,12 +53,16 @@ export class CompareBranchNode extends ViewNode { getTreeItem(): TreeItem { let state: TreeItemCollapsibleState; let label; + let description; if (this._compareWith === undefined) { label = `Compare ${this.branch.name} with `; 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; @@ -71,6 +75,7 @@ export class CompareBranchNode extends ViewNode { 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') diff --git a/src/views/nodes/remoteNode.ts b/src/views/nodes/remoteNode.ts index bc955af..ff92a92 100644 --- a/src/views/nodes/remoteNode.ts +++ b/src/views/nodes/remoteNode.ts @@ -70,28 +70,40 @@ export class RemoteNode extends ViewNode { } 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 diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index bc8e0cf..be8bb9c 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -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); @@ -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) {