From adeb5822faf0fc0b43039d55c0c7f57977fc5b9d Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Tue, 10 Feb 2015 17:06:45 -0800 Subject: [PATCH 1/9] cp --- __tests__/orc-test.js | 7 ---- orc | 2 +- orc.js | 90 +++++++++++++++++++++++-------------------- package.json | 14 ++++--- test/orc-test.js | 84 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 54 deletions(-) delete mode 100644 __tests__/orc-test.js create mode 100644 test/orc-test.js diff --git a/__tests__/orc-test.js b/__tests__/orc-test.js deleted file mode 100644 index dc7e59c..0000000 --- a/__tests__/orc-test.js +++ /dev/null @@ -1,7 +0,0 @@ -jest.dontMock('../orc.js'); - -describe('checkpoint', function() { - it('checkpoints a module by committing it', function() { - - }); -}); \ No newline at end of file diff --git a/orc b/orc index 303e93d..02f5b98 100755 --- a/orc +++ b/orc @@ -1,3 +1,3 @@ #! /usr/bin/env node var orc = require('./orc.js'); -orc.main(); \ No newline at end of file +orc.main(process.cwd(), process.argv); \ No newline at end of file diff --git a/orc.js b/orc.js index 8332d65..78cfc0c 100644 --- a/orc.js +++ b/orc.js @@ -1,42 +1,56 @@ var app = 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 _setup(dir) { + // TODO: march up to root dir just to make output consistent + var repo = git(dir); + try { + branches = repo.getBranchesSync(); + if (!branches.current) { + throw new Error('error: '+repo.name+' doesn\'t appear to be a valid git repo'); + } + } catch (e) { + console.error('error: problem getting info about repo '+repo.name+' '+e.message); + return false; + } + return { repo_dir: dir, repo: git(dir)}; } -function checkpoint() { +function _requireCommit(orc) { + if(orc.repo.statusSync().unstages.length > 0) { + throw new Error('unstaged files, commit before running this.'); + } +} +function checkpoint(orc) { + // commits local changes and pushes them without unit tests } -function pull() { - // TODO +function pull(orc) { + // TODO } -function push() { - // TODO +function push(orc) { + // TODO } -function branch() { - // TODO +function createBranch(orc, branchName) { + _requireCommit(); + orc.repo.checkoutSync('master'); + orc.repo.pullSync(); } -function status() { - // TODO: incomplete, just an example - /* - { staged: +function status(orc) { + // TODO: incomplete, just an example + /* + { staged: [ { file: '../package.json', status: 'new file' } ], unstaged: @@ -46,28 +60,22 @@ 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(function(err, stats){ + console.log('stats: '+JSON.stringify(stats)); + }); } -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 - -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 = function(dir, argv) { + var orc = _setup(dir); + if(!orc) { + return false; + } + app.command('checkpoint').alias('cp').description('commit all local changes and push to repo. use this all the time!').action(function() { checkpoint(orc); }); + app.command('pull').description('pull latest from remote master into your current branch').action(function() {pull(orc); }); + 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);}); + app.command('branch [name]').alias('br').description('helper for creating branches').action(function(branchName) { createBranch(orc, branch_name); }); + app.command('status').alias('st').description('helper for getting status').action(function() { status(orc);}); // REMOVE + app.parse(argv); + console.log('main! '+JSON.stringify(argv)); + return true; }; \ No newline at end of file diff --git a/package.json b/package.json index bb5bdc6..1a84b35 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -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": "*" + } } diff --git a/test/orc-test.js b/test/orc-test.js new file mode 100644 index 0000000..62fdfdf --- /dev/null +++ b/test/orc-test.js @@ -0,0 +1,84 @@ +var child_process = require('child_process'); +var expect = require("chai").expect; +var fs = require('fs'); +var git = require('gitty'); +var path = require('path'); +var pushover = require('pushover'); +var tmp = require('tmp'); + +var orc = require('../orc.js'); + +describe('no repo', function() { + it('should fail in a directory without git', function() { + tmp.dir(function(err, dir) { + expect(err).to.be.null(); + expect(orc.main(dir, [])).to.be.false(); + }); + }); +}); + +describe('basic repo', function() { + tmp.dir(function(err, dir) { + expect(err).to.be.null(); + var repo = git(dir, []); + repo.initSync(); + var fn = path.resolve(dir,'foo.js'); + fs.writeFileSync(fn, 'o hai'); + repo.addSync([fn]); + repo.commitSync('foo'); + + it('should start up properly in a new github repo', function() { + expect(orc.main(dir, ['node', 'orc'])).to.be.true(); + }); + }); +}); + +describe('remote tests', function() { + var repo; + var repo_dir; + var server_dir; + + // create a simple git server listener + before(function(done) { + tmp.dir(function(err, dir) { + server_dir = dir; + repo_dir = path.resolve(dir,'orctest1'); + fs.mkdirSync(repo_dir); + + repo = git(repo_dir); + repo.initSync(); + repo.addRemoteSync('local', 'http://localhost:7001/server'); + var repos = pushover(dir); + repos.on('push', function(push) { + push.accept(); + }); + require('http').createServer(function(req, res) { + repos.handle(req, res); + }).listen(7001, function() { + done(); + }); + }); + }); + it('should push to the remote', function(done) { + console.log('server dir: '+server_dir); + repo.push('local', 'master', function(err, result) { + var fn = path.resolve(repo_dir,'foo.js'); + fs.writeFileSync(fn, 'o hai'); + repo.addSync([fn]); + repo.commitSync('bar'); + expect(fs.existsSync(path.resolve(server_dir,'server.git'))).to.be.true(); + done(); + }); + }); + it('should create a branch based off of the latest commit on master', function() { + + }); +}); +/* +describe('github tests', function() { + var repo1 = null; + var repo2 = null; + tmp.dir(function(err, dir) { + child_process.execSync('git clone https://orctester:abcd1234@github.com/orctester/orctest.git', {cwd: dir}); + +});*/ \ No newline at end of file From 5048a7a273aa855513d4b0e5f2f217139ca3f35a Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 09:31:33 -0800 Subject: [PATCH 2/9] framework and some basic functionality, incorporate feedback --- orc.js | 108 +++++++++++++++++++++++++++++++++-------------- test/orc-test.js | 91 +++++++++++++++++++++++++++++---------- 2 files changed, 144 insertions(+), 55 deletions(-) diff --git a/orc.js b/orc.js index 78cfc0c..376d924 100644 --- a/orc.js +++ b/orc.js @@ -1,4 +1,4 @@ -var app = require('commander'); +var commander = require('commander'); var git = require('gitty'); var path = require('path'); var pushover = require('pushover'); @@ -11,44 +11,75 @@ process.on('SIGINT', function () { function _setup(dir) { // TODO: march up to root dir just to make output consistent var repo = git(dir); - try { - branches = repo.getBranchesSync(); - if (!branches.current) { - throw new Error('error: '+repo.name+' doesn\'t appear to be a valid git repo'); - } - } catch (e) { - console.error('error: problem getting info about repo '+repo.name+' '+e.message); - return false; + branches = repo.getBranchesSync(); + if (!branches.current) { + throw new Error('error: '+repo.name+' doesn\'t appear to be a valid git repo'); } return { repo_dir: dir, repo: git(dir)}; } -function _requireCommit(orc) { - if(orc.repo.statusSync().unstages.length > 0) { +function _requireClean(orc) { + var status = orc.repo.statusSync(); + if(status.unstaged.length > 0) { throw new Error('unstaged files, commit before running this.'); } + if(status.untracked.length > 0) { + throw new Error('untracked files, add or ignore before running this.'); + } } -function checkpoint(orc) { - // commits local changes and pushes them without unit tests +// commit local changes +// push to remote +function checkpoint(orc, cb) { + if(orc.repo.statusSync().untracked.length > 0) { + throw new Error('untracked files, add or ignore before running this.'); + } + if(!orc.repo.commitSync('ORC-CHECKPOINT')) { + throw new Error('checkpoint commit failed'); + } + orc.repo.push('origin', 'master', function(err, result) { + if (err) { + cb('error pushing checkpoint: '+JSON.stringify(err)); + return; + } + cb(null, true); + }); } -function pull(orc) { +function pull(orc, cb) { // TODO } -function push(orc) { +function push(orc, cb) { // TODO } -function createBranch(orc, branchName) { - _requireCommit(); +function createBranch(orc, branchName, cb) { + _requireClean(orc); orc.repo.checkoutSync('master'); - orc.repo.pullSync(); + orc.repo.pull('origin','master', function(err, res) { + if (err) { + throw new Error('failed to pull from master: '+JSON.stringify(err)); + } + if (orc.repo.createBranchSync(branchName) !== '') { + throw new Error('failed to create branch '+branchName); + } + if(!orc.repo.checkoutSync(branchName)) { + throw new Error('couldn\'t checkout branch '+branchName); + } + orc.repo.push('origin', branchName, ['--set-upstream'], function(err, res) { + if (err) { + cb(err); + } else { + cb(null, true); + } + }); + }); + // TODO: block until done } -function status(orc) { - // TODO: incomplete, just an example +function status(orc,cb) { + // TODO: remove, just an example /* { staged: [ { file: '../package.json', @@ -60,22 +91,35 @@ function status(orc) { status: 'modified' } ], untracked: [ 'orc-test.js' ] } */ - orc.repo.status(function(err, stats){ - console.log('stats: '+JSON.stringify(stats)); - }); + orc.repo.status(cb); } -exports.main = function(dir, argv) { +exports.main = function(dir, argv, cb) { + if(!cb) { + cb = function(err, res) { + if(err) { + console.err('error: '+JSON.stringify(err)); + } else { + // TODO: standardize result text and output + console.log('done. '+res); + } + }; + } + var orc = _setup(dir); if(!orc) { - return false; + cb('failed to init orc'); } - app.command('checkpoint').alias('cp').description('commit all local changes and push to repo. use this all the time!').action(function() { checkpoint(orc); }); - app.command('pull').description('pull latest from remote master into your current branch').action(function() {pull(orc); }); - 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);}); - app.command('branch [name]').alias('br').description('helper for creating branches').action(function(branchName) { createBranch(orc, branch_name); }); - app.command('status').alias('st').description('helper for getting status').action(function() { status(orc);}); // REMOVE + + 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); - console.log('main! '+JSON.stringify(argv)); - return true; }; \ No newline at end of file diff --git a/test/orc-test.js b/test/orc-test.js index 62fdfdf..a57d98b 100644 --- a/test/orc-test.js +++ b/test/orc-test.js @@ -12,7 +12,12 @@ describe('no repo', function() { it('should fail in a directory without git', function() { tmp.dir(function(err, dir) { expect(err).to.be.null(); - expect(orc.main(dir, [])).to.be.false(); + expect(function() { + orc.main(dir, [], function(err, res) { + expect(err).not.to.be.null(); + expect(res).to.be.undefined(); + }); + }).to.throw(); }); }); }); @@ -27,51 +32,91 @@ describe('basic repo', function() { repo.addSync([fn]); repo.commitSync('foo'); - it('should start up properly in a new github repo', function() { - expect(orc.main(dir, ['node', 'orc'])).to.be.true(); + it('should start up properly in a new github repo', function(done) { + orc.main(dir, ['node', 'orc'], function(err, res) { + expect(err).to.be.null(); + expect(res).to.be.true(); + done(); + }); }); }); }); describe('remote tests', function() { + var gitserver; var repo; - var repo_dir; - var server_dir; + var repo2; + var repoDir; + var rootDir; + var repoName = 'orctest'; + var branchName = 'foobranch'; // create a simple git server listener before(function(done) { tmp.dir(function(err, dir) { - server_dir = dir; - repo_dir = path.resolve(dir,'orctest1'); - fs.mkdirSync(repo_dir); + rootDir = dir; + repoDir = path.resolve(dir,repoName); + fs.mkdirSync(repoDir); - repo = git(repo_dir); + repo = git(repoDir); repo.initSync(); - repo.addRemoteSync('local', 'http://localhost:7001/server'); - var repos = pushover(dir); - repos.on('push', function(push) { + repo.addRemoteSync('origin', 'http://localhost:7001/server'); + var gitserver = pushover(dir); + gitserver.on('push', function(push) { push.accept(); }); + gitserver.on('fetch', function (fetch) { + fetch.accept(); + }); require('http').createServer(function(req, res) { - repos.handle(req, res); + gitserver.handle(req, res); }).listen(7001, function() { done(); }); }); }); - it('should push to the remote', function(done) { - console.log('server dir: '+server_dir); - repo.push('local', 'master', function(err, result) { - var fn = path.resolve(repo_dir,'foo.js'); - fs.writeFileSync(fn, 'o hai'); - repo.addSync([fn]); - repo.commitSync('bar'); - expect(fs.existsSync(path.resolve(server_dir,'server.git'))).to.be.true(); + // this is expected to have been done outside of orc + it('should create the master branch and push it', function(done) { + var fn = path.resolve(repoDir,'foo.js'); + fs.writeFileSync(fn, 'o hai'); + repo.addSync([fn]); + repo.commitSync('bar'); + repo.push('origin', 'master', function(err, result) { + expect(fs.existsSync(path.resolve(rootDir,'server.git'))).to.be.true(); + done(); + }); + }); + it('should create a branch based off of the latest commit on master', function(done) { + orc.main(repoDir,['node','orc','branch',branchName], function(err, res) { + expect(repo.getBranchesSync().current).to.equal(branchName); done(); }); }); - it('should create a branch based off of the latest commit on master', function() { - + it('should have pushed the branch so it is visible to others', function(done) { + tmp.dir(function(err, dir) { + expect(err).to.be.null(); + //console.log('root dir: '+rootDir); + //console.log('repo2 root: '+dir); + var repo2_dir = path.resolve(dir,dir); + git.clone(repo2_dir, 'http://localhost:7001/server', function(err) { + expect(err).to.be.null(); + repo2 = git(repo2_dir); + repo2.pull('origin','master',['-a'], function(err, res) { + var co_res = repo2.checkoutSync(branchName); + expect(co_res).to.be.ok(); + done(); + }); + }); + }); + }); + it('should checkpoint properly', function() { + var fn = path.resolve(repoDir,'bar.js'); + fs.writeFileSync(fn, 'o hai'); + expect(function() { + orc.main(repoDir, ['node','orc','checkpoint'], function(err, cb) { + expect(0).to.be.ok(); // shouldn't ever get here + }); + }).to.throw(); }); }); /* From 108658012d04027a04c3fb1407a9bc10d42e07b2 Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 09:31:33 -0800 Subject: [PATCH 3/9] framework and some basic functionality, incorporate feedback --- orc.js | 184 ++++++++++++++++++++++++++++++++++++----------- test/orc-test.js | 89 +++++++++++++++++------ 2 files changed, 210 insertions(+), 63 deletions(-) diff --git a/orc.js b/orc.js index 78cfc0c..01d1555 100644 --- a/orc.js +++ b/orc.js @@ -1,4 +1,4 @@ -var app = require('commander'); +var commander = require('commander'); var git = require('gitty'); var path = require('path'); var pushover = require('pushover'); @@ -8,47 +8,134 @@ process.on('SIGINT', function () { process.exit(0); }); -function _setup(dir) { +function init(dir, cb) { // TODO: march up to root dir just to make output consistent var repo = git(dir); - try { - branches = repo.getBranchesSync(); + repo.getBranches(function(err, branches) { + if(err) { + cb('error getting branches '+err); + return; + } if (!branches.current) { - throw new Error('error: '+repo.name+' doesn\'t appear to be a valid git repo'); + cb('error: '+repo.name+' doesn\'t appear to be a valid git repo'); + return; } - } catch (e) { - console.error('error: problem getting info about repo '+repo.name+' '+e.message); - return false; - } - return { repo_dir: dir, repo: git(dir)}; + cb(null, { repo_dir: dir, repo: git(dir)}); + }); } -function _requireCommit(orc) { - if(orc.repo.statusSync().unstages.length > 0) { - throw new Error('unstaged files, commit before running this.'); - } +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 checkpoint(orc) { - // commits local changes and pushes them without unit tests +function noUncommitted(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; + } + noUncommitted(orc, function(err, res) { + if(err) { + cb(err); + return; + } + cb(null, true); + }); + }); } -function pull(orc) { +// commit local changes +// push to remote +function checkpoint(orc, cb) { + orc.repo.status(function(err, res) { + if(err) { + cb('error getting status'+err); + return; + } + orc.repo.commit('ORC-CHECKPOINT', function(err, res) { + if(err) { + cb('checkpoint commit failed '+res); + return; + } + orc.repo.push('origin', 'master', function(err, result) { + if (err) { + cb('error pushing checkpoint: '+JSON.stringify(err)); + return; + } + cb(null, true); + }); + }); + }); +} + +function pull(orc, cb) { // TODO } -function push(orc) { +function push(orc, cb) { // TODO } -function createBranch(orc, branchName) { - _requireCommit(); - orc.repo.checkoutSync('master'); - orc.repo.pullSync(); +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); + return; + } + orc.repo.pull('origin','master', function(err, res) { + if (err) { + cb('failed to pull from master: '+JSON.stringify(err)); + return; + } + orc.repo.createBranch(branchName, function(err, res) { + if(err) { + cb('failed to create branch '+branchName); + return; + } + orc.repo.checkout(branchName, function(err, res) { + if(err) { + cb('couldn\'t checkout branch '+branchName); + return; + } + orc.repo.push('origin', branchName, ['--set-upstream'], cb); + }); + }); + }); + }); + }); } -function status(orc) { - // TODO: incomplete, just an example +function status(orc,cb) { + // TODO: remove, just an example /* { staged: [ { file: '../package.json', @@ -60,22 +147,39 @@ function status(orc) { status: 'modified' } ], untracked: [ 'orc-test.js' ] } */ - orc.repo.status(function(err, stats){ - console.log('stats: '+JSON.stringify(stats)); - }); + orc.repo.status(cb); } -exports.main = function(dir, argv) { - var orc = _setup(dir); - if(!orc) { - return false; +function main(dir, argv, cb) { + if(!cb) { + cb = function(err, res) { + if(err) { + console.err('error: '+JSON.stringify(err)); + } else { + // TODO: standardize result text and output + console.log('done. '+res); + } + }; } - app.command('checkpoint').alias('cp').description('commit all local changes and push to repo. use this all the time!').action(function() { checkpoint(orc); }); - app.command('pull').description('pull latest from remote master into your current branch').action(function() {pull(orc); }); - 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);}); - app.command('branch [name]').alias('br').description('helper for creating branches').action(function(branchName) { createBranch(orc, branch_name); }); - app.command('status').alias('st').description('helper for getting status').action(function() { status(orc);}); // REMOVE - app.parse(argv); - console.log('main! '+JSON.stringify(argv)); - return true; -}; \ No newline at end of file + + 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); + }); +} + +exports.main = main; \ No newline at end of file diff --git a/test/orc-test.js b/test/orc-test.js index 62fdfdf..f6a8421 100644 --- a/test/orc-test.js +++ b/test/orc-test.js @@ -12,7 +12,10 @@ describe('no repo', function() { it('should fail in a directory without git', function() { tmp.dir(function(err, dir) { expect(err).to.be.null(); - expect(orc.main(dir, [])).to.be.false(); + orc.main(dir, [], function(err, res) { + expect(err).not.to.be.null(); + expect(res).to.be.undefined(); + }); }); }); }); @@ -27,52 +30,92 @@ describe('basic repo', function() { repo.addSync([fn]); repo.commitSync('foo'); - it('should start up properly in a new github repo', function() { - expect(orc.main(dir, ['node', 'orc'])).to.be.true(); + it('should start up properly in a new github repo', function(done) { + orc.main(dir, ['node', 'orc'], function(err, res) { + expect(err).to.be.null(); + expect(res).to.be.true(); + done(); + }); }); }); }); describe('remote tests', function() { + var gitserver; var repo; - var repo_dir; - var server_dir; + var repo2; + var repoDir; + var rootDir; + var repoName = 'orctest'; + var branchName = 'foobranch'; // create a simple git server listener before(function(done) { tmp.dir(function(err, dir) { - server_dir = dir; - repo_dir = path.resolve(dir,'orctest1'); - fs.mkdirSync(repo_dir); + rootDir = dir; + repoDir = path.resolve(dir,repoName); + fs.mkdirSync(repoDir); - repo = git(repo_dir); + repo = git(repoDir); repo.initSync(); - repo.addRemoteSync('local', 'http://localhost:7001/server'); - var repos = pushover(dir); - repos.on('push', function(push) { + repo.addRemoteSync('origin', 'http://localhost:7001/server'); + var gitserver = pushover(dir); + gitserver.on('push', function(push) { push.accept(); }); + gitserver.on('fetch', function (fetch) { + fetch.accept(); + }); require('http').createServer(function(req, res) { - repos.handle(req, res); + gitserver.handle(req, res); }).listen(7001, function() { done(); }); }); }); - it('should push to the remote', function(done) { - console.log('server dir: '+server_dir); - repo.push('local', 'master', function(err, result) { - var fn = path.resolve(repo_dir,'foo.js'); - fs.writeFileSync(fn, 'o hai'); - repo.addSync([fn]); - repo.commitSync('bar'); - expect(fs.existsSync(path.resolve(server_dir,'server.git'))).to.be.true(); + // this is expected to have been done outside of orc + it('should create the master branch and push it', function(done) { + var fn = path.resolve(repoDir,'foo.js'); + fs.writeFileSync(fn, 'o hai'); + repo.addSync([fn]); + repo.commitSync('bar'); + repo.push('origin', 'master', function(err, result) { + expect(fs.existsSync(path.resolve(rootDir,'server.git'))).to.be.true(); + done(); + }); + }); + it('should create a branch based off of the latest commit on master', function(done) { + orc.main(repoDir,['node','orc','branch',branchName], function(err, res) { + expect(repo.getBranchesSync().current).to.equal(branchName); done(); }); }); - it('should create a branch based off of the latest commit on master', function() { - + it('should have pushed the branch so it is visible to others', function(done) { + tmp.dir(function(err, dir) { + expect(err).to.be.null(); + //console.log('root dir: '+rootDir); + //console.log('repo2 root: '+dir); + var repo2_dir = path.resolve(dir,dir); + git.clone(repo2_dir, 'http://localhost:7001/server', function(err) { + expect(err).to.be.null(); + repo2 = git(repo2_dir); + repo2.pull('origin','master',['-a'], function(err, res) { + var co_res = repo2.checkoutSync(branchName); + expect(co_res).to.be.ok(); + done(); + }); + }); + }); + }); + it('should checkpoint properly', function() { + var fn = path.resolve(repoDir,'bar.js'); + fs.writeFileSync(fn, 'o hai'); + orc.main(repoDir, ['node','orc','checkpoint'], function(err, res) { + expect(err).to.be.ok(); + expect(res).to.be.undefined(); + }); }); + // createBranch test: success and failure }); /* describe('github tests', function() { From 8ba695dc67dbc8580dfb67de999f403a0a6c1fb0 Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 19:52:05 -0800 Subject: [PATCH 4/9] ORC-CHECKPOINT --- orc.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/orc.js b/orc.js index 01d1555..7ae3983 100644 --- a/orc.js +++ b/orc.js @@ -38,7 +38,7 @@ function noUnstaged(orc, cb) { }); } -function noUncommitted(orc, cb) { +function noUntracked(orc, cb) { orc.repo.status(function(err, status) { if(err) { cb('error getting status checking unstaged '+err); @@ -58,7 +58,7 @@ function repoIsClean(orc, cb) { cb(err); return; } - noUncommitted(orc, function(err, res) { + noUntracked(orc, function(err, res) { if(err) { cb(err); return; @@ -71,14 +71,14 @@ function repoIsClean(orc, cb) { // commit local changes // push to remote function checkpoint(orc, cb) { - orc.repo.status(function(err, res) { + noUntracked(orc, function(err, res) { if(err) { - cb('error getting status'+err); + cb('you have unstaged files: '+err); return; } - orc.repo.commit('ORC-CHECKPOINT', function(err, res) { + orc.repo.commit('ORC-CHECKPOINT', ['-a', '--no-verify'], function(err, res) { if(err) { - cb('checkpoint commit failed '+res); + cb('checkpoint commit failed: \n'+err.message); return; } orc.repo.push('origin', 'master', function(err, result) { @@ -108,22 +108,22 @@ function createBranch(orc, branchName, cb) { } orc.repo.checkout('master', function(err, res) { if(err) { - cb('failed to checkout master'+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: '+JSON.stringify(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); + cb('failed to create branch '+branchName)+': '+err.message; return; } orc.repo.checkout(branchName, function(err, res) { if(err) { - cb('couldn\'t checkout branch '+branchName); + cb('couldn\'t checkout branch '+branchName+': '+err.message); return; } orc.repo.push('origin', branchName, ['--set-upstream'], cb); @@ -154,7 +154,7 @@ function main(dir, argv, cb) { if(!cb) { cb = function(err, res) { if(err) { - console.err('error: '+JSON.stringify(err)); + console.log('error: '+err); } else { // TODO: standardize result text and output console.log('done. '+res); From 249ae332b4b48bac40cacad87f08d45fcdf57073 Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 19:58:08 -0800 Subject: [PATCH 5/9] ORC-CHECKPOINT --- orc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/orc.js b/orc.js index d58e5bb..5af3027 100644 --- a/orc.js +++ b/orc.js @@ -181,5 +181,6 @@ function main(dir, argv, cb) { app.parse(argv); }); } +// orc checkpoint change exports.main = main; From 74a33fbd03dd1fb1fb33ebc6acf88d36a7eee63e Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 20:01:34 -0800 Subject: [PATCH 6/9] ORC-CHECKPOINT --- orc.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/orc.js b/orc.js index 5af3027..4ed3d38 100644 --- a/orc.js +++ b/orc.js @@ -81,12 +81,18 @@ function checkpoint(orc, cb) { cb('checkpoint commit failed: \n'+err.message); return; } - orc.repo.push('origin', 'master', function(err, result) { - if (err) { - cb('error pushing checkpoint: '+JSON.stringify(err)); + orc.repo.getBranches(function(err, branches) { + if(err) { + cb('error getting branches: '+err.message); return; } - cb(null, true); + orc.repo.push('origin', branches.current, function(err, result) { + if (err) { + cb('error pushing checkpoint: '+err.message); + return; + } + cb(null, true); + }); }); }); }); From 097bb36fb00c4e93e95bcfb483bf27d49b5d12b9 Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 20:01:52 -0800 Subject: [PATCH 7/9] ORC-CHECKPOINT --- orc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orc.js b/orc.js index 4ed3d38..052e970 100644 --- a/orc.js +++ b/orc.js @@ -91,7 +91,7 @@ function checkpoint(orc, cb) { cb('error pushing checkpoint: '+err.message); return; } - cb(null, true); + cb(null, 'checkpoint finished.'); }); }); }); From eb45ec0046d6fdf5ecc324905f0b66cd5a38e5ba Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 21:02:29 -0800 Subject: [PATCH 8/9] ORC-CHECKPOINT --- orc.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/orc.js b/orc.js index 052e970..d40fb31 100644 --- a/orc.js +++ b/orc.js @@ -68,6 +68,20 @@ function repoIsClean(orc, cb) { }); } +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) { From 593e1e7d1952c6f290d77157f7e1db604e54d26b Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Wed, 11 Feb 2015 21:03:26 -0800 Subject: [PATCH 9/9] ORC-CHECKPOINT --- orc.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/orc.js b/orc.js index d40fb31..b76ac83 100644 --- a/orc.js +++ b/orc.js @@ -90,22 +90,28 @@ function checkpoint(orc, cb) { cb('you have unstaged files: '+err); return; } - orc.repo.commit('ORC-CHECKPOINT', ['-a', '--no-verify'], function(err, res) { + repoHasChanges(orc, function(err, res) { if(err) { - cb('checkpoint commit failed: \n'+err.message); + cb(err); return; } - orc.repo.getBranches(function(err, branches) { + orc.repo.commit('ORC-CHECKPOINT', ['-a', '--no-verify'], function(err, res) { if(err) { - cb('error getting branches: '+err.message); + cb('checkpoint commit failed: \n'+err.message); return; } - orc.repo.push('origin', branches.current, function(err, result) { - if (err) { - cb('error pushing checkpoint: '+err.message); + orc.repo.getBranches(function(err, branches) { + if(err) { + cb('error getting branches: '+err.message); return; } - cb(null, 'checkpoint finished.'); + orc.repo.push('origin', branches.current, function(err, result) { + if (err) { + cb('error pushing checkpoint: '+err.message); + return; + } + cb(null, 'checkpoint finished.'); + }); }); }); });