@@ -322,26 +322,35 @@ 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 + '">'
329
332
+ refname
330
333
+ '</button>' ) . appendTo ( cardHeader ) ;
331
334
335
+ var collapseDiv = $ ( '<div id="collapse-' + itemId + '" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId + '" data-parent="#accordion-' + id + '-' + idPostfix + '">' ) . appendTo ( cardDiv ) ;
332
336
if ( ref [ 0 ] != "*" ) {
333
- var collapseDiv = $ ( '<div id="collapse-' + itemId + '" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId + '" data-parent="#accordion-' + id + '-' + idPostfix + '">' ) . appendTo ( cardDiv ) ;
334
337
var cardBody = $ ( '<div class="card-body">' +
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>' +
341
+ ( canPush ? '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' : '' ) +
338
342
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>' +
339
343
'</div>' +
340
344
'</div>' ) . appendTo ( collapseDiv ) ;
341
- }
342
-
343
- if ( ref [ 0 ] == "*" ) {
345
+ } else {
344
346
$ ( button ) . addClass ( "branch-current" ) ;
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
+ }
345
354
}
346
355
} else {
347
356
var refname = ref . replaceAll ( '/' , '-' ) ;
@@ -642,6 +651,14 @@ webui.SideBarView = function(mainView, noEventHandlers) {
642
651
webui . git ( "merge --no-commit --no-ff " + refName , "" , self . upToDateHandler , callTestMergeHandler , callTestMergeHandler ) ;
643
652
}
644
653
654
+ /// pushes the selected local branch to "origin"
655
+ self . pushBranch = function ( e ) {
656
+ e . preventDefault ( ) ;
657
+ var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
658
+ ".card-header" ) . children ( "button" ) . html ( ) ;
659
+ webui . git ( `push -u origin ${ refName } ` , "" , self . upToDateHandler )
660
+ }
661
+
645
662
self . goToSettingsPage = function ( ) {
646
663
window . location . replace ( webui . settingsURL ) ;
647
664
}
@@ -667,7 +684,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
667
684
$ ( self . buildAccordion ( section , refs , id , undefined , "popup" ) ) . appendTo ( popupContent ) ;
668
685
// Hide popup when the user selects a branch operation
669
686
// Then execute the required operation with other even listeners
670
- $ ( popupContent ) . find ( ".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch" ) . click ( function ( ) {
687
+ $ ( popupContent ) . find ( ".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch, .btn-push-branch " ) . click ( function ( ) {
671
688
$ ( popup ) . modal ( 'hide' ) ;
672
689
} ) ;
673
690
}
@@ -742,12 +759,13 @@ webui.SideBarView = function(mainView, noEventHandlers) {
742
759
$ ( "#sidebar-settings" , self . element ) . click ( self . goToSettingsPage ) ;
743
760
}
744
761
745
- 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 " ) ;
746
763
self . fetchSection ( $ ( "#sidebar-remote-branches" , self . element ) [ 0 ] , "Remote Branches" , "remote-branches" , "branch --remotes" ) ;
747
764
self . fetchSection ( $ ( "#sidebar-tags" , self . element ) [ 0 ] , "Tags" , "tags" , "tag" ) ;
748
765
749
766
if ( ! noEventHandlers ) {
750
767
$ ( document ) . on ( 'click' , '.btn-checkout-local-branch' , self . checkoutBranch ) ;
768
+ $ ( document ) . on ( 'click' , '.btn-push-branch' , self . pushBranch ) ;
751
769
$ ( document ) . on ( 'click' , '.btn-checkout-remote-branch' , self . checkoutBranch ) ;
752
770
753
771
$ ( document ) . on ( 'click' , '.btn-delete-branch' , self . deleteLocalBranch ) ;
0 commit comments