function gulpStatus() {
  const Vinyl = require('vinyl');
  const path = require('path');
  const gulpGit = require('gulp-git');
  const through = require('through2');
  const srcStream = through.obj();

  const opt = {cwd: process.cwd()};

  // https://git-scm.com/docs/git-status#_short_format
  const RE_STATUS = /((\s\w)|(\w+)|\?{0,2})\s([\w\+\-\/\\\.]+)(\s->\s)?([\w\+\-\/\\\.]+)*\n{0,1}/gm;

  gulpGit.status({args: '--porcelain', quiet: true}, function(err, stdout) {
    if (err) return srcStream.emit('error', err);

    const data = stdout.toString();
    let currentMatch;

    while ((currentMatch = RE_STATUS.exec(data)) !== null) {
      // status
      const status = currentMatch[1].trim().toLowerCase();

      // We only care about untracked files and renamed files
      if (!new RegExp(/r|\?/i).test(status)) {
        continue;
      }

      // file path
      const currentFilePath = currentMatch[4];

      // new file path in case its been moved
      const newFilePath = currentMatch[6];
      const filePath = newFilePath || currentFilePath;

      srcStream.write(new Vinyl({
        path: path.resolve(opt.cwd, filePath),
        cwd: opt.cwd,
      }));

      RE_STATUS.lastIndex++;
    }

    srcStream.end();
  });

  return srcStream;
}
function gulpStatus() {
  const Vinyl = require('vinyl');
  const path = require('path');
  const gulpGit = require('gulp-git');
  const through = require('through2');
  const srcStream = through.obj();

  const opt = {cwd: process.cwd()};

  // https://git-scm.com/docs/git-status#_short_format
  const RE_STATUS = /((\s\w)|(\w+)|\?{0,2})\s([\w\+\-\/\\\.]+)(\s->\s)?([\w\+\-\/\\\.]+)*\n{0,1}/gm;

  gulpGit.status({args: '--porcelain', quiet: true}, function(err, stdout) {
    if (err) return srcStream.emit('error', err);

    const data = stdout.toString();
    let currentMatch;

    while ((currentMatch = RE_STATUS.exec(data)) !== null) {
      // status
      const status = currentMatch[1].trim().toLowerCase();

      // We only care about untracked files and renamed files
      if (!new RegExp(/r|\?/i).test(status)) {
        continue;
      }

      // file path
      const currentFilePath = currentMatch[4];

      // new file path in case its been moved
      const newFilePath = currentMatch[6];
      const filePath = newFilePath || currentFilePath;

      srcStream.write(new Vinyl({
        path: path.resolve(opt.cwd, filePath),
        cwd: opt.cwd,
      }));

      RE_STATUS.lastIndex++;
    }

    srcStream.end();
  });

  return srcStream;
}
function gulpStatus ( ) { const Vinyl = require ( 'vinyl' ) ; const path = require ( 'path' ) ; const gulpGit = require ( 'gulp-git' ) ; const through = require ( 'through2' ) ; const srcStream = through . obj ( ) ; const opt = { cwd : process . cwd ( ) } ; // https://git-scm.com/docs/git-status#_short_format const RE_STATUS = / ((\s\w)|(\w+)|\?{0,2})\s([\w\+\-\/\\\.]+)(\s->\s)?([\w\+\-\/\\\.]+)*\n{0,1} / gm ; gulpGit . status ( { args : '--porcelain' , quiet : true } , function ( err , stdout ) { if ( err ) return srcStream . emit ( 'error' , err ) ; const data = stdout . toString ( ) ; let currentMatch ; while ( ( currentMatch = RE_STATUS . exec ( data ) ) !== null ) { // status const status = currentMatch [ 1 ] . trim ( ) . toLowerCase ( ) ; // We only care about untracked files and renamed files if ( ! new RegExp ( / r|\? / i ) . test ( status ) ) { continue ; } // file path const currentFilePath = currentMatch [ 4 ] ; // new file path in case its been moved const newFilePath = currentMatch [ 6 ] ; const filePath = newFilePath || currentFilePath ; srcStream . write ( new Vinyl ( { path : path . resolve ( opt . cwd , filePath ) , cwd : opt . cwd , } ) ) ; RE_STATUS . lastIndex ++ ; } srcStream . end ( ) ; } ) ; return srcStream ; }
Gulp stream that wraps the gulp-git status,
only returns untracked files, and converts
the stdout into a stream of files.
Gulp stream that wraps the gulp - git status only returns untracked files and converts the stdout into a stream of files .
Gulp status function