pull.js 1006 B

12345678910111213141516171819202122232425262728293031323334353637
  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 (remote, branch, opt, cb) {
  6. if (!cb && typeof opt === 'function') {
  7. // optional options
  8. cb = opt;
  9. opt = {};
  10. }
  11. // pull with callback only
  12. if (!cb && typeof remote === 'function') {
  13. cb = remote;
  14. remote = {};
  15. }
  16. if (!cb || typeof cb !== 'function') cb = function () {};
  17. if (!opt) opt = {};
  18. if (!opt.cwd) opt.cwd = process.cwd();
  19. if (!opt.args) opt.args = ' ';
  20. var cmd = 'git pull ' + opt.args;
  21. if (typeof remote === 'string') {
  22. cmd += ' ' + escape(remote);
  23. }
  24. if (branch && typeof branch === 'string' || branch && branch[0]) {
  25. cmd += ' ' + escape([].concat(branch));
  26. }
  27. var maxBuffer = opt.maxBuffer || 200 * 1024;
  28. return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
  29. if (err) return cb(err);
  30. if (!opt.quiet) log(stdout, stderr);
  31. cb();
  32. });
  33. };