Skip to content

Commit

Permalink
adding pull all
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Mar 10, 2017
1 parent 6682f38 commit 1ffaa3b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
12 changes: 10 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function setSearchTerm(options) {
let defaultToWild = _.pick(options, [
'completions',
'clone-all',
'force-latest'
'force-latest',
'pull-all'
]);
if (options._ && options._[0]) {
searchTerm = options._[0];
Expand Down Expand Up @@ -47,7 +48,7 @@ function mapToHandler(options) {
}
]).then((answers) => {
if (answers.confirm) {
return Promise.resolve(repos).map(handler).then(() => {
return Promise.resolve(repos).mapSeries(handler).then(() => {
return { repoDir: workspaceDir };
});
} else {
Expand Down Expand Up @@ -98,6 +99,13 @@ function cli(options) {
errorMessage: 'Force latest aborted',
handler: lib.forceLatest
});
} else if (results.length && options['pull-all']) {
return mapToHandler({
results,
confirmMessage: 'Are you sure you want pull all of the above?',
errorMessage: 'Pull all aborted',
handler: (r) => lib.maybeClone(r).then(lib.maybePull)
});
} else if (results.length > 1) {
resultPromise = inquirer.prompt([
{
Expand Down
4 changes: 2 additions & 2 deletions lib/forceLatest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const output = require('./output');
module.exports = forceLatest;

function forceLatest(sourceResult) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
if (fs.existsSync(sourceResult.repoDir)) {
let git = gitFactory.getInstance(sourceResult.repoDir);
return git.fetch([ 'origin' ], (fetchErr) => {
if (fetchErr) output.log('Error trying to fetch ' + sourceResult.clone + '. Message: ' + fetchErr);
git.reset([ '--hard', 'origin/master' ], (resetErr) => {
if (resetErr) output.log('Error trying to reset hard to origin/master for ' + sourceResult.clone + '. Message: ' + resetErr);
return git.clean('f', [ '-d' ], (cleanErr) => {
if (cleanErr) return reject(cleanErr);
output.error(cleanErr);
git = null;
return resolve(sourceResult);
});
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.getPaths = require('./getPaths');
exports.getSourceData = require('./getSourceData');
exports.getSourceResult = require('./getSourceResult');
exports.maybeClone = require('./maybeClone');
exports.maybePull = require('./maybePull');
exports.forceLatest = require('./forceLatest');
exports.openInBrowser = require('./openInBrowser');
exports.workspaceDir = require('./workspaceDir');
Expand Down
5 changes: 3 additions & 2 deletions lib/maybeClone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const workspaceDir = require('./workspaceDir');
const output = require('./output');
const gitFactory = require('./gitFactory');
let git;

Expand All @@ -12,10 +13,10 @@ function maybeClone(sourceResult) {
if (!git) {
git = gitFactory.getInstance(workspaceDir);
}
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
if (!fs.existsSync(sourceResult.repoDir)) {
return git.clone(sourceResult.clone, sourceResult.repoDir, (err, data) => {
if (err) return reject(err);
output.error(err);
return resolve(sourceResult);
});
} else {
Expand Down
26 changes: 26 additions & 0 deletions lib/maybePull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const workspaceDir = require('./workspaceDir');
const gitFactory = require('./gitFactory');
const output = require('./output');

module.exports = forceLatest;

function forceLatest(sourceResult) {
return new Promise((resolve) => {
if (fs.existsSync(sourceResult.repoDir)) {
let git = gitFactory.getInstance(sourceResult.repoDir);
return git.checkout('master', (checkoutErr) => {
output.error(checkoutErr);
return git.pull('origin', 'master', { '--rebase': true }, (pullErr, data) => {
output.error(pullErr);
return resolve(sourceResult);
});
});
} else {
return resolve(sourceResult);
}
});
}
8 changes: 8 additions & 0 deletions lib/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';
const chalk = require('chalk');
const _ = require('lodash');

module.exports = {
log: (...args) => {
console.log.apply(console, args);
},
error: (...args) => {
if (args[0] != null) {
console.error.apply(console, _.map(args, chalk.bold.red));
}
}
};

0 comments on commit 1ffaa3b

Please sign in to comment.