showBranch.js 594 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var log = require('fancy-log');
  3. var exec = require('child_process').exec;
  4. module.exports = function (opt, cb) {
  5. if (!cb && typeof opt === 'function') {
  6. // optional options
  7. cb = opt;
  8. opt = {};
  9. }
  10. if (!cb || typeof cb !== 'function') cb = function () {};
  11. if (!opt) opt = {};
  12. if (!opt.cwd) opt.cwd = process.cwd();
  13. if (!opt.args) opt.args = ' ';
  14. var cmd = 'git show-branch ' + opt.args;
  15. return exec(cmd, {cwd: opt.cwd}, function(err, stdout, stderr) {
  16. if (err) return cb(err);
  17. if (!opt.quiet) log(stdout, stderr);
  18. cb(null, stdout);
  19. });
  20. };