瀏覽代碼

Fixes tracking status remote/provider name

Adds better tooltips for branches
main
Eric Amodio 4 年之前
父節點
當前提交
7ef1352546
共有 3 個檔案被更改,包括 85 行新增63 行删除
  1. +1
    -1
      src/git/models/status.ts
  2. +56
    -44
      src/views/nodes/branchNode.ts
  3. +28
    -18
      src/views/nodes/branchTrackingStatusNode.ts

+ 1
- 1
src/git/models/status.ts 查看文件

@ -209,7 +209,7 @@ export class GitStatus {
}
if (state.ahead) {
status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`;
if (suffix.endsWith(upstream)) {
if (suffix.startsWith(` ${upstream.split('/')[0]}`)) {
status += ' of';
}
}

+ 56
- 44
src/views/nodes/branchNode.ts 查看文件

@ -14,6 +14,7 @@ import {
GitBranch,
GitBranchReference,
GitLog,
GitRemote,
GitRemoteType,
PullRequestState,
} from '../../git/git';
@ -214,7 +215,7 @@ export class BranchNode
this.splatted = false;
const name = this.label;
let tooltip = `${this.branch.getNameWithoutRemote()}${this.current ? ' (current)' : ''}`;
let tooltip = `Branch ${this.branch.getNameWithoutRemote()}${this.current ? ' (current)' : ''}`;
let iconSuffix = '';
let contextValue: string = ContextValues.Branch;
@ -232,54 +233,65 @@ export class BranchNode
}
let description;
if (!this.branch.remote && this.branch.tracking != null) {
let arrows = GlyphChars.Dash;
const remote = await this.branch.getRemote();
if (remote != null) {
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 (!this.branch.remote) {
if (this.branch.tracking != null) {
let arrows = GlyphChars.Dash;
const remote = await this.branch.getRemote();
if (remote != null) {
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;
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 ${this.branch.getTrackingStatus({
empty: `up to date with ${this.branch.tracking}`,
expand: true,
separator: ', ',
suffix: ` ${this.branch.tracking}`,
})}`;
if (this.branch.state.ahead || this.branch.state.behind) {
if (this.branch.state.behind) {
contextValue += '+behind';
iconSuffix = '-red';
}
if (this.branch.state.ahead) {
contextValue += '+ahead';
iconSuffix = this.branch.state.behind ? '-yellow' : '-green';
description = `${this.branch.getTrackingStatus({ suffix: `${GlyphChars.Space} ` })}${arrows}${
GlyphChars.Space
} ${this.branch.tracking}`;
tooltip += ` is ${this.branch.getTrackingStatus({
empty: `up to date with ${this.branch.tracking}${
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
}`,
expand: true,
separator: ', ',
suffix: ` ${this.branch.tracking}${remote?.provider?.name ? ` on ${remote.provider.name}` : ''}`,
})}`;
if (this.branch.state.ahead || this.branch.state.behind) {
if (this.branch.state.behind) {
contextValue += '+behind';
iconSuffix = '-red';
}
if (this.branch.state.ahead) {
contextValue += '+ahead';
iconSuffix = this.branch.state.behind ? '-yellow' : '-green';
}
}
} else {
const providers = GitRemote.getHighlanderProviders(
await Container.git.getRemotes(this.branch.repoPath),
);
const providerName = providers?.length ? providers[0].name : undefined;
tooltip += ` hasn't been published to ${providerName ?? 'a remote'}`;
}
}

+ 28
- 18
src/views/nodes/branchTrackingStatusNode.ts 查看文件

@ -120,9 +120,6 @@ export class BranchTrackingStatusNode extends ViewNode implement
lastFetched = (await repo?.getLastFetched()) ?? 0;
}
const providers = GitRemote.getHighlanderProviders(await Container.git.getRemotes(this.branch.repoPath));
const providerName = providers?.length ? providers[0].name : undefined;
let label;
let description;
let collapsibleState;
@ -130,15 +127,17 @@ export class BranchTrackingStatusNode extends ViewNode implement
let icon;
let tooltip;
switch (this.upstreamType) {
case 'ahead':
label = `Changes to push to ${GitBranch.getRemote(this.status.upstream!)}${
providerName ? ` on ${providerName}` : ''
case 'ahead': {
const remote = await this.branch.getRemote();
label = `Changes to push to ${remote?.name ?? GitBranch.getRemote(this.status.upstream!)}${
remote?.provider?.name ? ` on ${remote?.provider.name}` : ''
}`;
description = Strings.pluralize('commit', this.status.state.ahead);
tooltip = `Branch ${this.branch.name} is ${Strings.pluralize(
'commit',
this.status.state.ahead,
)} ahead of ${this.status.upstream}`;
)} ahead of ${this.status.upstream}${remote?.provider?.name ? ` on ${remote.provider.name}` : ''}`;
// collapsibleState = !this.isReposView
// ? TreeItemCollapsibleState.Expanded
@ -150,16 +149,18 @@ export class BranchTrackingStatusNode extends ViewNode implement
icon = new ThemeIcon('cloud-upload', new ThemeColor('gitlens.viewChangesToPushIconColor'));
break;
}
case 'behind': {
const remote = await this.branch.getRemote();
case 'behind':
label = `Changes to pull from ${GitBranch.getRemote(this.status.upstream!)}${
providerName ? ` on ${providerName}` : ''
label = `Changes to pull from ${remote?.name ?? GitBranch.getRemote(this.status.upstream!)}${
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
}`;
description = Strings.pluralize('commit', this.status.state.behind);
tooltip = `Branch ${this.branch.name} is ${Strings.pluralize(
'commit',
this.status.state.behind,
)} behind ${this.status.upstream}`;
)} behind ${this.status.upstream}${remote?.provider?.name ? ` on ${remote.provider.name}` : ''}`;
collapsibleState = TreeItemCollapsibleState.Collapsed;
contextValue = this.root
@ -168,23 +169,32 @@ export class BranchTrackingStatusNode extends ViewNode implement
icon = new ThemeIcon('cloud-download', new ThemeColor('gitlens.viewChangesToPullIconColor'));
break;
}
case 'same': {
const remote = await this.branch.getRemote();
case 'same':
label = `Up to date with ${GitBranch.getRemote(this.status.upstream!)}${
providerName ? ` on ${providerName}` : ''
label = `Up to date with ${remote?.name ?? GitBranch.getRemote(this.status.upstream!)}${
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
}`;
description = `Last fetched ${Dates.getFormatter(new Date(lastFetched)).fromNow()}`;
tooltip = `Branch ${this.branch.name} is up to date with ${this.status.upstream}`;
tooltip = `Branch ${this.branch.name} is up to date with ${this.status.upstream}${
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
}`;
collapsibleState = TreeItemCollapsibleState.None;
contextValue = this.root ? ContextValues.StatusSameAsUpstream : undefined;
icon = new ThemeIcon('cloud');
break;
}
case 'none': {
label = `Publish ${this.branch.name} to ${providerName ?? 'remote'}`;
tooltip = `Branch ${this.branch.name} hasn't yet been published to ${providerName ?? 'remote'}`;
const providers = GitRemote.getHighlanderProviders(
await Container.git.getRemotes(this.branch.repoPath),
);
const providerName = providers?.length ? providers[0].name : undefined;
label = `Publish ${this.branch.name} to ${providerName ?? 'a remote'}`;
tooltip = `Branch ${this.branch.name} hasn't been published to ${providerName ?? 'a remote'}`;
collapsibleState = TreeItemCollapsibleState.None;
contextValue = this.root ? ContextValues.StatusNoUpstream : undefined;

Loading…
取消
儲存