removeRemote.js 942 B

12345678910111213141516171819202122232425262728293031
  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, opt, cb) {
  6. if (!cb && typeof opt === 'function') {
  7. // optional options
  8. cb = opt;
  9. opt = {};
  10. }
  11. if (!remote || typeof remote !== 'string') {
  12. var error = new Error('gulp-git: remote is required git.removeRemote("origin")');
  13. if (!cb || typeof cb !== 'function') throw error;
  14. return cb(error);
  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 maxBuffer = opt.maxBuffer || 200 * 1024;
  21. var cmd = 'git remote remove ' + opt.args + ' ' + escape([remote]);
  22. return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
  23. if (err) return cb(err);
  24. if (!opt.quiet) log(stdout, stderr);
  25. cb();
  26. });
  27. };