@@ -2269,6 +2269,15 @@ webui.NewChangedFilesView = function(workspaceView) {
22692269
22702270 } ) ;
22712271
2272+ $ ( "#amendBtn" ) . off ( "click" ) ;
2273+ $ ( "#amendBtn" ) . on ( "click" , function ( ) {
2274+ if ( selectedItemsFromOtherUser . length > 0 ) {
2275+ self . confirmActionOnOtherUsersChanges ( "amend" ) ;
2276+ } else {
2277+ self . confirmAmend ( ) ;
2278+ }
2279+ } ) ;
2280+
22722281 $ ( "#discardBtn" ) . off ( "click" ) ;
22732282 $ ( "#discardBtn" ) . on ( "click" , function ( ) {
22742283 if ( selectedItemsFromOtherUser . length > 0 ) {
@@ -2291,6 +2300,64 @@ webui.NewChangedFilesView = function(workspaceView) {
22912300 } ) ;
22922301 }
22932302
2303+ self . confirmAmend = function ( ) {
2304+ function removePopup ( popup ) {
2305+ $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
2306+ $ ( ".modal-backdrop" ) . remove ( ) ;
2307+ $ ( "#confirmAmend" ) . remove ( ) ;
2308+ }
2309+
2310+ var popup = $ (
2311+ '<div class="modal fade" tabindex="-1" id="confirmAmend" role="dialog" data-backdrop="static">' +
2312+ '<div class="modal-dialog modal-md" role="document">' +
2313+ '<div class="modal-content">' +
2314+ '<div class="modal-header">' +
2315+ '<h5 class="modal-title">Confirm amend</h5>' +
2316+ '<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui . largeXIcon + '</button>' +
2317+ '</div>' +
2318+ '<div class="modal-body"></div>' +
2319+ '<div class="modal-footer"></div>' +
2320+ '</div>' +
2321+ '</div>' +
2322+ '</div>'
2323+ ) [ 0 ] ;
2324+
2325+ $ ( "body" ) . append ( popup ) ;
2326+ var popupContent = $ ( ".modal-body" , popup ) [ 0 ] ;
2327+ webui . detachChildren ( popupContent ) ;
2328+
2329+ $ (
2330+ '<div class="row">' +
2331+ '<div class="col-sm-1">' +
2332+ webui . warningIcon +
2333+ '</div>' +
2334+ '<div class="col-sm-11">' +
2335+ '<p>Careful, amending commits will rewrite the branch history. The amended commit will not be pushed to remote, even if the previous commit was.</p>' + // Removed extra closing </p> tag
2336+ '</div>' +
2337+ '</div>'
2338+ ) . appendTo ( popupContent ) ;
2339+
2340+ var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
2341+ webui . detachChildren ( popupFooter ) ;
2342+
2343+ $ (
2344+ '<button class="btn btn-sm btn-warning action-btn" id="confirmAmendBtn">Confirm amend</button>' +
2345+ '<button class="btn btn-sm btn-secondary action-btn" id="cancelAmendBtn">Cancel</button>'
2346+ ) . appendTo ( popupFooter ) ;
2347+
2348+ $ ( popup ) . modal ( 'show' ) ;
2349+
2350+ $ ( '#confirmAmendBtn' ) . on ( 'click' , function ( ) {
2351+ removePopup ( popup ) ;
2352+ var commitMessage = $ ( '#commitMsg' ) . val ( ) ;
2353+ self . amend ( commitMessage , $ ( "#commitMsgDetail" ) . val ( ) ) ;
2354+ } ) ;
2355+
2356+ $ ( '#confirmAmend' ) . find ( '#cancelAmendBtn, .close' ) . click ( function ( ) {
2357+ removePopup ( popup ) ;
2358+ } ) ;
2359+ }
2360+
22942361 self . confirmActionOnOtherUsersChanges = function ( action ) {
22952362 function removeWarningModal ( popup ) {
22962363 $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
@@ -2327,6 +2394,12 @@ webui.NewChangedFilesView = function(workspaceView) {
23272394 } ) ;
23282395
23292396 $ ( '</ul>' ) . appendTo ( popupContent ) ;
2397+
2398+ if ( action == "amend" ) {
2399+ $ ( '<div>' +
2400+ '<p>Careful, amending commits will rewrite the branch history. The amended commit will not be pushed to remote, even if the previous commit was.</p>' +
2401+ '</div>' ) . appendTo ( popupContent ) ;
2402+ }
23302403
23312404 var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
23322405 webui . detachChildren ( popupFooter ) ;
@@ -2342,12 +2415,15 @@ webui.NewChangedFilesView = function(workspaceView) {
23422415 $ ( '#confirmActionBtn' ) . on ( 'click' , function ( ) {
23432416 removeWarningModal ( popup ) ;
23442417 if ( action == "commit" ) {
2345- var commitMessage = $ ( '#commitMsg' ) . val ( ) + "\n" + $ ( "#commitMsgDetail" ) . val ( ) ;
2346- self . commit ( commitMessage ) ;
2418+ var commitMessage = $ ( '#commitMsg' ) . val ( ) ;
2419+ self . commit ( commitMessage , $ ( "#commitMsgDetail" ) . val ( ) ) ;
23472420 } else if ( action == "discard" ) {
23482421 self . discard ( ) ;
23492422 } else if ( action == "stash" ) {
23502423 self . stash ( ) ;
2424+ } else if ( action == "amend" ) {
2425+ var commitMessage = $ ( '#commitMsg' ) . val ( ) ;
2426+ self . amend ( commitMessage , $ ( "#commitMsgDetail" ) . val ( ) ) ;
23512427 }
23522428 } ) ;
23532429
@@ -2398,6 +2474,7 @@ webui.NewChangedFilesView = function(workspaceView) {
23982474 if ( self . getSelectedItemsCount ( ) > 0 ) {
23992475 $ ( '#stashBtn' ) . prop ( "disabled" , false ) ;
24002476 $ ( '#discardBtn' ) . prop ( "disabled" , false ) ;
2477+ $ ( '#amendBtn' ) . prop ( "disabled" , false ) ;
24012478 if ( ! self . commitMsgEmpty ( ) ) {
24022479 $ ( '#commitBtn' ) . prop ( "disabled" , false ) ;
24032480 } else {
@@ -2407,6 +2484,12 @@ webui.NewChangedFilesView = function(workspaceView) {
24072484 $ ( '#stashBtn' ) . prop ( "disabled" , true ) ;
24082485 $ ( '#discardBtn' ) . prop ( "disabled" , true ) ;
24092486 $ ( '#commitBtn' ) . prop ( "disabled" , true ) ;
2487+ if ( ! self . commitMsgEmpty ( ) ) {
2488+ $ ( '#amendBtn' ) . prop ( "disabled" , false ) ;
2489+ } else {
2490+ $ ( '#amendBtn' ) . prop ( "disabled" , true ) ;
2491+ }
2492+
24102493 }
24112494
24122495 }
@@ -2466,6 +2549,30 @@ webui.NewChangedFilesView = function(workspaceView) {
24662549 } ) ;
24672550 }
24682551
2552+ self . amend = function ( message , details ) {
2553+ var selectedFilesAsString = selectedItems . join ( " " ) ;
2554+ if ( self . commitMsgEmpty ( ) ) {
2555+ webui . git ( "add " + selectedFilesAsString ) ;
2556+ webui . git ( "commit --amend --no-edit -- " + selectedFilesAsString , function ( output ) {
2557+ webui . showSuccess ( output ) ;
2558+ workspaceView . update ( ) ;
2559+ } )
2560+ } else if ( selectedItems . length != 0 ) {
2561+ webui . git ( "add " + selectedFilesAsString ) ;
2562+ webui . git ( 'commit --amend -m "' + message + '" -m "' + details + '" -- ' + selectedFilesAsString , function ( output ) {
2563+ webui . showSuccess ( output ) ;
2564+ workspaceView . update ( ) ;
2565+ } )
2566+ } else {
2567+ webui . git ( 'commit --amend --allow-empty -m "' + message + '" -m "' + details + '"' , function ( output ) {
2568+ webui . showSuccess ( output ) ;
2569+ workspaceView . update ( ) ;
2570+ } )
2571+ }
2572+
2573+
2574+ }
2575+
24692576 self . commit = function ( message , details ) {
24702577 var selectedFilesAsString = selectedItems . join ( " " ) ;
24712578
@@ -2495,6 +2602,7 @@ webui.NewChangedFilesView = function(workspaceView) {
24952602 '</div>' +
24962603 '<div class="button-group">' +
24972604 '<button type="button" class="btn btn-primary file-action-button" id="commitBtn" disabled> Commit </button>' +
2605+ '<button type="button" class="btn btn-outline-primary file-action-button" id="amendBtn" disabled> Amend </button>' +
24982606 '<button type="button" class="btn btn-secondary file-action-button" id="stashBtn" disabled> Stash </button>' +
24992607 '<button type="button" class="btn btn-danger file-action-button" id="discardBtn" disabled> Discard </button>' +
25002608 '</div>' +
0 commit comments