status.js 741 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var log = require('fancy-log');
  3. var exec = require('child_process').exec;
  4. module.exports = function (opt, cb) {
  5. if (!cb && typeof opt === 'function') {
  6. // optional options
  7. cb = opt;
  8. opt = {};
  9. }
  10. if (!cb || typeof cb !== 'function') cb = function () {};
  11. if (!opt) opt = {};
  12. if (!opt.cwd) opt.cwd = process.cwd();
  13. if (!opt.args) opt.args = ' ';
  14. if (!opt.maxBuffer) opt.maxBuffer = 200 * 1024; // Default buffer value for child_process.exec
  15. var cmd = 'git status ' + opt.args;
  16. return exec(cmd, {cwd : opt.cwd, maxBuffer: opt.maxBuffer}, function(err, stdout, stderr) {
  17. if (err) return cb(err, stderr);
  18. if (!opt.quiet) log(cmd + '\n' + stdout, stderr);
  19. if (cb) cb(err, stdout);
  20. });
  21. };