Explorar el Código

Adds "upstream" info to remotes in quickpicks

main
Eric Amodio hace 1 año
padre
commit
42d526a74b
Se han modificado 4 ficheros con 53 adiciones y 33 borrados
  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 Ver fichero

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

+ 43
- 0
src/git/models/remote.ts Ver fichero

@ -1,5 +1,6 @@
import type { ColorTheme } from 'vscode';
import { Uri, window } from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { sortCompare } from '../../system/string';
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(
container: Container,
remote: GitRemote,

+ 7
- 1
src/quickpicks/items/gitCommands.ts Ver fichero

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

+ 2
- 32
src/views/nodes/remoteNode.ts Ver fichero

@ -3,7 +3,7 @@ import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { GitUri } from '../../git/gitUri';
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 { makeHierarchical } from '../../system/array';
import { log } from '../../system/decorators/log';
@ -83,38 +83,13 @@ export class RemoteNode extends ViewNode {
}
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);
item.id = this.id;
item.description = getRemoteUpstreamDescription(this.remote);
if (this.remote.provider != null) {
const { provider } = this.remote;
item.description = `${arrows}${GlyphChars.Space} ${provider.name} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${provider.displayPath}`;
item.iconPath =
provider.avatarUri != null && this.view.config.avatars
? provider.avatarUri
@ -137,11 +112,6 @@ export class RemoteNode extends ViewNode {
item.tooltip = `${this.remote.name} (${provider.name})\n${provider.displayPath}\n`;
}
} 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.iconPath = new ThemeIcon('cloud');
item.tooltip = `${this.remote.name} (${this.remote.domain})\n${this.remote.path}\n`;

Cargando…
Cancelar
Guardar