Skip to content

Commit

Permalink
Aligns repo tooltip with commits view
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 21, 2020
1 parent 016d1ee commit fd9f827
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/git/models/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitFile, GitFileStatus } from './file';
import { GitUri } from '../gitUri';
import { GitCommitType, GitLogCommit, GitRevision } from './models';
import { GitCommitType, GitLogCommit, GitRemote, GitRevision } from './models';
import { memoize, Strings } from '../../system';

export interface ComputedWorkingTreeGitStatus {
Expand Down Expand Up @@ -184,6 +184,17 @@ export class GitStatus {
return `${prefix}${status}${suffix}`;
}

@memoize()
async getRemote(): Promise<GitRemote | undefined> {
if (this.upstream == null) return undefined;

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

const remoteName = GitBranch.getRemote(this.upstream);
return remotes.find(r => r.name === remoteName);
}

getUpstreamStatus(options: {
empty?: string;
expand?: boolean;
Expand Down
23 changes: 17 additions & 6 deletions src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import {
GitBranch,
GitRemote,
GitRevision,
GitStatus,
Repository,
Expand Down Expand Up @@ -137,8 +138,8 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
}

const status = await this._status;
if (status !== undefined) {
tooltip += `\n\nCurrent branch is ${status.branch}`;
if (status != null) {
tooltip += `\n\nBranch ${status.branch}`;

if (status.files.length !== 0 && this.includeWorkingTree) {
workingStatus = status.getFormattedDiffStatus({
Expand All @@ -153,12 +154,22 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {

description = `${status.branch}${upstreamStatus}${workingStatus}`;

let providerName;
if (status.upstream != null) {
const providers = GitRemote.getHighlanderProviders(await Container.git.getRemotes(status.repoPath));
providerName = providers?.length ? providers[0].name : undefined;
} else {
const remote = await status.getRemote();
providerName = remote?.provider?.name;
}

iconSuffix = workingStatus ? '-blue' : '';
if (status.upstream !== undefined) {
tooltip += ` and is tracking ${status.upstream}\n${status.getUpstreamStatus({
empty: 'No commits ahead or behind',
if (status.upstream != null) {
tooltip += ` is ${status.getUpstreamStatus({
empty: `up to date with ${status.upstream}${providerName ? ` on ${providerName}` : ''}`,
expand: true,
separator: '\n',
separator: ',',
suffix: ` ${status.upstream}${providerName ? ` on ${providerName}` : ''}`,
})}`;

if (status.state.behind) {
Expand Down

0 comments on commit fd9f827

Please sign in to comment.