addRemote.js 898 B

12345678910111213141516171819202122232425262728
  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, url, opt, cb) {
  6. if (!cb && typeof opt === 'function') {
  7. // optional options
  8. cb = opt;
  9. opt = {};
  10. }
  11. if (!cb || typeof cb !== 'function') cb = function () {};
  12. if (!url) return cb(new Error('gulp-git: Repo URL is required git.addRemote("origin", "https://github.com/user/repo.git")'));
  13. if (!remote) remote = 'origin';
  14. if (!opt) opt = {};
  15. if (!opt.cwd) opt.cwd = process.cwd();
  16. if (!opt.args) opt.args = ' ';
  17. var maxBuffer = opt.maxBuffer || 200 * 1024;
  18. var cmd = 'git remote add ' + opt.args + ' ' + escape([remote, url]);
  19. return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
  20. if (err) return cb(err);
  21. if (!opt.quiet) log(stdout, stderr);
  22. cb();
  23. });
  24. };