@@ -323,15 +323,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
323
323
var cardDiv = $ ( '<div class="card custom-card">' ) . appendTo ( accordionDiv ) [ 0 ] ;
324
324
if ( id . indexOf ( "local-branches" ) > - 1 ) {
325
325
// parses the output of git branch --verbose --verbose
326
- var matches = / ^ \* ? \s * ( [ \w - ] + ) \s + ( [ ^ \s ] + ) \s + ( \[ .* \] ) ? .* / . exec ( ref ) ;
326
+ var matches = / ^ \* ? \s * ( [ \w -\/ ] + ) \s + ( [ ^ \s ] + ) \s + ( \[ .* \] ) ? .* / . exec ( ref ) ;
327
327
var branchInfo = {
328
328
"branch_name" : matches [ 1 ] ,
329
329
"hash" : matches [ 2 ] ,
330
330
"remote" : matches [ 3 ]
331
331
}
332
332
var refname = branchInfo . branch_name ;
333
333
var canPush = ( branchInfo . remote === undefined ) || ( branchInfo . remote . indexOf ( "ahead" ) > - 1 ) // either no upstream or ahead of upstream
334
- var itemId = refname + idPostfix ;
334
+ var itemId = refname . replaceAll ( '/' , '-' ) + idPostfix ;
335
335
var cardHeader = $ ( '<div class="card-header" id="heading-' + itemId + '">' ) . appendTo ( cardDiv ) ;
336
336
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 + '">'
337
337
+ refname
@@ -479,16 +479,12 @@ webui.SideBarView = function(mainView, noEventHandlers) {
479
479
webui . git ( "fetch --prune" , updateSideBar ) ;
480
480
}
481
481
482
- self . checkoutBranch = function ( e ) {
483
- e . preventDefault ( ) ;
484
- $ ( "#confirm-branch-checkout" ) . remove ( ) ;
485
482
486
- var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
487
- ".card-header ") . children ( "button" ) . html ( ) ;
483
+ self . checkoutBranch = function ( branchType , refName ) {
484
+ $ ( "#confirm-branch-checkout ") . remove ( ) ;
488
485
489
486
var remoteName = refName . split ( "/" ) [ 0 ] ;
490
- var branchName = refName . split ( "/" ) [ 1 ] ;
491
-
487
+ var branchName = refName . split ( "/" ) . slice ( 1 ) . join ( "/" ) ;
492
488
var flag = 0 ;
493
489
webui . git ( "status -u --porcelain" , function ( data ) {
494
490
$ . get ( "api/uncommitted" , function ( uncommitted ) {
@@ -534,12 +530,18 @@ webui.SideBarView = function(mainView, noEventHandlers) {
534
530
$ ( "#confirm-branch-checkout" ) . on ( 'click' , '#confirm-checkout' , function ( e ) {
535
531
e . preventDefault ( ) ;
536
532
var refName = $ ( "#confirm-branch-checkout pre" ) [ 0 ] . innerHTML ;
537
- var remoteName = refName . split ( "/" ) [ 0 ] ;
538
- var branchName = refName . split ( "/" ) [ 1 ] ;
539
533
540
- if ( branchName ) {
534
+ if ( branchType === "remote" ) {
535
+ var remoteName = refName . split ( "/" ) [ 0 ] ;
536
+ var branchName = refName . split ( "/" ) [ 1 ] ;
541
537
webui . git ( "fetch " + remoteName + " " + branchName ) ;
542
- webui . git ( "checkout -b " + branchName + " " + refName , updateSideBar ) ;
538
+ webui . git ( "branch -l " + branchName , function ( existingBranch ) {
539
+ if ( existingBranch . length > 0 ) {
540
+ webui . git ( "checkout " + branchName , updateSideBar ) ;
541
+ } else {
542
+ webui . git ( "checkout -b " + branchName + " " + refName , updateSideBar ) ;
543
+ }
544
+ } ) ;
543
545
}
544
546
else {
545
547
webui . git ( "checkout " + refName , updateSideBar , "" , "" , webui . showSuccess ) ;
@@ -552,11 +554,16 @@ webui.SideBarView = function(mainView, noEventHandlers) {
552
554
} ) ;
553
555
}
554
556
else {
555
- if ( branchName ) {
557
+ if ( branchType === "remote" ) {
556
558
webui . git ( "fetch " + remoteName + " " + branchName ) ;
557
- webui . git ( "checkout -b " + branchName + " " + refName , updateSideBar ) ;
559
+ webui . git ( "branch -l " + branchName , function ( existingBranch ) {
560
+ if ( existingBranch . length > 0 ) {
561
+ webui . git ( "checkout " + branchName , updateSideBar ) ;
562
+ } else {
563
+ webui . git ( "checkout -b " + branchName + " " + refName , updateSideBar ) ;
564
+ }
565
+ } ) ;
558
566
}
559
-
560
567
else {
561
568
webui . git ( "checkout " + refName , updateSideBar , "" , "" , webui . showSuccess ) ;
562
569
}
@@ -565,6 +572,24 @@ webui.SideBarView = function(mainView, noEventHandlers) {
565
572
} ) ;
566
573
}
567
574
575
+ self . checkoutLocalBranch = function ( e ) {
576
+ e . preventDefault ( ) ;
577
+
578
+ var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
579
+ ".card-header" ) . children ( "button" ) . html ( ) ;
580
+
581
+ self . checkoutBranch ( "local" , refName ) ;
582
+ }
583
+
584
+ self . checkoutRemoteBranch = function ( e ) {
585
+ e . preventDefault ( ) ;
586
+
587
+ var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
588
+ ".card-header" ) . children ( "button" ) . html ( ) ;
589
+
590
+ self . checkoutBranch ( "remote" , refName ) ;
591
+ }
592
+
568
593
self . deleteLocalBranch = function ( e ) {
569
594
e . preventDefault ( ) ;
570
595
@@ -779,9 +804,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
779
804
self . fetchSection ( $ ( "#sidebar-tags" , self . element ) [ 0 ] , "Tags" , "tags" , "tag" ) ;
780
805
781
806
if ( ! noEventHandlers ) {
782
- $ ( document ) . on ( 'click' , '.btn-checkout-local-branch' , self . checkoutBranch ) ;
807
+ $ ( document ) . on ( 'click' , '.btn-checkout-local-branch' , self . checkoutLocalBranch ) ;
783
808
$ ( document ) . on ( 'click' , '.btn-push-branch' , self . pushBranch ) ;
784
- $ ( document ) . on ( 'click' , '.btn-checkout-remote-branch' , self . checkoutBranch ) ;
809
+ $ ( document ) . on ( 'click' , '.btn-checkout-remote-branch' , self . checkoutRemoteBranch ) ;
785
810
786
811
$ ( document ) . on ( 'click' , '.btn-delete-branch' , self . deleteLocalBranch ) ;
787
812
0 commit comments