exports.add_remote = function(repository, remote_name, remote_url, cb) { var repo = git(REPOSITORY_PATH + repository); repo.addRemote(remote_name, remote_url, function(err, message) { winston.debug(err); cb(err, message); }); };
exports.is_modified = function (file, cb) { var path_array = file.path.split('/'); var repository = path_array[2]; var repository_path = path.resolve(REPOSITORY_PATH, repository); var item_path = path_array.slice(3).join('/'); var is_modified = false; var repo = git(repository_path); repo.status(function(err, output) { winston.debug(err, output); if (output.not_staged.length > 0) { output.not_staged.forEach(function(item, index) { if (item.file === item_path) { is_modified = true; } }); } if (output.untracked.indexOf(item_path) !== -1) { is_modified = true; } cb(err, is_modified); }); };
exports.move = function move(repository, source, destination, cb) { var repository_path = REPOSITORY_PATH + repository; var repo = git(repository_path); repo.move(source, destination, function(err, message) { //winston.debug(obj); cb(err, message); }); };
before(function(cb) { process.chdir(project); repo = gitty(process.cwd()); repo.initSync(); repo.addSync(['.']); repo.commitSync('first commit'); cb(); });
exports.commit = function commit(repository, message, cb) { var repository_path = REPOSITORY_PATH + repository; winston.debug(repository_path); var repo = git(repository_path); repo.commit(message, function(err, message) { //winston.debug(obj); cb(err, message); }); };
exports.remove_recursive = function remove_recursive(repository, path, cb) { var repository_path = REPOSITORY_PATH + repository; var repo = git(repository_path); repo.remove_recursive(path, function(err, data) { winston.debug(err); cb(err, data); }); };
function push(repository_path, remote, branch, username) { var repo = git(repository_path); repo.push(remote, branch, function(err) { if (err) { winston.error(err); ws_helper.send_message(null, 'git-push-error', {err: "Error: Failure pushing code to remote repository"}); } //winston.debug(obj); }); }
exports.remove = function remove(repository, files, cb) { if (!Array.isArray(files)) { files = [files]; } var repository_path = REPOSITORY_PATH + repository; var repo = git(repository_path); repo.remove(files, function(err, added) { winston.debug(err); cb(err, added); }); };
exports.create_local_repository = function(name, cb) { winston.debug("create_repository", name); //create directory var repository_path = REPOSITORY_PATH + name; if (!fs.existsSync(repository_path)){ fs.mkdirSync(repository_path); } var repo = git(repository_path); repo.init(function(err, output) { cb(err, output); }); };
exports.pull = function pull(repository, remote, branch, cb) { var repository_path = REPOSITORY_PATH + repository; var repo = git(repository_path); repo.pull(remote, branch, function(err, message) { if (err) { winston.error(err); cb("Error: Failure updating from remote repository", message); } else { cb(null, message); } }); };
/** * Finds and initializes the Git Repository * @returns {Repository} */ function initializeRepository() { if (getBasePath() === null) return null; repository = git(getBasePath()); cli.spinner(ui.message.locating_repository + '..'); while(!repository._ready){ // do nothing }; cli.spinner(ui.message.locating_repository + '..' + ui.message.done + '!', true); //End the spinner console.log(repository); repository.status(function (err, status) { if (err) return console.log('Error:', err); }); return repository; }
promptTask : function() { var repo = git(this.destinationRoot()); var remotes = {}; try { remotes = repo.getRemotesSync(); } catch (e) { // If we're not in a repo it will cause an exception, we can trap this // silently } var defaults = { name : this.appname, repository : _.has(remotes, 'origin') ? remotes.origin : '' }; var config = _.extend(defaults, basic_config.getDefaults(), drupal_config.getDefaults(), puppet_config .getDefaults(), capistrano_config.getDefaults(), this.config.getAll()); var prompts = [].concat(basic_config.getPrompts(config), drupal_config.getPrompts(config), puppet_config .getPrompts(config), capistrano_config.getPrompts(config)); var done = this.async(); this.prompt(prompts, function(props) { _.extend(this, config, props); // Check to see if we should be using SASS / Compass // TODO: Make this less manual this.use_compass = (_.has(this, 'drupal_use_compass') && this.drupal_use_compass) || (_.has(this, 'wordpress_use_compass') && this.wordpress_use_compass); var that = this; _.each(props, function(val, key) { that.config.set(key, val); }); // Set variables for platform // TODO: Fix duplication of labels that.is_drupal = (that.platform == 'drupal'); that.is_wordpress = (that.platform == 'wordpress'); that.is_javascript = (that.platform == 'javascript'); done(); }.bind(this)); },
config.watch.forEach(function (element, index) { var git = gitty(element.directory); if (element.credentials != undefined) { git.pull(element.repository, element.branch, element.credentials, function (err) { if (err) { return console.log(err); } }); }else { git.pull(element.repository, element.branch, element.username, function (err) { if (err) { return console.log(err); } }); }; });
exports.is_untracked = function (file, cb) { var path_array = file.path.split('/'); var repository = path_array[2]; var repository_path = path.resolve(REPOSITORY_PATH, repository); var item_path = path_array.slice(3).join('/'); winston.debug(item_path); var is_untracked = false; var repo = git(repository_path); repo.status(function(err, output) { winston.debug(err, output); if (output.untracked.indexOf(item_path) !== -1) { is_untracked = true; } cb(err, is_untracked); }); };
var update = function(req, res) { if(sd._config.update.key!=req.params.key) return res.send(false); else res.send(true); var git = require('gitty'); var myRepo = git(process.cwd()); myRepo.fetch('--all',function(err){ myRepo.reset('origin/'+(req.params.branch||'master'),function(err){ var pm2 = require('pm2'); pm2.connect(function(err) { if (err) { console.error(err); process.exit(2); } pm2.restart({ name: sd._config.name }, function(err, apps) { pm2.disconnect(); process.exit(2); }); }); }); }); }
var Compiler = function(paths) { this.paths = paths; this.repo = Promise.promisifyAll(gitty(this.paths.repo)); };
var Compiler = function(options) { _.extend(this, options); this.repo = Promise.promisifyAll(gitty(this.repo)); };
var config = require("./release_config") var git = require("gitty") var newTagName = config.tagPrefix + config.currVersion var myRepo = git("") myRepo.addSync( [config.versionPath, config.packagePath, config.changeLogPath].concat( config.docFilesPaths ) ) myRepo.commitSync("release " + config.currVersion) // version has already been increased... myRepo.createTagSync(newTagName) myRepo.push("origin", "master", function() { console.log("finished push to branch") }) myRepo.push("origin", newTagName, function() { console.log("finished push tag") })
var chevrotainJSPath_bin = path.join(__dirname, '../bin/chevrotain.js') var chevrotainJSPath_bin_min = path.join(__dirname, '../bin/chevrotain.min.js') var chevrotainDTSPath_bin = path.join(__dirname, '../bin/chevrotain.d.ts') var chevrotainJSPath_release = path.join(__dirname, '../release/chevrotain.js') var chevrotainJSPath_release_min = path.join(__dirname, '../release/chevrotain.min.js') var chevrotainDTSPath_release = path.join(__dirname, '../release/chevrotain.d.ts') fs.writeFileSync(chevrotainJSPath_release, fs.readFileSync(chevrotainJSPath_bin)) fs.writeFileSync(chevrotainJSPath_release_min, fs.readFileSync(chevrotainJSPath_bin_min)) fs.writeFileSync(chevrotainDTSPath_release, fs.readFileSync(chevrotainDTSPath_bin)) var newTagName = config.tagPrefix + config.currVersion var myRepo = git('') myRepo.addSync([ config.apiPath, config.travisPath, config.packagePath, config.bowerPath, chevrotainJSPath_release, chevrotainJSPath_release_min, chevrotainDTSPath_release ].concat(config.docFilesPaths)) myRepo.commitSync("release " + config.currVersion) // version has already been increased... myRepo.createTagSync(newTagName) myRepo.push("origin", "master", function() { console.log("finished push to branch") })
var Engine = function(){ var _this = this; var dis_snap_path = "data/dis_snapshot.json"; var rules_path = "data/rules.json"; var myRepo = git('.'); var url = 'https://github.com/wizardamigosinstitute/RepPointsServer'; var dis_snapshot, rules; var event_queue = async.queue(function(task, callback){ _this.eventWrapper(task.fn, task.args, task.message, callback); }); this.enqueueTask = function(_fn, _args, _message){ event_queue.push({ fn: _fn, args: _args, message: _message }); } var redistribute_timer_id; var creation_timer_id; this.start = function(){ async.series([ function(cb){ _this.gitInit(cb); }, function(cb){ _this.loadData(cb); }, function(cb){ redistribute_timer_id = setInterval(function(){ _this.enqueueTask(_this.performRedistribution, [], "redistribution of points by RepPointsServer"); }, rules.redistribution_interval); creation_timer_id = setInterval(function(){ _this.enqueueTask(_this.performCreatePoints, [], "points created by RepPointsServer"); }, rules.creation_interval); cb(); } ]); } this.gitInit = function(cb){ if(!fs.existsSync('.git')){ console.log('initializing git'); myRepo.initSync(); myRepo.addRemoteSync('origin', url); execSync('git config --global user.email ' + process.env.GITHUB_USERNAME); execSync('git config --global user.name ' + process.env.GITHUB_USERNAME); execSync('git config credential.helper store'); myRepo.addSync(['-A']); myRepo.commitSync('git init from heroku'); } cb(); } this.loadData = function(cb){ console.log("--> git pull origin master"); myRepo.pull('origin', 'master', function(err){ if(err) return console.log(err); console.log('--> git pull successful!'); dis_snapshot = JSON.parse(fs.readFileSync(dis_snap_path, 'utf8')); console.log("read dis_snapshot"); rules = JSON.parse(fs.readFileSync(rules_path, 'utf8')); console.log("read rules"); if(cb !== undefined) cb(); }); } this.saveData = function(message, cb){ //write to file fs.writeFileSync(dis_snap_path, JSON.stringify(dis_snapshot, null, 4)); //stage myRepo.addSync([dis_snap_path]); //commit myRepo.commitSync(message); //push execSync('git push --all --repo=' + url); console.log("pushed to remote"); if(cb !== undefined) cb(); } this.eventWrapper = function(fn, args, message, queue_callback){ console.log("performing '" + message + "'"); async.series([ function(cb){ _this.loadData(cb); }, function(cb){ fn.apply(null, args); cb(); }, function(cb){ _this.saveData(message, cb); }, function(cb){ cb(); queue_callback(); } ]); } this.performRedistribution = function(){ var sum = 0; dis_snapshot.users.forEach(function(e){ var r; sum += r = e.points * rules.redistribution_rate; e.points -= r; }); dis_snapshot.users.forEach(function(e, i, arr){ e.points += sum / arr.length; }); dis_snapshot.timestamp = Date.now(); } this.performCreatePoints = function(){ dis_snapshot.users.forEach(function(e, i, arr){ e.points += rules.creation_rate / arr.length; }); dis_snapshot.timestamp = Date.now(); } /** * Transfers reputation points from user A to user B * if balance of A is sufficient * #transferPoints * @param {String} fromUserId * @param {String} toUserId * @param {int} amount */ this.transferPoints = function(fromUserId, toUserId, amount){ var valid = false; var users = dis_snapshot.users; for(var i = 0 ; i < users.length ; i++){ if(users[i].name === fromUserId){ console.log("fromUser found"); if(users[i].points >= amount){ console.log("withdrawal successful"); users[i].points -= amount; valid = true; } break; } } if(valid){ for(var i = 0 ; i < users.length ; i++){ if(users[i].name == toUserId){ console.log("toUser found"); users[i].points = parseInt(users[i].points) + parseInt(amount); break; } } } dis_snapshot.timestamp = Date.now(); } }