Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions __tests__/orc-test.js

This file was deleted.

2 changes: 1 addition & 1 deletion orc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /usr/bin/env node
var orc = require('./orc.js');
orc.main();
orc.main(process.cwd(), process.argv);
221 changes: 180 additions & 41 deletions orc.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,169 @@
var app = require('commander');
var commander = require('commander');
var git = require('gitty');
var path = require('path');

// process.stdin.resume();
// process.stdin.setEncoding('utf8');
// process.stdin.on('data', function(data) {
// process.stdout.write(data);
// });
var pushover = require('pushover');

process.on('SIGINT', function () {
console.log('Got a SIGINT. Goodbye cruel world');
process.exit(0);
});

function _requireCommit() {
function init(dir, cb) {
// TODO: march up to root dir just to make output consistent
var repo = git(dir);
repo.getBranches(function(err, branches) {
if(err) {
cb('error getting branches '+err);
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stylistic nit: "return cb('error getting branches '+err);" is how we do it all through the server code.

}
if (!branches.current) {
cb('error: '+repo.name+' doesn\'t appear to be a valid git repo');
return;
}
cb(null, { repo_dir: dir, repo: git(dir)});
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the repo: git(dir)? Isn't repo set at the beginning of this function? Shouldn't it be just repo: repo ?

}

function noUnstaged(orc, cb) {
orc.repo.status(function(err, status) {
if(err) {
cb('error getting status checking unstaged '+err);
return;
}
if(status.unstaged.length > 0) {
cb('unstaged files, commit before running this.');
return;
}
cb(null, true);
});
}

function noUntracked(orc, cb) {
orc.repo.status(function(err, status) {
if(err) {
cb('error getting status checking unstaged '+err);
return;
}
if(status.untracked.length > 0) {
cb('untracked files, add or ignore before running this.');
return;
}
cb(null, true);
});
}

function repoIsClean(orc, cb) {
noUnstaged(orc, function(err, res) {
if (err) {
cb(err);
return;
}
noUntracked(orc, function(err, res) {
if(err) {
cb(err);
return;
}
cb(null, true);
});
});
}

function checkpoint() {
function repoHasChanges(orc, cb) {
orc.repo.status(function(err, status) {
if(err) {
cb('error getting status checking unstaged '+err);
return;
}
if(status.staged.length === 0 && status.unstaged.length === 0) {
cb('no changes, aborting.');
return;
}
cb(null, true);
});
}

// commit local changes
// push to remote
function checkpoint(orc, cb) {
noUntracked(orc, function(err, res) {
if(err) {
cb('you have unstaged files: '+err);
return;
}
repoHasChanges(orc, function(err, res) {
if(err) {
cb(err);
return;
}
orc.repo.commit('ORC-CHECKPOINT', ['-a', '--no-verify'], function(err, res) {
if(err) {
cb('checkpoint commit failed: \n'+err.message);
return;
}
orc.repo.getBranches(function(err, branches) {
if(err) {
cb('error getting branches: '+err.message);
return;
}
orc.repo.push('origin', branches.current, function(err, result) {
if (err) {
cb('error pushing checkpoint: '+err.message);
return;
}
cb(null, 'checkpoint finished.');
});
});
});
});
});
}

function pull() {
// TODO
function pull(orc, cb) {
// TODO
}

function push() {
// TODO
function push(orc, cb) {
// TODO
}

function branch() {
// TODO
function createBranch(orc, branchName, cb) {
repoIsClean(orc, function(err, res) {
if(err) {
cb(err);
return;
}
orc.repo.checkout('master', function(err, res) {
if(err) {
cb('failed to checkout master'+err.message);
return;
}
orc.repo.pull('origin','master', function(err, res) {
if (err) {
cb('failed to pull from master: '+err.message);
return;
}
orc.repo.createBranch(branchName, function(err, res) {
if(err) {
cb('failed to create branch '+branchName+': '+err.message);
return;
}
orc.repo.checkout(branchName, function(err, res) {
if(err) {
cb('couldn\'t checkout branch '+branchName+': '+err.message);
return;
}
orc.repo.push('origin', branchName, ['--set-upstream'], cb);
});
});
});
});
});
}

function status() {
// TODO: incomplete, just an example
/*
{ staged:
function status(orc,cb) {
// TODO: remove, just an example
/*
{ staged:
[ { file: '../package.json',
status: 'new file' } ],
unstaged:
Expand All @@ -46,28 +173,40 @@ function status() {
status: 'modified' } ],
untracked: [ 'orc-test.js' ] }
*/
r = new git.Repo('.', {}, function(err, repo) {
if(err) {
console.log('error getting repo status');
return;
}
repo.status(function(err, stats){
console.log('stats: '+JSON.stringify(stats));
});
});
orc.repo.status(cb);
}

app.command('checkpoint').alias('cp').description('commit all local changes and push to repo. use this all the time!').action(checkpoint);
app.command('pull').description('pull latest from remote master into your current branch').action(pull);
app.command('push').description("use this when you're ready to submit a pull request on github: squash your branch down to one commit, run unit tests, and push.").action(push);
app.command('branch').description('helper for switching branches').action(branch);
app.command('status').alias('st').description('helper for getting status').action(status); // REMOVE
function main(dir, argv, cb) {
if(!cb) {
cb = function(err, res) {
if(err) {
console.log('error: '+err);
} else {
// TODO: standardize result text and output
console.log('done. '+res);
}
};
}

init(dir, function(err, orc) {
if(err) {
cb('failed to init orc: '+err);
return;
}

var app = new commander.Command();
app.command('checkpoint').alias('cp').description('commit all local changes and push to repo. use this all the time!')
.action(function() { checkpoint(orc, cb); });
app.command('pull').description('pull latest from remote master into your current branch')
.action(function() {pull(orc, cb); });
app.command('push').description("use this when you're ready to submit a pull request on github: squash your branch down to one commit, run unit tests, and push.")
.action(function() {push(orc, cb);});
app.command('branch [name]').alias('br').description('helper for creating branches')
.action(function(branchName) { createBranch(orc, branchName, cb); });
app.command('status').alias('st').description('helper for getting status').action(function() { status(orc, cb);}); // REMOVE
app.parse(argv);
});
}
// orc checkpoint change

exports.checkpoint = checkpoint;
exports.pull = pull;
exports.push = push;
exports.branch = branch;
exports.main = function() {
p = app.parse(process.argv);
console.log('main! '+JSON.stringify(process.argv));
};
exports.main = main;
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "overlook research command line interface to change manager",
"main": "orc.js",
"scripts": {
"test": "jest",
"test": "mocha",
"lint": "jshint orc *.js"
},
"keywords": [
Expand All @@ -14,10 +14,14 @@
"dependencies": {
"commander": "~2.6.0",
"gitty": "*",
"jest": "~0.1.37",
"jshint": "~2.6.0",
"tmp": "*"
"jshint": "~2.6.0"
},
"author": "Aaron Brady",
"license": "(c) Overlook Research 2014"
"license": "(c) Overlook Research 2014",
"devDependencies": {
"chai": "^1.10.0",
"mocha": "^2.1.0",
"pushover": "^1.3.6",
"tmp": "*"
}
}
Loading