@@ -1256,11 +1256,7 @@ webui.StashCommitView = function(stashView) {
12561256 var self = this ;
12571257
12581258 self . update = function ( entry ) {
1259- if ( currentCommit == entry . commit ) {
1260- // We already display the right data. No need to update.
1261- return ;
12621259
1263- }
12641260 currentCommit = entry . commit ;
12651261 self . showDiff ( ) ;
12661262 diffView . update ( "stash show -p stash@{" + entry . stashIndex + "}" ) ;
@@ -1294,7 +1290,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
12941290 if ( cmd ) {
12951291 self . gitCmd = cmd ;
12961292 self . gitDiffOpts = diffOpts ;
1297- if ( file != self . gitFile ) {
1293+ if ( file != self . gitFile && self . gitFile != '"undefined"' ) {
12981294 left . scrollTop = 0 ;
12991295 left . scrollLeft = 0 ;
13001296 right . scrollTop = 0 ;
@@ -1304,12 +1300,15 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
13041300 right . webuiPrevScrollTop = 0 ;
13051301 right . webuiPrevScrollLeft = 0 ;
13061302 }
1307- webui . git ( "ls-files " + file , function ( path ) {
1308- self . gitFile = file ;
1303+ webui . git ( "ls-files \"" + file + "\"" , function ( path ) {
1304+ self . gitFile = "\"" + file + "\"" ;
13091305 self . noIndex = ""
13101306 if ( path . length == 0 && file != undefined ) {
13111307 self . gitFile = " /dev/null " + file ;
1312- self . noIndex = " --no-index "
1308+ self . noIndex = " --no-index " ;
1309+ if ( self . gitDiffOpts == "--cached" ) {
1310+ self . gitDiffOpts = "" ;
1311+ }
13131312 }
13141313 if ( self . gitCmd ) {
13151314 var fullCmd = self . gitCmd ;
@@ -1324,7 +1323,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
13241323 if ( self . gitDiffOpts ) {
13251324 fullCmd += " " + self . gitDiffOpts . join ( " " )
13261325 }
1327- if ( self . gitFile ) {
1326+ if ( self . gitFile && self . gitFile != '"undefined"' ) {
13281327 fullCmd += self . noIndex + " -- " + self . gitFile ;
13291328 }
13301329 webui . git ( fullCmd , self . refresh , self . refresh , self . refresh ) ;
@@ -2060,11 +2059,6 @@ webui.CommitView = function(historyView) {
20602059 var self = this ;
20612060
20622061 self . update = function ( entry ) {
2063- if ( currentCommit == entry . commit ) {
2064- // We already display the right data. No need to update.
2065- return ;
2066-
2067- }
20682062 currentCommit = entry . commit ;
20692063 self . showDiff ( ) ;
20702064 buttonBox . select ( 0 ) ;
@@ -2172,9 +2166,10 @@ webui.NewChangedFilesView = function(workspaceView) {
21722166 webui . git ( "status -u --porcelain" , function ( data ) {
21732167 $ . get ( "api/uncommitted" , function ( uncommitted ) {
21742168 var uncommittedItems = JSON . parse ( uncommitted ) [ "current user's changes" ] ;
2169+ var otherUserUncommittedItems = JSON . parse ( uncommitted ) [ "other users' changes" ] ;
21752170 self . filesCount = 0 ;
21762171
2177- function addItemToFileList ( fileList , indexStatus , workingTreeStatus , model , isOtherUserChange ) {
2172+ function addItemToFileList ( fileList , indexStatus , workingTreeStatus , model , isOtherUserChange , otherUser ) {
21782173 var formCheck ;
21792174 if ( isOtherUserChange ) {
21802175 formCheck = $ ( '<div class="form-check changes-check other-user"></div>' ) ;
@@ -2201,7 +2196,7 @@ webui.NewChangedFilesView = function(workspaceView) {
22012196
22022197 var checkboxLabel ;
22032198 if ( isOtherUserChange ) {
2204- checkboxLabel = $ ( '<label class="form-check-label file-item-label other-user-label" data-toggle="tooltip" title="File changed by another user ">' + webui . peopleIcon + '</label>' ) . append ( model ) ;
2199+ checkboxLabel = $ ( '<label class="form-check-label file-item-label other-user-label" data-toggle="tooltip" data-placement="top" title="File changed by: ' + otherUser + ' ">' + webui . peopleIcon + '</label>' ) . append ( model ) ;
22052200 } else {
22062201 checkboxLabel = $ ( '<label class="form-check-label file-item-label"></label>' ) . text ( model ) ;
22072202 }
@@ -2224,6 +2219,7 @@ webui.NewChangedFilesView = function(workspaceView) {
22242219 } else {
22252220 model = line ;
22262221 }
2222+ model = model . replace ( / ^ " ( .* ) " $ / g, '$1' ) ;
22272223
22282224 ++ self . filesCount ;
22292225 var isForCurrentUser ;
@@ -2236,7 +2232,8 @@ webui.NewChangedFilesView = function(workspaceView) {
22362232 if ( isForCurrentUser ) {
22372233 addItemToFileList ( fileList , indexStatus , workingTreeStatus , model , false ) ;
22382234 } else {
2239- addItemToFileList ( fileList , indexStatus , workingTreeStatus , model , true ) ;
2235+ var otherUser = otherUserUncommittedItems [ model . replace ( / \/ / g, '\\' ) ] ;
2236+ addItemToFileList ( fileList , indexStatus , workingTreeStatus , model , true , otherUser ) ;
22402237 }
22412238
22422239 } ) ;
@@ -2272,6 +2269,15 @@ webui.NewChangedFilesView = function(workspaceView) {
22722269
22732270 } ) ;
22742271
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+
22752281 $ ( "#discardBtn" ) . off ( "click" ) ;
22762282 $ ( "#discardBtn" ) . on ( "click" , function ( ) {
22772283 if ( selectedItemsFromOtherUser . length > 0 ) {
@@ -2294,6 +2300,64 @@ webui.NewChangedFilesView = function(workspaceView) {
22942300 } ) ;
22952301 }
22962302
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+
22972361 self . confirmActionOnOtherUsersChanges = function ( action ) {
22982362 function removeWarningModal ( popup ) {
22992363 $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
@@ -2330,6 +2394,12 @@ webui.NewChangedFilesView = function(workspaceView) {
23302394 } ) ;
23312395
23322396 $ ( '</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+ }
23332403
23342404 var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
23352405 webui . detachChildren ( popupFooter ) ;
@@ -2345,12 +2415,15 @@ webui.NewChangedFilesView = function(workspaceView) {
23452415 $ ( '#confirmActionBtn' ) . on ( 'click' , function ( ) {
23462416 removeWarningModal ( popup ) ;
23472417 if ( action == "commit" ) {
2348- var commitMessage = $ ( '#commitMsg' ) . val ( ) + "\n" + $ ( "#commitMsgDetail" ) . val ( ) ;
2349- self . commit ( commitMessage ) ;
2418+ var commitMessage = $ ( '#commitMsg' ) . val ( ) ;
2419+ self . commit ( commitMessage , $ ( "#commitMsgDetail" ) . val ( ) ) ;
23502420 } else if ( action == "discard" ) {
23512421 self . discard ( ) ;
23522422 } else if ( action == "stash" ) {
23532423 self . stash ( ) ;
2424+ } else if ( action == "amend" ) {
2425+ var commitMessage = $ ( '#commitMsg' ) . val ( ) ;
2426+ self . amend ( commitMessage , $ ( "#commitMsgDetail" ) . val ( ) ) ;
23542427 }
23552428 } ) ;
23562429
@@ -2401,6 +2474,7 @@ webui.NewChangedFilesView = function(workspaceView) {
24012474 if ( self . getSelectedItemsCount ( ) > 0 ) {
24022475 $ ( '#stashBtn' ) . prop ( "disabled" , false ) ;
24032476 $ ( '#discardBtn' ) . prop ( "disabled" , false ) ;
2477+ $ ( '#amendBtn' ) . prop ( "disabled" , false ) ;
24042478 if ( ! self . commitMsgEmpty ( ) ) {
24052479 $ ( '#commitBtn' ) . prop ( "disabled" , false ) ;
24062480 } else {
@@ -2410,6 +2484,12 @@ webui.NewChangedFilesView = function(workspaceView) {
24102484 $ ( '#stashBtn' ) . prop ( "disabled" , true ) ;
24112485 $ ( '#discardBtn' ) . prop ( "disabled" , true ) ;
24122486 $ ( '#commitBtn' ) . prop ( "disabled" , true ) ;
2487+ if ( ! self . commitMsgEmpty ( ) ) {
2488+ $ ( '#amendBtn' ) . prop ( "disabled" , false ) ;
2489+ } else {
2490+ $ ( '#amendBtn' ) . prop ( "disabled" , true ) ;
2491+ }
2492+
24132493 }
24142494
24152495 }
@@ -2469,6 +2549,30 @@ webui.NewChangedFilesView = function(workspaceView) {
24692549 } ) ;
24702550 }
24712551
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+
24722576 self . commit = function ( message , details ) {
24732577 var selectedFilesAsString = selectedItems . join ( " " ) ;
24742578
@@ -2498,6 +2602,7 @@ webui.NewChangedFilesView = function(workspaceView) {
24982602 '</div>' +
24992603 '<div class="button-group">' +
25002604 '<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>' +
25012606 '<button type="button" class="btn btn-secondary file-action-button" id="stashBtn" disabled> Stash </button>' +
25022607 '<button type="button" class="btn btn-danger file-action-button" id="discardBtn" disabled> Discard </button>' +
25032608 '</div>' +
0 commit comments