@@ -870,54 +870,86 @@ RED.sidebar.versionControl = (function() {
870870 } ) ;
871871 } ) ;
872872
873- $ ( '<button id="sidebar-version-control-repo-pull" class="sidebar-version-control-repo-sub-action editor-button"><i class="fa fa-long-arrow-down"></i> <span>pull</span></button>' )
874- . appendTo ( row )
875- . click ( function ( e ) {
876- e . preventDefault ( ) ;
877- var spinner = utils . addSpinnerOverlay ( remoteBox ) . addClass ( "projects-dialog-spinner-contain" ) ;
878- var activeProject = RED . projects . getActiveProject ( ) ;
879- var url = "projects/" + activeProject . name + "/pull" ;
880- if ( activeProject . git . branches . remoteAlt ) {
881- url += "/" + activeProject . git . branches . remoteAlt ;
882- }
883- if ( $ ( "#sidebar-version-control-repo-toolbar-set-upstream" ) . prop ( 'checked' ) ) {
884- url += "?u=true"
873+ var pullRemote = function ( options ) {
874+ options = options || { } ;
875+ var spinner = utils . addSpinnerOverlay ( remoteBox ) . addClass ( "projects-dialog-spinner-contain" ) ;
876+ var activeProject = RED . projects . getActiveProject ( ) ;
877+ var url = "projects/" + activeProject . name + "/pull" ;
878+ if ( activeProject . git . branches . remoteAlt ) {
879+ url += "/" + activeProject . git . branches . remoteAlt ;
880+ }
881+ if ( options . setUpstream || options . allowUnrelatedHistories ) {
882+ url += "?" ;
883+ }
884+ if ( options . setUpstream ) {
885+ url += "setUpstream=true"
886+ if ( options . allowUnrelatedHistories ) {
887+ url += "&" ;
885888 }
886-
887- utils . sendRequest ( {
888- url : url ,
889- type : "POST" ,
890- responses : {
891- 0 : function ( error ) {
892- console . log ( error ) ;
893- // done(error,null);
889+ }
890+ if ( options . allowUnrelatedHistories ) {
891+ url += "allowUnrelatedHistories=true"
892+ }
893+ utils . sendRequest ( {
894+ url : url ,
895+ type : "POST" ,
896+ responses : {
897+ 0 : function ( error ) {
898+ console . log ( error ) ;
899+ // done(error,null);
900+ } ,
901+ 200 : function ( data ) {
902+ refresh ( true ) ;
903+ closeRemoteBox ( ) ;
904+ } ,
905+ 400 : {
906+ 'git_local_overwrite' : function ( err ) {
907+ RED . notify ( "<p>Unable to pull remote changes; your unstaged local changes would be overwritten.</p><p>Commit your changes and try again.</p>" +
908+ '<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">' + 'Show unstaged changes' + '</a></p>' , "error" , false , 10000000 ) ;
894909 } ,
895- 200 : function ( data ) {
910+ 'git_pull_merge_conflict' : function ( err ) {
896911 refresh ( true ) ;
897- closeRemoteBox ( ) ;
898912 } ,
899- 400 : {
900- 'git_local_overwrite' : function ( err ) {
901- RED . notify ( "Unable to pull remote changes; your unstaged local changes would be overwritten. Commit your changes and try again." +
902- '<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">' + 'Show unstaged changes' + '</a></p>' , "error" , false , 10000000 ) ;
903- } ,
904- 'git_pull_merge_conflict' : function ( err ) {
905- refresh ( true ) ;
906- } ,
907- 'git_connection_failed' : function ( err ) {
908- RED . notify ( "Could not connect to remote repository: " + err . toString ( ) , "warning" )
909- } ,
910- 'unexpected_error' : function ( error ) {
911- console . log ( error ) ;
912- // done(error,null);
913- } ,
914- 'git_pull_unrelated_history' : function ( error ) {
915- RED . notify ( "Unable to pull remote changes; refusing to merge unrelated histories." , "error" ) ;
916- }
913+ 'git_connection_failed' : function ( err ) {
914+ RED . notify ( "Could not connect to remote repository: " + err . toString ( ) , "warning" )
917915 } ,
918- }
919- } , { } ) . always ( function ( ) {
920- spinner . remove ( ) ;
916+ 'git_pull_unrelated_history' : function ( error ) {
917+ var notification = RED . notify ( "<p>The remote has an unrelated history of commits.</p><p>Are you sure you want to pull the changes into your local repository?</p>" , {
918+ type : 'error' ,
919+ modal : true ,
920+ fixed : true ,
921+ buttons : [
922+ {
923+ text : RED . _ ( "common.label.cancel" ) ,
924+ click : function ( ) {
925+ notification . close ( ) ;
926+ }
927+ } , {
928+ text : 'Pull changes' ,
929+ click : function ( ) {
930+ notification . close ( ) ;
931+ options . allowUnrelatedHistories = true ;
932+ pullRemote ( options )
933+ }
934+ }
935+ ]
936+ } ) ;
937+ } ,
938+ '*' : function ( error ) {
939+ utils . reportUnexpectedError ( error ) ;
940+ }
941+ } ,
942+ }
943+ } , { } ) . always ( function ( ) {
944+ spinner . remove ( ) ;
945+ } ) ;
946+ }
947+ $ ( '<button id="sidebar-version-control-repo-pull" class="sidebar-version-control-repo-sub-action editor-button"><i class="fa fa-long-arrow-down"></i> <span>pull</span></button>' )
948+ . appendTo ( row )
949+ . click ( function ( e ) {
950+ e . preventDefault ( ) ;
951+ pullRemote ( {
952+ setUpstream : $ ( "#sidebar-version-control-repo-toolbar-set-upstream" ) . prop ( 'checked' )
921953 } ) ;
922954 } ) ;
923955
0 commit comments