-
Notifications
You must be signed in to change notification settings - Fork 0
Orc checkpoint #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abrady0
wants to merge
10
commits into
master
Choose a base branch
from
orc_checkpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
adeb582
cp
abrady0 5048a7a
framework and some basic functionality, incorporate feedback
abrady0 1086580
framework and some basic functionality, incorporate feedback
abrady0 8ba695d
ORC-CHECKPOINT
abrady0 2544ade
merge
abrady0 249ae33
ORC-CHECKPOINT
abrady0 74a33fb
ORC-CHECKPOINT
abrady0 097bb36
ORC-CHECKPOINT
abrady0 eb45ec0
ORC-CHECKPOINT
abrady0 593e1e7
ORC-CHECKPOINT
abrady0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| 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)}); | ||
| }); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
@@ -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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.