<commit_before>
/* IMPORT */

import * as _ from 'lodash';
import * as  fs from 'fs';
import * as path from 'path';
import Utils from '../../utils';

/* GIT CACHE */

let cache;

const DirtyGitCache = {

  filename: '.vscode-projects-plus_dirty-git-cache.json',

  read () {
    return Utils.cache.read ( DirtyGitCache.filename );
  },

  write ( content ) {
    return Utils.cache.write ( DirtyGitCache.filename, content );
  },

  delete () {
    cache = undefined;
    return Utils.cache.delete ( DirtyGitCache.filename );
  }

};

/* GIT */

async function fetchDirtyGit ( folderpath, updateCache = true ) {

  let returnVal;

  const gitPath = path.join ( folderpath, '.git' ),
        stat = await Utils.file.stat ( gitPath );

  if ( stat ) {

    if ( !cache ) cache = await DirtyGitCache.read ();

    if ( cache[folderpath] && !_.isNull ( cache[folderpath].dirty ) && cache[folderpath].timestamp >= new Date ( stat.mtime ).getTime () ) {

      returnVal = cache[folderpath].dirty;

    } else {

      const commandOptions = {
        cwd: folderpath,
        encoding: 'utf8'
      };

      const command = 'git diff-index --quiet HEAD -- || echo "dirty"',
            result = await Utils.exec ( command, commandOptions, null );

      let dirty = _.isNull ( result ) ? result : !!result;

      if ( !_.isNull ( dirty ) && !dirty ) {

        const command = 'git ls-files --other --directory --no-empty-directory --exclude-standard',
              result = await Utils.exec ( command, commandOptions, null );

        dirty = _.isNull ( result ) ? result : !!result;

      }

      cache[folderpath] = {
        timestamp: new Date ().getTime (),
        dirty
      };

      returnVal = dirty;

    }

  }

  if ( updateCache ) await DirtyGitCache.write ( cache );

  return returnVal;

}

/* EXPORT */

export {DirtyGitCache, fetchDirtyGit};
<commit_msg>Git: updated command for checking for dirtiness<commit_after>
/* IMPORT */

import * as _ from 'lodash';
import * as  fs from 'fs';
import * as path from 'path';
import Utils from '../../utils';

/* GIT CACHE */

let cache;

const DirtyGitCache = {

  filename: '.vscode-projects-plus_dirty-git-cache.json',

  read () {
    return Utils.cache.read ( DirtyGitCache.filename );
  },

  write ( content ) {
    return Utils.cache.write ( DirtyGitCache.filename, content );
  },

  delete () {
    cache = undefined;
    return Utils.cache.delete ( DirtyGitCache.filename );
  }

};

/* GIT */

async function fetchDirtyGit ( folderpath, updateCache = true ) {

  let returnVal;

  const gitPath = path.join ( folderpath, '.git' ),
        stat = await Utils.file.stat ( gitPath );

  if ( stat ) {

    if ( !cache ) cache = await DirtyGitCache.read ();

    if ( cache[folderpath] && !_.isNull ( cache[folderpath].dirty ) && cache[folderpath].timestamp >= new Date ( stat.mtime ).getTime () ) {

      returnVal = cache[folderpath].dirty;

    } else {

      const command = 'git status --porcelain --untracked-files | tail -n1',
            commandOptions = {
              cwd: folderpath,
              encoding: 'utf8'
            },
            result = await Utils.exec ( command, commandOptions, null ),
            dirty = _.isNull ( result ) ? result : !!result;

      cache[folderpath] = {
        timestamp: new Date ().getTime (),
        dirty
      };

      returnVal = dirty;

    }

  }

  if ( updateCache ) await DirtyGitCache.write ( cache );

  return returnVal;

}

/* EXPORT */

export {DirtyGitCache, fetchDirtyGit};

{'fraction_non_alphanumeric': 0.13879408418657566, 'fraction_numerical': 0.0008532423208191126, 'mean_word_length': 2.391513982642237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1277238', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1075, 'n_words': 279}