Browse Source

Adds "upstream" info to remotes in quickpicks

main
Eric Amodio 1 year ago
parent
commit
42d526a74b
4 changed files with 53 additions and 33 deletions
  1. +1
    -0
      src/commands/quickCommand.steps.ts
  2. +43
    -0
      src/git/models/remote.ts
  3. +7
    -1
      src/quickpicks/items/gitCommands.ts
  4. +2
    -32
      src/views/nodes/remoteNode.ts

+ 1
- 0
src/commands/quickCommand.steps.ts View File

@ -150,6 +150,7 @@ export async function getRemotes(
(typeof options.picked === 'string' ? r.name === options.picked : options.picked.includes(r.name)), (typeof options.picked === 'string' ? r.name === options.picked : options.picked.includes(r.name)),
{ {
buttons: options?.buttons, buttons: options?.buttons,
upstream: true,
}, },
), ),
); );

+ 43
- 0
src/git/models/remote.ts View File

@ -1,5 +1,6 @@
import type { ColorTheme } from 'vscode'; import type { ColorTheme } from 'vscode';
import { Uri, window } from 'vscode'; import { Uri, window } from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { sortCompare } from '../../system/string'; import { sortCompare } from '../../system/string';
import { isLightTheme } from '../../system/utils'; import { isLightTheme } from '../../system/utils';
@ -92,6 +93,48 @@ export class GitRemote
} }
} }
export function getRemoteArrowsGlyph(remote: GitRemote): GlyphChars {
let arrows;
let left;
let right;
for (const { type } of remote.urls) {
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;
} else {
arrows = GlyphChars.Dash;
}
return arrows;
}
export function getRemoteUpstreamDescription(remote: GitRemote): string {
const arrows = getRemoteArrowsGlyph(remote);
const { provider } = remote;
if (provider != null) {
return `${arrows}${GlyphChars.Space} ${provider.name} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${provider.displayPath}`;
}
return `${arrows}${GlyphChars.Space} ${
remote.domain ? `${remote.domain} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ` : ''
}${remote.path}`;
}
export function getRemoteIconUri( export function getRemoteIconUri(
container: Container, container: Container,
remote: GitRemote, remote: GitRemote,

+ 7
- 1
src/quickpicks/items/gitCommands.ts View File

@ -10,7 +10,7 @@ import { isStash } from '../../git/models/commit';
import type { GitContributor } from '../../git/models/contributor'; import type { GitContributor } from '../../git/models/contributor';
import { GitReference, GitRevision } from '../../git/models/reference'; import { GitReference, GitRevision } from '../../git/models/reference';
import type { GitRemote } from '../../git/models/remote'; import type { GitRemote } from '../../git/models/remote';
import { GitRemoteType } from '../../git/models/remote';
import { getRemoteUpstreamDescription, GitRemoteType } from '../../git/models/remote';
import type { Repository } from '../../git/models/repository'; import type { Repository } from '../../git/models/repository';
import type { GitStatus } from '../../git/models/status'; import type { GitStatus } from '../../git/models/status';
import type { GitTag } from '../../git/models/tag'; import type { GitTag } from '../../git/models/tag';
@ -321,6 +321,7 @@ export function createRemoteQuickPickItem(
buttons?: QuickInputButton[]; buttons?: QuickInputButton[];
checked?: boolean; checked?: boolean;
type?: boolean; type?: boolean;
upstream?: boolean;
}, },
) { ) {
let description = ''; let description = '';
@ -328,6 +329,11 @@ export function createRemoteQuickPickItem(
description = 'remote'; description = 'remote';
} }
if (options?.upstream) {
const upstream = getRemoteUpstreamDescription(remote);
description = description ? `${description}${pad(GlyphChars.Dot, 2, 2)}${upstream}` : upstream;
}
const item: RemoteQuickPickItem = { const item: RemoteQuickPickItem = {
label: `$(cloud)${GlyphChars.Space}${remote.name}${options?.checked ? pad('$(check)', 2) : ''}`, label: `$(cloud)${GlyphChars.Space}${remote.name}${options?.checked ? pad('$(check)', 2) : ''}`,
description: description, description: description,

+ 2
- 32
src/views/nodes/remoteNode.ts View File

@ -3,7 +3,7 @@ import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import type { GitRemote } from '../../git/models/remote'; import type { GitRemote } from '../../git/models/remote';
import { GitRemoteType } from '../../git/models/remote';
import { getRemoteUpstreamDescription } from '../../git/models/remote';
import type { Repository } from '../../git/models/repository'; import type { Repository } from '../../git/models/repository';
import { makeHierarchical } from '../../system/array'; import { makeHierarchical } from '../../system/array';
import { log } from '../../system/decorators/log'; import { log } from '../../system/decorators/log';
@ -83,38 +83,13 @@ export class RemoteNode extends ViewNode {
} }
async getTreeItem(): Promise<TreeItem> { async getTreeItem(): Promise<TreeItem> {
let arrows;
let left;
let right;
for (const { type } of this.remote.urls) {
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;
} else {
arrows = GlyphChars.Dash;
}
const item = new TreeItem(this.remote.name, TreeItemCollapsibleState.Collapsed); const item = new TreeItem(this.remote.name, TreeItemCollapsibleState.Collapsed);
item.id = this.id; item.id = this.id;
item.description = getRemoteUpstreamDescription(this.remote);
if (this.remote.provider != null) { if (this.remote.provider != null) {
const { provider } = this.remote; const { provider } = this.remote;
item.description = `${arrows}${GlyphChars.Space} ${provider.name} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${provider.displayPath}`;
item.iconPath = item.iconPath =
provider.avatarUri != null && this.view.config.avatars provider.avatarUri != null && this.view.config.avatars
? provider.avatarUri ? provider.avatarUri
@ -137,11 +112,6 @@ export class RemoteNode extends ViewNode {
item.tooltip = `${this.remote.name} (${provider.name})\n${provider.displayPath}\n`; item.tooltip = `${this.remote.name} (${provider.name})\n${provider.displayPath}\n`;
} }
} else { } else {
item.description = `${arrows}${GlyphChars.Space} ${
this.remote.domain
? `${this.remote.domain} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} `
: ''
}${this.remote.path}`;
item.contextValue = ContextValues.Remote; item.contextValue = ContextValues.Remote;
item.iconPath = new ThemeIcon('cloud'); item.iconPath = new ThemeIcon('cloud');
item.tooltip = `${this.remote.name} (${this.remote.domain})\n${this.remote.path}\n`; item.tooltip = `${this.remote.name} (${this.remote.domain})\n${this.remote.path}\n`;

Loading…
Cancel
Save