@@ -57,9 +57,11 @@ webui.showWarning = function(message) {
57
57
'</div>' ) . appendTo ( messageBox ) ;
58
58
}
59
59
60
- webui . git = function ( cmd , arg1 , arg2 ) {
60
+ webui . git = function ( cmd , arg1 , arg2 , arg3 , arg4 ) {
61
61
// cmd = git command line arguments
62
- // other arguments = optional stdin content and a callback function:
62
+ // other arguments = optional stdin content and a callback function.
63
+ // arg3 = optional callback for error handling
64
+ // arg4 = optional callback for warning handling
63
65
// ex:
64
66
// git("log", mycallback)
65
67
// git("commit -F -", "my commit message", mycallback)
@@ -70,6 +72,14 @@ webui.git = function(cmd, arg1, arg2) {
70
72
cmd += "\n" + arg1 ;
71
73
var callback = arg2 ;
72
74
}
75
+
76
+ if ( typeof ( arg3 ) == "function" ) {
77
+ var errorCallback = arg3 ;
78
+ }
79
+ if ( typeof ( arg4 ) == "function" ) {
80
+ var warningCallback = arg4 ;
81
+ }
82
+
73
83
$ . post ( "git" , cmd , function ( data , status , xhr ) {
74
84
if ( xhr . status == 200 ) {
75
85
// Convention : last lines are footer meta data like headers. An empty line marks the start if the footers
@@ -105,13 +115,25 @@ webui.git = function(cmd, arg1, arg2) {
105
115
}
106
116
// Return code is 0 but there is stderr output: this is a warning message
107
117
if ( message . length > 0 ) {
108
- webui . showWarning ( message ) ;
118
+ if ( warningCallback ) {
119
+ warningCallback ( message ) ;
120
+ } else {
121
+ webui . showWarning ( message ) ;
122
+ }
109
123
}
110
124
} else {
111
- webui . showError ( message ) ;
125
+ if ( errorCallback ) {
126
+ errorCallback ( message ) ;
127
+ } else {
128
+ webui . showError ( message ) ;
129
+ }
112
130
}
113
131
} else {
114
- webui . showError ( data ) ;
132
+ if ( errorCallback ) {
133
+ errorCallback ( message ) ;
134
+ } else {
135
+ webui . showError ( message ) ;
136
+ }
115
137
}
116
138
} , "text" )
117
139
. fail ( function ( xhr , status , error ) {
@@ -1781,6 +1803,12 @@ function updateSideBar () {
1781
1803
$ ( sideBarView ) . replaceWith ( MainUIObject . sideBarView . element ) ;
1782
1804
}
1783
1805
1806
+ function removeAllChildNodes ( parent ) {
1807
+ while ( parent . firstChild ) {
1808
+ parent . removeChild ( parent . firstChild ) ;
1809
+ }
1810
+ }
1811
+
1784
1812
$ ( function ( ) {
1785
1813
$ ( '[data-toggle="tooltip"]' ) . tooltip ( )
1786
1814
} )
@@ -1827,6 +1855,12 @@ $(function () {
1827
1855
1828
1856
$ ( document ) . on ( 'click' , '.btn-delete-branch' , function ( e ) {
1829
1857
e . preventDefault ( ) ;
1858
+
1859
+ function removeDeleteModal ( popup ) {
1860
+ $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
1861
+ $ ( ".modal-backdrop" ) . remove ( ) ;
1862
+ $ ( "#confirm-branch-delete" ) . remove ( ) ;
1863
+ }
1830
1864
$ ( "#confirm-branch-delete" ) . remove ( ) ; //removes any remaining modals. If there are more than one modals, the ids are duplicated and event listeners won't work.
1831
1865
var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
1832
1866
".card-header" ) . children ( "button" ) . html ( ) ;
@@ -1861,20 +1895,46 @@ $(function () {
1861
1895
$ ( popup ) . modal ( 'show' ) ;
1862
1896
1863
1897
$ ( "#confirm-branch-delete" ) . on ( 'click' , '#confirm-delete' , function ( e ) {
1864
- $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
1865
- $ ( ".modal-backdrop" ) . remove ( ) ;
1866
- $ ( "#confirm-branch-delete" ) . remove ( ) ;
1867
- webui . git ( "branch -d " + refName , function ( ) {
1868
- webui . showWarning ( "Local branch " + refName + " deleted." ) ;
1898
+
1899
+ removeDeleteModal ( popup ) ;
1900
+
1901
+ function deleteSuccessDisplay ( output ) {
1902
+ webui . showWarning ( output ) ;
1869
1903
updateSideBar ( ) ;
1870
- } ) ;
1871
-
1872
- } ) ;
1904
+ }
1905
+
1906
+ function forceDelete ( message ) {
1907
+ if ( message . includes ( "git branch -D" ) ) {
1908
+ $ ( "body" ) . append ( popup ) ;
1909
+ var popupContent = $ ( ".modal-body" , popup ) [ 0 ] ;
1910
+ removeAllChildNodes ( popupContent ) ;
1911
+ $ ( '<div class="row"><div class="col-sm-1">' +
1912
+ '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#dc3545" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">' +
1913
+ '<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"></path>' +
1914
+ '</svg></div>' +
1915
+ '<div class="col-sm-11">This branch is not fully merged. Do you want to force delete it?</div></div>' +
1916
+ '<button class="btn btn-sm btn-danger float-right" id="confirm-force-delete">Force Delete</button>' +
1917
+ '<button class="btn btn-sm btn-secondary float-right" id="cancel-delete">Cancel</button>' ) . appendTo ( popupContent ) ;
1918
+ $ ( popup ) . modal ( 'show' ) ;
1919
+
1920
+ $ ( "#confirm-branch-delete" ) . on ( 'click' , '#confirm-force-delete' , function ( e ) {
1921
+ removeDeleteModal ( popup ) ;
1922
+ webui . git ( "branch -D " + refName , deleteSuccessDisplay ) ;
1923
+ } ) ;
1924
+
1925
+ $ ( "#confirm-branch-delete" ) . find ( "#cancel-delete, .close" ) . click ( function ( ) {
1926
+ removeDeleteModal ( popup ) ;
1927
+ } ) ;
1928
+ }
1929
+ else {
1930
+ webui . showError ( message ) ;
1931
+ }
1932
+ }
1933
+ webui . git ( "branch -d " + refName , deleteSuccessDisplay , "" , forceDelete ) ;
1934
+ } ) ;
1873
1935
1874
1936
$ ( "#confirm-branch-delete" ) . find ( "#cancel-delete, .close" ) . click ( function ( ) {
1875
- $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
1876
- $ ( ".modal-backdrop" ) . remove ( ) ;
1877
- $ ( "#confirm-branch-delete" ) . remove ( ) ;
1937
+ removeDeleteModal ( popup ) ;
1878
1938
} ) ;
1879
1939
1880
1940
} ) ;
0 commit comments