<commit_before>import { stat } from 'fs';
import { join, basename } from 'path';

import { eachSeries } from 'async';
const simpleGit = require('simple-git');

import walk from './DirWalk';
const promisify = require('es6-promisify');

export class Repo {
  updateStatusTI: any;
  git: any;
  state: any;
  gitFetch: any;

  constructor (dir, callback) {
    this.state = {
      dir: dir,
      name: basename(dir),
      branch: '',
      ahead: 0,
      behind: 0,
      modified: [],
      added: []
    };

    this.validateDir(dir, (err) => {
      if (!err) {
        this.git = simpleGit(dir);
        // PROMISIFY THIS SHIT
        this.git.fetch = promisify(this.git.fetch.bind(this.git));
        this.git.pull = promisify(this.git.pull.bind(this.git));
        this.git.status = promisify(this.git.status.bind(this.git));
        this.git.stash = promisify(this.git.stash.bind(this.git));
        this.git.push = promisify(this.git.push.bind(this.git));
        callback(null);
      } else {
        callback(err);
      }
    });
  }

  updateStatus () {
    return this.git.status()
    .then(status => new Promise((resolve) => {
      let newState = this.state;
      newState.lastUpdate = Date.now();
      newState.ahead = status.ahead;
      newState.behind = status.behind;

      newState.created = status.created || [];
      newState.modified = status.modified || [];
      newState.deleted = status.deleted || [];
      newState.renamed = status.renamed || [];
      newState.untracked = status.not_added || [];

      newState.files = status.files.map(file => {
        return {
          path: file.path,
          staged: file.index !== ' ' && file.index !== '?',
          type: file.index !== ' ' && file.index !== '?' ? file.index : file.working_dir
        };
      });

      newState.unstaged = newState.files
        .filter(f => !f.staged);

      newState.staged = newState.files
        .filter(f => f.staged);

      newState.branch = status.tracking ? status.tracking.replace('origin/', '') : '-';

      console.log(newState, status);

      this.state = newState;
      resolve(newState);
    }));
  }

  fetch () {
    return this.git.fetch()
    .then(() => this.updateStatus());
  }

  refresh () {
    // git log origin/master --pretty=format:"%H"

    // this.git.listRemote(['--heads'], (err, remoteHeads) => {
    //   console.log(err, remoteHeads);
    //   this.updateStatus(callback, { remoteHeads });
    // })

    return this.git.fetch()
    .then(() => this.updateStatus());
  }

  pull () {
    return this.git.pull(null, null, {'--rebase': 'true'})<commit_msg>cleanup logs<commit_after>import { stat } from 'fs';
import { join, basename } from 'path';

import { eachSeries } from 'async';
const simpleGit = require('simple-git');

import walk from './DirWalk';
const promisify = require('es6-promisify');

export class Repo {
  updateStatusTI: any;
  git: any;
  state: any;
  gitFetch: any;

  constructor (dir, callback) {
    this.state = {
      dir: dir,
      name: basename(dir),
      branch: '',
      ahead: 0,
      behind: 0,
      modified: [],
      added: []
    };

    this.validateDir(dir, (err) => {
      if (!err) {
        this.git = simpleGit(dir);
        // PROMISIFY THIS SHIT
        this.git.fetch = promisify(this.git.fetch.bind(this.git));
        this.git.pull = promisify(this.git.pull.bind(this.git));
        this.git.status = promisify(this.git.status.bind(this.git));
        this.git.stash = promisify(this.git.stash.bind(this.git));
        this.git.push = promisify(this.git.push.bind(this.git));
        callback(null);
      } else {
        callback(err);
      }
    });
  }

  updateStatus () {
    return this.git.status()
    .then(status => new Promise((resolve) => {
      let newState = this.state;
      newState.lastUpdate = Date.now();
      newState.ahead = status.ahead;
      newState.behind = status.behind;

      newState.created = status.created || [];
      newState.modified = status.modified || [];
      newState.deleted = status.deleted || [];
      newState.renamed = status.renamed || [];
      newState.untracked = status.not_added || [];

      newState.files = status.files.map(file => {
        return {
          path: file.path,
          staged: file.index !== ' ' && file.index !== '?',
          type: file.index !== ' ' && file.index !== '?' ? file.index : file.working_dir
        };
      });

      newState.unstaged = newState.files
        .filter(f => !f.staged);

      newState.staged = newState.files
        .filter(f => f.staged);

      newState.branch = status.tracking ? status.tracking.replace('origin/', '') : '-';

      // console.log(newState, status);

      this.state = newState;
      resolve(newState);
    }));
  }

  fetch () {
    return this.git.fetch()
    .then(() => this.updateStatus());
  }

  refresh () {
    // git log origin/master --pretty=format:"%H"

    // this.git.listRemote(['--heads'], (err, remoteHeads) => {
    //   console.log(err, remoteHeads);
    //   this.updateStatus(callback, { remoteHeads });
    // })

    return this.git.fetch()
    .then(() => this.updateStatus());
  }

  pull () {
    return this.git.pull(null, null, {'--rebase': 'true'})
{'fraction_non_alphanumeric': 0.1750095529231945, 'fraction_numerical': 0.0011463507833397019, 'mean_word_length': 2.3195941661382373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3607158', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1688, 'n_words': 304}