Skip to content

Instantly share code, notes, and snippets.

@haxorjim
Created December 3, 2015 13:55
Show Gist options
  • Save haxorjim/5c36a4d754d4789490ea to your computer and use it in GitHub Desktop.
Save haxorjim/5c36a4d754d4789490ea to your computer and use it in GitHub Desktop.
Node.js SVN Module
var svn = module.exports = {};
var execSync = require("exec-sync"),
util = require('util');
// equivalent to svn log command
svn.log = function (options) {
// TOOD: modify this to accept an options object that configures the xml, v, limit, username, password variables
var log = execSync(util.format('%s log --xml -v -r%d:%d --username %s --password %s %s', options.svn, options.nextRevision, options.maxRevision, options.username, options.password, options.remote), true);
if(log.stderr) {
return log.stderr;
}
return log.stdout;
}
// equivalent to svn cat command
svn.cat = function (options) {
// TOOD: modify this to accept an options object that configures the xml, v, limit, username, password variables
// TODO: handle errors here
// urls should not have spaces
options.target = options.target.replace(/ /g, '%20');
var cmd = util.format('%s cat --username %s --password %s --revision %s %s', options.svn, options.username, options.password, options.revision, options.target);
//console.log(cmd);
return execSync(cmd);
}
// equivalent to svn info command
svn.info = function (options) {
// TOOD: modify this to accept an options object that configures the xml, v, limit, username, password variables
// TODO: handle errors here
return execSync(util.format('%s info --xml --username %s --password %s', options.svn, options.username, options.password, options.target));
}
// equivalent to svn diff command
svn.diff = function (options) {
// TOOD: modify this to accept an options object that configures the xml, v, limit, username, password variables
// TODO: handle errors here
// urls should not have spaces
//options.target = options.target.replace(/ /g, '%20');
//var cmd = util.format('%s diff --git --username %s --password %s %s@%s %s@%s', options.svn, options.username, options.password, options.target, options.oldRev, options.target, options.newRev);
var cmd = util.format('%s diff --git --username %s --password %s -c %s %s', options.svn, options.username, options.password, options.newRev, options.target);
//console.log(cmd);
return execSync(cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment