@@ -385,25 +385,46 @@ define(function (require, exports) {
385385 return doPushWithArgs ( args , progressTracker ) ;
386386 }
387387
388+ const PUSH_PORCELAIN_TO_LINE = new RegExp ( "^To\\s" ) ;
389+ const PUSH_PORCELAIN_REF_LINE = new RegExp ( "^[ +\\-*!=]\\t[^\\t]*:[^\\t]*\\t" ) ;
390+
388391 function doPushWithArgs ( args , progressTracker ) {
389392 return git ( args , { progressTracker} )
390393 . catch ( repositoryNotFoundHandler )
391394 . then ( function ( stdout ) {
392- // this should clear lines from push hooks
393- var lines = stdout . split ( "\n" ) ;
394- while ( lines . length > 0 && lines [ 0 ] . match ( / ^ T o / ) === null ) {
395- lines . shift ( ) ;
395+ // pre-push hooks print to stdout before the porcelain block and may
396+ // even print lines starting with "To" (Eg. "Total size..."), so the
397+ // "To <url>" line only counts when a ref status line follows it.
398+ // the block is at the end of the output, so scan backwards.
399+ const lines = stdout . split ( "\n" ) ;
400+ let headerIndex = - 1 ;
401+ for ( let i = lines . length - 2 ; i >= 0 ; i -- ) {
402+ if ( PUSH_PORCELAIN_TO_LINE . test ( lines [ i ] ) && PUSH_PORCELAIN_REF_LINE . test ( lines [ i + 1 ] ) ) {
403+ headerIndex = i ;
404+ break ;
405+ }
406+ }
407+
408+ const retObj = { } ;
409+ if ( headerIndex === - 1 ) {
410+ // the push itself succeeded as git exited with 0, we just can't
411+ // parse the output. never report a successful push as an error.
412+ retObj . flagDescription = Strings . GIT_PUSH_SUCCESS_MSG ;
413+ retObj . from = "" ;
414+ retObj . to = "" ;
415+ retObj . summary = "" ;
416+ retObj . status = "" ;
417+ return retObj ;
396418 }
397419
398- var retObj = { } ,
399- lineTwo = lines [ 1 ] . split ( "\t" ) ;
420+ const lineTwo = lines [ headerIndex + 1 ] . split ( "\t" ) ;
400421
401- retObj . remoteUrl = lines [ 0 ] . trim ( ) . split ( " " ) [ 1 ] ;
422+ retObj . remoteUrl = lines [ headerIndex ] . trim ( ) . split ( " " ) [ 1 ] ;
402423 retObj . flag = lineTwo [ 0 ] ;
403424 retObj . from = lineTwo [ 1 ] . split ( ":" ) [ 0 ] ;
404425 retObj . to = lineTwo [ 1 ] . split ( ":" ) [ 1 ] ;
405426 retObj . summary = lineTwo [ 2 ] ;
406- retObj . status = lines [ 2 ] ;
427+ retObj . status = lines [ headerIndex + 2 ] || "" ;
407428
408429 switch ( retObj . flag ) {
409430 case " " :
0 commit comments