@@ -322,7 +322,10 @@ webui.SideBarView = function(mainView, noEventHandlers) {
322
322
}
323
323
var cardDiv = $ ( '<div class="card custom-card">' ) . appendTo ( accordionDiv ) [ 0 ] ;
324
324
if ( id . indexOf ( "local-branches" ) > - 1 ) {
325
- var refname = ref . substring ( 2 ) ;
325
+ // parses the output of git branch --verbose --verbose
326
+ var branchInfo = / ^ \* ? \s * (?< branch_name > [ \w - ] + ) \s + (?< hash > [ ^ \s ] + ) \s + (?< remote > \[ .* \] ) ? .* / . exec ( ref ) . groups ;
327
+ var refname = branchInfo . branch_name ;
328
+ var canPush = ( branchInfo . remote === undefined ) || ( branchInfo . remote . includes ( "ahead" ) ) // either no upstream or ahead of upstream
326
329
var itemId = refname + idPostfix ;
327
330
var cardHeader = $ ( '<div class="card-header" id="heading-' + itemId + '">' ) . appendTo ( cardDiv ) ;
328
331
var button = $ ( '<button class="btn btn-sm btn-default btn-branch text-left" type="button" data-toggle="collapse" data-target="#collapse-' + itemId + '" aria-expanded="true" aria-controls="collapse-' + itemId + '">'
@@ -335,17 +338,19 @@ webui.SideBarView = function(mainView, noEventHandlers) {
335
338
'<div class="d-grid gap-2 col-12 mx-auto">' +
336
339
'<button class="btn btn-xs btn-primary btn-block btn-checkout-local-branch mt-1">Checkout Branch</button>' +
337
340
'<button class="btn btn-xs btn-warning btn-block btn-merge-branch">Merge Branch</button>' +
338
- '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' +
341
+ ( canPush ? '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' : '' ) +
339
342
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>' +
340
343
'</div>' +
341
344
'</div>' ) . appendTo ( collapseDiv ) ;
342
345
} else {
343
346
$ ( button ) . addClass ( "branch-current" ) ;
344
- var cardBody = $ ( '<div class="card-body">' +
345
- '<div class="d-grid gap-2 col-12 mx-auto">' +
346
- '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' +
347
- '</div>' +
348
- '</div>' ) . appendTo ( collapseDiv ) ;
347
+ if ( canPush ) {
348
+ var cardBody = $ ( '<div class="card-body">' +
349
+ '<div class="d-grid gap-2 col-12 mx-auto">' +
350
+ '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' +
351
+ '</div>' +
352
+ '</div>' ) . appendTo ( collapseDiv ) ;
353
+ }
349
354
}
350
355
} else {
351
356
var refname = ref . replaceAll ( '/' , '-' ) ;
@@ -754,7 +759,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
754
759
$ ( "#sidebar-settings" , self . element ) . click ( self . goToSettingsPage ) ;
755
760
}
756
761
757
- self . fetchSection ( $ ( "#sidebar-local-branches" , self . element ) [ 0 ] , "Local Branches" , "local-branches" , "branch" ) ;
762
+ self . fetchSection ( $ ( "#sidebar-local-branches" , self . element ) [ 0 ] , "Local Branches" , "local-branches" , "branch --verbose --verbose " ) ;
758
763
self . fetchSection ( $ ( "#sidebar-remote-branches" , self . element ) [ 0 ] , "Remote Branches" , "remote-branches" , "branch --remotes" ) ;
759
764
self . fetchSection ( $ ( "#sidebar-tags" , self . element ) [ 0 ] , "Tags" , "tags" , "tag" ) ;
760
765
0 commit comments