@@ -37,6 +37,19 @@ webui.COLORS = ["#ffab1d", "#fd8c25", "#f36e4a", "#fc6148", "#d75ab6", "#b25ade"
3737 "#e47b07" , "#e36920" , "#d34e2a" , "#ec3b24" , "#ba3d99" , "#9d45c9" , "#4f5aec" , "#615dcf" , "#3286cf" , "#00abca" , "#279227" , "#3a980c" , "#6c7f00" , "#ab8b0a" , "#b56427" , "#757575" ,
3838 "#ff911a" , "#fc8120" , "#e7623e" , "#fa5236" , "#ca4da9" , "#a74fd3" , "#5a68ff" , "#6d69db" , "#489bd9" , "#00bcde" , "#36a436" , "#47a519" , "#798d0a" , "#c1a120" , "#bf7730" , "#8e8e8e" ]
3939
40+ webui . showSuccess = function ( message ) {
41+ var messageBox = $ ( "#message-box" ) ;
42+ messageBox . empty ( ) ;
43+ $ ( '<div class="alert alert-success alert-dismissible" role="alert">' +
44+ '<button type="button" class="btn btn-default close" data-dismiss="alert">' +
45+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">' +
46+ '<path fill-rule="evenodd" clip-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z" fill="#000"/>' +
47+ '<path fill-rule="evenodd" clip-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z" fill="#000"/>' +
48+ '</svg>' +
49+ '</button>' +
50+ message +
51+ '</div>' ) . appendTo ( messageBox ) ;
52+ }
4053
4154webui . showError = function ( message ) {
4255 $ ( "#error-modal .alert" ) . text ( message ) ;
@@ -122,10 +135,21 @@ webui.git = function(cmd, arg1, arg2, arg3, arg4) {
122135 }
123136 }
124137 } else {
125- if ( errorCallback ) {
126- errorCallback ( message ) ;
127- } else {
128- webui . showError ( message ) ;
138+ var displayMessage = ""
139+ if ( output . length > 0 ) {
140+ displayMessage += ( output + "\n" ) ;
141+ }
142+ if ( message . length > 0 ) {
143+ displayMessage += message ;
144+ }
145+ if ( displayMessage . length > 0 ) {
146+ if ( errorCallback ) {
147+ errorCallback ( displayMessage ) ;
148+ } else {
149+ webui . showError ( displayMessage ) ;
150+ }
151+ } else {
152+ webui . showError ( "The command <pre>" + cmd + "</pre> failed because of an unknown reason. Returned response: \n\n" + data )
129153 }
130154 }
131155 } else {
@@ -289,6 +313,7 @@ webui.SideBarView = function(mainView) {
289313 var cardBody = $ ( '<div class="card-body">' +
290314 '<div class="d-grid gap-2 col-12 mx-auto">' +
291315 '<button class="btn btn-xs btn-primary btn-block btn-checkout-local-branch mt-1">Checkout Branch</button>' +
316+ '<button class="btn btn-xs btn-warning btn-block btn-merge-branch">Merge Branch</button>' +
292317 '<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>' +
293318 '</div>' +
294319 '</div>' ) . appendTo ( collapseDiv ) ;
@@ -315,6 +340,7 @@ webui.SideBarView = function(mainView) {
315340 var cardBody = $ ( '<div class="card-body">' +
316341 '<div class="d-grid gap-2 col-12 mx-auto">' +
317342 '<button class="btn btn-xs btn-primary btn-block btn-checkout-remote-branch">Checkout Branch</button>' +
343+ '<button class="btn btn-xs btn-warning btn-block btn-merge-remote-branch">Merge Branch</button>' +
318344 '</div>' +
319345 '</div>' ) . appendTo ( collapseDiv ) ;
320346 }
@@ -1953,6 +1979,55 @@ $(function () {
19531979
19541980 } ) ;
19551981
1982+ $ ( document ) . on ( 'click' , '.btn-merge-branch' , function ( e ) {
1983+ e . preventDefault ( ) ;
1984+ var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
1985+ ".card-header" ) . children ( "button" ) . html ( ) ;
1986+
1987+ function testMergeHandler ( message ) {
1988+ function suppressErrorMessage ( error ) {
1989+ }
1990+ webui . git ( "merge --abort" , "" , "" , suppressErrorMessage ) ;
1991+
1992+ if ( message . includes ( "Automatic merge went well" ) || message . includes ( "Auto-merging " ) ) {
1993+ webui . git ( "merge " + refName , function ( output ) {
1994+ webui . showSuccess ( output ) ;
1995+ } ) ;
1996+ }
1997+ else {
1998+ webui . showError ( message ) ;
1999+ }
2000+ }
2001+ webui . git ( "merge --no-commit --no-ff " + refName , "" , "" , testMergeHandler , testMergeHandler ) ;
2002+ } ) ;
2003+
2004+ $ ( document ) . on ( 'click' , '.btn-merge-remote-branch' , function ( e ) {
2005+ e . preventDefault ( ) ;
2006+ var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
2007+ ".card-header" ) . children ( "button" ) . html ( ) ;
2008+
2009+ var remoteName = refName . split ( '/' ) [ 0 ] ;
2010+ var branchName = refName . split ( '/' ) [ 1 ] ;
2011+
2012+ webui . git ( "fetch " + remoteName + " " + branchName ) ;
2013+
2014+ function testMergeHandler ( message ) {
2015+ function suppressErrorMessage ( error ) {
2016+ }
2017+ webui . git ( "merge --abort" , "" , "" , suppressErrorMessage ) ;
2018+
2019+ if ( message . includes ( "Automatic merge went well" ) || message . includes ( "Auto-merging " ) ) {
2020+ webui . git ( "merge " + refName , function ( output ) {
2021+ webui . showSuccess ( output ) ;
2022+ } ) ;
2023+ }
2024+ else {
2025+ webui . showError ( message ) ;
2026+ }
2027+ }
2028+ webui . git ( "merge --no-commit --no-ff " + refName , "" , "" , testMergeHandler , testMergeHandler ) ;
2029+ } ) ;
2030+
19562031 $ ( document ) . on ( 'click' , '.btn-checkout-remote-branch' , function ( e ) {
19572032 e . preventDefault ( ) ;
19582033 var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
@@ -1961,7 +2036,7 @@ $(function () {
19612036 var remoteName = refName . split ( '/' ) [ 0 ] ;
19622037 var branchName = refName . split ( '/' ) [ 1 ] ;
19632038
1964- webui . git ( "fetch " + remoteName ) ;
2039+ webui . git ( "fetch " + remoteName + " " + branchName ) ;
19652040 webui . git ( "checkout -b " + branchName + " " + refName , function ( ) {
19662041 updateSideBar ( ) ;
19672042 } ) ;
0 commit comments