Skip to content

Commit 11237b6

Browse files
committed
1 parent 25add22 commit 11237b6

3 files changed

Lines changed: 44 additions & 19 deletions

File tree

extensions/git/src/model.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ import * as nls from 'vscode-nls';
1717
const localize = nls.loadMessageBundle();
1818

1919
class RepositoryPick implements QuickPickItem {
20-
@memoize get label(): string { return path.basename(this.repository.root); }
21-
@memoize get description(): string { return path.dirname(this.repository.root); }
20+
@memoize get label(): string {
21+
return path.basename(this.repository.root);
22+
}
23+
24+
@memoize get description(): string {
25+
return [this.repository.headLabel, this.repository.syncLabel]
26+
.filter(l => !!l)
27+
.join(' ');
28+
}
29+
2230
constructor(public readonly repository: Repository) { }
2331
}
2432

extensions/git/src/repository.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import { Uri, Command, EventEmitter, Event, scm, SourceControl, SourceControlInputBox, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit } from 'vscode';
9-
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash } from './git';
9+
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType } from './git';
1010
import { anyEvent, filterEvent, eventToPromise, dispose, find } from './util';
1111
import { memoize, throttle, debounce } from './decorators';
1212
import { toGitUri } from './uri';
@@ -835,6 +835,36 @@ export class Repository implements Disposable {
835835
}
836836
}
837837

838+
get headLabel(): string {
839+
const HEAD = this.HEAD;
840+
841+
if (!HEAD) {
842+
return '';
843+
}
844+
845+
const tag = this.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
846+
const tagName = tag && tag.name;
847+
const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
848+
849+
return head
850+
+ (this.workingTreeGroup.resourceStates.length > 0 ? '*' : '')
851+
+ (this.indexGroup.resourceStates.length > 0 ? '+' : '')
852+
+ (this.mergeGroup.resourceStates.length > 0 ? '!' : '');
853+
}
854+
855+
get syncLabel(): string {
856+
if (!this.HEAD
857+
|| !this.HEAD.name
858+
|| !this.HEAD.commit
859+
|| !this.HEAD.upstream
860+
|| !(this.HEAD.ahead || this.HEAD.behind)
861+
) {
862+
return '';
863+
}
864+
865+
return `${this.HEAD.behind}${this.HEAD.ahead}↑`;
866+
}
867+
838868
dispose(): void {
839869
this.disposables = dispose(this.disposables);
840870
}

extensions/git/src/statusbar.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import { Disposable, Command, EventEmitter, Event } from 'vscode';
9-
import { RefType, Branch } from './git';
9+
import { Branch } from './git';
1010
import { Repository, Operation } from './repository';
1111
import { anyEvent, dispose } from './util';
1212
import * as nls from 'vscode-nls';
@@ -24,20 +24,7 @@ class CheckoutStatusBar {
2424
}
2525

2626
get command(): Command | undefined {
27-
const HEAD = this.repository.HEAD;
28-
29-
if (!HEAD) {
30-
return undefined;
31-
}
32-
33-
const tag = this.repository.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
34-
const tagName = tag && tag.name;
35-
const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
36-
const title = '$(git-branch) '
37-
+ head
38-
+ (this.repository.workingTreeGroup.resourceStates.length > 0 ? '*' : '')
39-
+ (this.repository.indexGroup.resourceStates.length > 0 ? '+' : '')
40-
+ (this.repository.mergeGroup.resourceStates.length > 0 ? '!' : '');
27+
const title = `$(git-branch) ${this.repository.headLabel}`;
4128

4229
return {
4330
command: 'git.checkout',
@@ -112,7 +99,7 @@ class SyncStatusBar {
11299
if (HEAD && HEAD.name && HEAD.commit) {
113100
if (HEAD.upstream) {
114101
if (HEAD.ahead || HEAD.behind) {
115-
text += `${HEAD.behind}${HEAD.ahead}↑`;
102+
text += this.repository.syncLabel;
116103
}
117104
command = 'git.sync';
118105
tooltip = localize('sync changes', "Synchronize Changes");

0 commit comments

Comments
 (0)