Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qw3rtman/gg
Browse files Browse the repository at this point in the history
  • Loading branch information
qw3rtman committed Aug 7, 2015
2 parents 33e4eaa + 1d03b50 commit 58c5f56
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 124 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,4 @@ Fork our code, make a new branch, and send a pull request.
* undo last commit
* add custom files/directories to .gitignore
* **introduction scene to Git** (for those new to Git)
* [switch to previously selected branch](https://github.com/qw3rtman/gg/issues/40)
251 changes: 127 additions & 124 deletions bin/gg
Original file line number Diff line number Diff line change
Expand Up @@ -9,130 +9,133 @@ var cli = require('cli');

cli.parse(null, ['v', 'version', '-v', '--version', 'i', 'init', 'initialize', 'ig', 'ignore', 'cl', 'clone', 'a', 'aa', 'add', 'c', 'ci', 'commit', 'cn', 'commitnoadd', 'p', 'push', 'pl', 'pull', 'f', 'fetch', 'fa', 's', 'status', 'l', 'log', 'b', 'branch', 'ch', 'checkout']);

switch (cli.command) {
// Version.
case 'v':
case 'version':
case '-v':
case '--version':
gg.version();
break;

// Initialize.
case 'i':
case 'init':
case 'initialize':
gg.init();
break;

// .gitignores.
case 'ig':
case 'ignore':
var template = cli.args.join('-');

gg.ignore(template);
break;

// Clone.
case 'cl':
case 'clone':
var repository = cli.args[0];

if (typeof repository === 'undefined') {
repository = '';
}

if (repository.substring(0, 7) === 'http://' || repository.substring(0, 8) === 'https://') { // URL.
gg.clone(repository);
} else if (repository.indexOf('@') > -1 && repository.indexOf(':') > -1) { // SSH.
gg.clone(repository);
} else {
gg.cloneGitHub(repository);
}
break;

// Add.
case 'a':
case 'add':
if (cli.args[1] === '' || typeof cli.args[1] !== 'undefined') {
var options = cli.args[0];
var target = cli.args[1];
gg.addOptions(options, target);
} else {
var target = cli.args[0];
gg.addSingle(target);
}
break;

// Add all.
case 'aa': // Short for 'add all'.
gg.addAll();
break;

// Commit.
case 'c':
case 'ci':
case 'commit':
var message = cli.args.join(' ');
gg.commit(message, true);
break;

// Commit without adding.
case 'cn':
var message = cli.args.join(' ');
gg.commit(message, false);
break;

// Push.
case 'p':
case 'push':
gg.push();
break;

// Pull.
case 'pl':
case 'pull':
gg.pull();
break;

// Fetch.
case 'f':
case 'fetch':
gg.fetch();
break;

// Fetch all.
case 'fa': // Short for 'fetch --all'.
gg.fetchAll();
break;

// Status.
case 's':
case 'st':
case 'status':
gg.status();
break;

// Log.
case 'l':
case 'log':
var file = cli.args.join(' ');
gg.log(file);
break;

// Branch.
case 'b':
case 'branch':
var branch = cli.args.join('-');
gg.branch(branch);
break;

// Checkout.
case 'ch':
case 'checkout':
var branch = cli.args.join('-');
gg.checkout(branch);
break;
gg.repoCheck(parseCommand);
function parseCommand() {
switch (cli.command) {
// Version.
case 'v':
case 'version':
case '-v':
case '--version':
gg.version();
break;

// Initialize.
case 'i':
case 'init':
case 'initialize':
gg.init();
break;

// .gitignores.
case 'ig':
case 'ignore':
var template = cli.args.join('-');

gg.ignore(template);
break;

// Clone.
case 'cl':
case 'clone':
var repository = cli.args[0];

if (typeof repository === 'undefined') {
repository = '';
}

if (repository.substring(0, 7) === 'http://' || repository.substring(0, 8) === 'https://') { // URL.
gg.clone(repository);
} else if (repository.indexOf('@') > -1 && repository.indexOf(':') > -1) { // SSH.
gg.clone(repository);
} else {
gg.cloneGitHub(repository);
}
break;

// Add.
case 'a':
case 'add':
if (cli.args[1] === '' || typeof cli.args[1] !== 'undefined') {
var options = cli.args[0];
var target = cli.args[1];
gg.addOptions(options, target);
} else {
var target = cli.args[0];
gg.addSingle(target);
}
break;

// Add all.
case 'aa': // Short for 'add all'.
gg.addAll();
break;

// Commit.
case 'c':
case 'ci':
case 'commit':
var message = cli.args.join(' ');
gg.commit(message, true);
break;

// Commit without adding.
case 'cn':
var message = cli.args.join(' ');
gg.commit(message, false);
break;

// Push.
case 'p':
case 'push':
gg.push();
break;

// Pull.
case 'pl':
case 'pull':
gg.pull();
break;

// Fetch.
case 'f':
case 'fetch':
gg.fetch();
break;

// Fetch all.
case 'fa': // Short for 'fetch --all'.
gg.fetchAll();
break;

// Status.
case 's':
case 'st':
case 'status':
gg.status();
break;

// Log.
case 'l':
case 'log':
var file = cli.args.join(' ');
gg.log(file);
break;

// Branch.
case 'b':
case 'branch':
var branch = cli.args.join('-');
gg.branch(branch);
break;

// Checkout.
case 'ch':
case 'checkout':
var branch = cli.args.join('-');
gg.checkout(branch);
break;
}
}

gg.upToDate(false, true);
9 changes: 9 additions & 0 deletions lib/gg.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,12 @@ exports.checkout = function(branch) {
});
}
};

exports.repoCheck = function(callback) {
exec('git rev-parse', function(error, stdout, stderr) {
if (stderr.length === 0) {
return callback();
}
console.log(whoops('[✖] Not in a valid git repository! Run "gg i" to initialise one.'));
});
};

0 comments on commit 58c5f56

Please sign in to comment.