11'use strict' ;
2- import { TreeItem , TreeItemCollapsibleState , window } from 'vscode' ;
2+ import { MarkdownString , ThemeColor , ThemeIcon , TreeItem , TreeItemCollapsibleState , window } from 'vscode' ;
33import { BranchesView } from '../branchesView' ;
44import { BranchTrackingStatusNode } from './branchTrackingStatusNode' ;
55import { CommitNode } from './commitNode' ;
@@ -38,6 +38,7 @@ export class BranchNode
3838 private _children : ViewNode [ ] | undefined ;
3939 private readonly options : {
4040 expanded : boolean ;
41+ showAsCommits : boolean ;
4142 showComparison : false | ViewShowBranchComparison ;
4243 showCurrent : boolean ;
4344 showTracking : boolean ;
@@ -50,11 +51,12 @@ export class BranchNode
5051 view : BranchesView | CommitsView | RemotesView | RepositoriesView ,
5152 parent : ViewNode ,
5253 public readonly branch : GitBranch ,
53- // Specifies that the node is shown as a root and not nested under the branches node
54+ // Specifies that the node is shown as a root
5455 public readonly root : boolean ,
5556
5657 options ?: {
5758 expanded ?: boolean ;
59+ showAsCommits ?: boolean ;
5860 showComparison ?: false | ViewShowBranchComparison ;
5961 showCurrent ?: boolean ;
6062 showTracking ?: boolean ;
@@ -65,6 +67,7 @@ export class BranchNode
6567
6668 this . options = {
6769 expanded : false ,
70+ showAsCommits : false ,
6871 showComparison : false ,
6972 // Hide the current branch checkmark when the node is displayed as a root under the repository node
7073 showCurrent : ! this . root ,
@@ -89,6 +92,8 @@ export class BranchNode
8992 }
9093
9194 get label ( ) : string {
95+ if ( this . options . showAsCommits ) return 'Commits' ;
96+
9297 const branchName = this . branch . getNameWithoutRemote ( ) ;
9398 return this . view . config . branches ?. layout !== ViewBranchesLayout . Tree ||
9499 this . compacted ||
@@ -132,11 +137,17 @@ export class BranchNode
132137 ] ) ;
133138 if ( log == null ) return [ new MessageNode ( this . view , this , 'No commits could be found.' ) ] ;
134139
135- if (
136- this . options . showComparison !== false &&
137- ( this . view instanceof BranchesView || this . view instanceof CommitsView )
138- ) {
139- children . push ( new CompareBranchNode ( this . uri , this . view , this , this . branch ) ) ;
140+ if ( this . options . showComparison !== false && ! ( this . view instanceof RemotesView ) ) {
141+ children . push (
142+ new CompareBranchNode (
143+ this . uri ,
144+ this . view ,
145+ this ,
146+ this . branch ,
147+ this . options . showComparison ,
148+ this . splatted ,
149+ ) ,
150+ ) ;
140151 }
141152
142153 if ( pr != null ) {
@@ -157,15 +168,15 @@ export class BranchNode
157168 new BranchTrackingStatusNode ( this . view , this , this . branch , status , 'same' , this . root ) ,
158169 ) ;
159170 } else {
160- if ( status . state . ahead ) {
171+ if ( status . state . behind ) {
161172 children . push (
162- new BranchTrackingStatusNode ( this . view , this , this . branch , status , 'ahead ' , this . root ) ,
173+ new BranchTrackingStatusNode ( this . view , this , this . branch , status , 'behind ' , this . root ) ,
163174 ) ;
164175 }
165176
166- if ( status . state . behind ) {
177+ if ( status . state . ahead ) {
167178 children . push (
168- new BranchTrackingStatusNode ( this . view , this , this . branch , status , 'behind ' , this . root ) ,
179+ new BranchTrackingStatusNode ( this . view , this , this . branch , status , 'ahead ' , this . root ) ,
169180 ) ;
170181 }
171182 }
@@ -214,9 +225,9 @@ export class BranchNode
214225 async getTreeItem ( ) : Promise < TreeItem > {
215226 this . splatted = false ;
216227
217- const name = this . label ;
218- let tooltip = `Branch ${ this . branch . getNameWithoutRemote ( ) } ${ this . current ? ' (current) ' : '' } ` ;
219- let iconSuffix = '' ;
228+ let tooltip = ` ${
229+ this . current ? 'Current branch ' : 'Branch'
230+ } $(git-branch) ${ this . branch . getNameWithoutRemote ( ) } ` ;
220231
221232 let contextValue : string = ContextValues . Branch ;
222233 if ( this . current ) {
@@ -231,8 +242,13 @@ export class BranchNode
231242 if ( this . branch . tracking ) {
232243 contextValue += '+tracking' ;
233244 }
245+ if ( this . options . showAsCommits ) {
246+ contextValue += '+commits' ;
247+ }
234248
249+ let color : ThemeColor | undefined ;
235250 let description ;
251+ let iconSuffix = '' ;
236252 if ( ! this . branch . remote ) {
237253 if ( this . branch . tracking != null ) {
238254 let arrows = GlyphChars . Dash ;
@@ -262,27 +278,36 @@ export class BranchNode
262278 }
263279 }
264280
265- description = `${ this . branch . getTrackingStatus ( { suffix : `${ GlyphChars . Space } ` } ) } ${ arrows } ${
266- GlyphChars . Space
267- } ${ this . branch . tracking } `;
281+ description = this . options . showAsCommits
282+ ? `${ this . branch . getTrackingStatus ( {
283+ suffix : Strings . pad ( GlyphChars . Dot , 1 , 1 ) ,
284+ } ) } ${ this . branch . getNameWithoutRemote ( ) } ${ Strings . pad ( arrows , 2 , 2 ) } ${ this . branch . tracking } `
285+ : `${ this . branch . getTrackingStatus ( { suffix : `${ GlyphChars . Space } ` } ) } ${ arrows } ${
286+ GlyphChars . Space
287+ } ${ this . branch . tracking } `;
268288
269289 tooltip += ` is ${ this . branch . getTrackingStatus ( {
270- empty : `up to date with ${ this . branch . tracking } ${
290+ empty : `up to date with $(git-branch) $ {this . branch . tracking } ${
271291 remote ?. provider ?. name ? ` on ${ remote . provider . name } ` : ''
272292 } `,
273293 expand : true ,
294+ icons : true ,
274295 separator : ', ' ,
275- suffix : ` ${ this . branch . tracking } ${ remote ?. provider ?. name ? ` on ${ remote . provider . name } ` : '' } ` ,
296+ suffix : ` $(git-branch) ${ this . branch . tracking } ${
297+ remote ?. provider ?. name ? ` on ${ remote . provider . name } ` : ''
298+ } `,
276299 } ) } `;
277300
278301 if ( this . branch . state . ahead || this . branch . state . behind ) {
279- if ( this . branch . state . behind ) {
280- contextValue += '+behind' ;
281- iconSuffix = '-red' ;
282- }
283302 if ( this . branch . state . ahead ) {
284303 contextValue += '+ahead' ;
285- iconSuffix = this . branch . state . behind ? '-yellow' : '-green' ;
304+ color = new ThemeColor ( 'gitlens.viewChangesToPushIconColor' ) ;
305+ iconSuffix = '-green' ;
306+ }
307+ if ( this . branch . state . behind ) {
308+ contextValue += '+behind' ;
309+ color = new ThemeColor ( 'gitlens.viewChangesToPullIconColor' ) ;
310+ iconSuffix = this . branch . state . ahead ? '-yellow' : '-red' ;
286311 }
287312 }
288313 } else {
@@ -295,28 +320,30 @@ export class BranchNode
295320 }
296321 }
297322
298- if ( this . branch . date !== undefined ) {
323+ if ( this . branch . date != null ) {
299324 description = `${ description ? `${ description } ${ Strings . pad ( GlyphChars . Dot , 2 , 2 ) } ` : '' } ${
300325 this . branch . formattedDate
301326 } `;
302327
303- tooltip += `\nLast commit ${ this . branch . formatDateFromNow ( ) } (${ this . branch . formatDate (
328+ tooltip += `\n\ nLast commit ${ this . branch . formatDateFromNow ( ) } (${ this . branch . formatDate (
304329 BranchDateFormatting . dateFormat ,
305330 ) } )`;
306331 }
307332
308333 const item = new TreeItem (
309- `${ this . options . showCurrent && this . current ? ` ${ GlyphChars . Check } ${ GlyphChars . Space } ` : '' } ${ name } ` ,
334+ `${ this . options . showCurrent && this . current ? Strings . pad ( GlyphChars . Check , 0 , 2 ) : '' } ${ this . label } ` ,
310335 this . options . expanded ? TreeItemCollapsibleState . Expanded : TreeItemCollapsibleState . Collapsed ,
311336 ) ;
337+ item . iconPath = this . options . showAsCommits
338+ ? new ThemeIcon ( 'git-commit' , color )
339+ : {
340+ dark : Container . context . asAbsolutePath ( `images/dark/icon-branch${ iconSuffix } .svg` ) ,
341+ light : Container . context . asAbsolutePath ( `images/light/icon-branch${ iconSuffix } .svg` ) ,
342+ } ;
312343 item . contextValue = contextValue ;
313344 item . description = description ;
314- item . iconPath = {
315- dark : Container . context . asAbsolutePath ( `images/dark/icon-branch${ iconSuffix } .svg` ) ,
316- light : Container . context . asAbsolutePath ( `images/light/icon-branch${ iconSuffix } .svg` ) ,
317- } ;
318345 item . id = this . id ;
319- item . tooltip = tooltip ;
346+ item . tooltip = new MarkdownString ( tooltip , true ) ;
320347
321348 return item ;
322349 }
@@ -345,12 +372,10 @@ export class BranchNode
345372 private _log : GitLog | undefined ;
346373 private async getLog ( ) {
347374 if ( this . _log == null ) {
348- // Ensure we always show all unpublished commits (and the upstream tip)
349- let limit =
350- this . limit ??
351- ( this . view instanceof CommitsView ? this . view . config . pageItemLimit : this . view . config . defaultItemLimit ) ;
375+ let limit = this . limit ?? ( this . root ? this . view . config . pageItemLimit : this . view . config . defaultItemLimit ) ;
376+ // Try to show more commits if they are unpublished
352377 if ( limit !== 0 && this . branch . state . ahead > limit ) {
353- limit = this . branch . state . ahead + 1 ;
378+ limit = Math . min ( this . branch . state . ahead + 1 , limit * 2 ) ;
354379 }
355380
356381 this . _log = await Container . git . getLog ( this . uri . repoPath ! , {
0 commit comments