Follow by Email

SVN checkout and commit using gulp commands


Below code explain the code checkout, commit and view updated revision in SVN using gulp. package “node-svn-ultimate
-          Create a gulpfile in the project directory.
-          Project folder name is FOLDER_NAME
-          Add below code snippet
-          Install “node-svn-ultimate” node package.
-          Run the gulp command “gulp svn_update” in you project directory command prompt.



 var svnUltimate = require('node-svn-ultimate');

gulp.task('svn_checkout', function() {
     svnUltimate.commands.checkout( 'SVN_REPOSITORY_LINK', 'PROJECT_FOLDER', function( err ) {
      console.log( "SVN Checkout complete" );

      if(err == null){
         gulp
        .src('DESTINATION_FOLDER')
             var prompt = require('prompt');
             console.log( "Enter your SVN credentials:" );
        prompt.start();
            prompt.get([{
                name: 'username',
                required: true
            }, {
                name: 'password',
                required: true,
                hidden: true,
                replace: '*'
            }], function (err, result) {
                console.log('Command-line input received');
   svnUltimate.commands.commit( ['PROJECT_CODE'],
   { // optional options object - can be passed to any command not just update
    trustServerCert: true, // same as --trust-server-cert
    username: result.username, // same as --username
    password: result.password, // same as --password
   // shell: "sh",    // override shell used to execute command
    cwd: process.cwd(),  // override working directory command is executed
    quiet: true,   // provide --quiet to commands that accept it
    force: true,   // provide --force to commands that accept it
   //  revision: 9288,  // provide --revision to commands that accept it
    depth: "empty",   // provide --depth to commands that accept it
    ignoreExternals: true, // provide --ignore-externals to commands that accept it
    params: [ '-m "Commit comment"' ] // extra parameters to pass
   },
   function( err, revision ) {
     if(err != null){
       console.log(err);
     }else{
       console.log( "Code is sucessfully committed" );
       svnUltimate.util.getRevision( 'SVN_REPOSITORY_LINK', function( err, revision ) {
      console.log( "Updated revision=" + revision );
      });
     }    
   });
            // Gets the working copy revision or the HEAD revision if the target is a URL
   });
         
});
});

// To get the SVN revision 

gulp.task('svn_revision', function() { 
          svnUltimate.util.getRevision( 'SVN_REPOSITORY_LINK', function( err, revision ) {
            console.log( "Last revision=" + revision );
          });

});


// Sequencing the task for checkout , commit and getting the last version

gulp.task('svn_update', sequence('svn_checkout','svn_revision'));