clean.js 899 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var log = require('fancy-log');
  3. var exec = require('child_process').exec;
  4. var escape = require('any-shell-escape');
  5. module.exports = function (paths, opt, cb) {
  6. if (!cb) {
  7. if (typeof opt === 'function') {
  8. // passed in 2 arguments
  9. cb = opt;
  10. if (typeof paths === 'object') {
  11. opt = paths;
  12. paths = '';
  13. }
  14. else opt = {};
  15. }
  16. else {
  17. // passed in only cb
  18. cb = paths;
  19. paths = '';
  20. opt = {};
  21. }
  22. }
  23. if (!opt.cwd) opt.cwd = process.cwd();
  24. if (!opt.args) opt.args = ' ';
  25. var cmd = 'git clean ' + opt.args + ' ' + (paths.trim() ? (' -- ' + escape(paths)) : '');
  26. var maxBuffer = opt.maxBuffer || 200 * 1024;
  27. return exec(cmd, { cwd: opt.cwd, maxBuffer: maxBuffer }, function (err, stdout, stderr) {
  28. if (err)
  29. return cb(err);
  30. if (!opt.quiet)
  31. log(stdout, stderr);
  32. cb();
  33. });
  34. };