checkoutFiles.js 765 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var through = require('through2');
  3. var log = require('fancy-log');
  4. var exec = require('child_process').exec;
  5. var escape = require('any-shell-escape');
  6. module.exports = function (opt) {
  7. if (!opt) opt = {};
  8. if (!opt.args) opt.args = ' ';
  9. function checkout(file, enc, cb) {
  10. var that = this;
  11. var cmd = 'git checkout ' + opt.args + ' ' + escape([file.path]);
  12. if (!cb || typeof cb !== 'function') cb = function () {};
  13. var maxBuffer = opt.maxBuffer || 200 * 1024;
  14. exec(cmd, {cwd: file.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
  15. if (err) return cb(err);
  16. if (!opt.quiet) log(stdout, stderr);
  17. that.push(file);
  18. cb(null);
  19. });
  20. }
  21. // Return a stream
  22. return through.obj(checkout);
  23. };