<commit_before>/**
 * @module lib/git
 * @exports {Function} Git
 */
'use strict'

var Promise = require('bluebird')
var compose = require('101/compose')
var find = require('101/find')
var hasKeypaths = require('101/has-keypaths')
var pluck = require('101/pluck')
var simpleGit = require('simple-git')

class Git {
  constructor () {
    this._simpleGit = simpleGit(process.cwd())
    this._simpleGit.checkIgnore = Promise.promisify(this._simpleGit.checkIgnore)
    this._simpleGit.getRemotes = Promise.promisify(this._simpleGit.getRemotes)
    this._simpleGit.revparse = Promise.promisify(this._simpleGit.revparse)
  }
  /**
   * Fetch repository info of cwd, returns formatted object with selected properties
   * @param {Function} cb
   * @returns Promise - will resolve object:
   *   - branch: {String
   *   - orgName: {String}
   *   - repoName: {String}
   */
  fetchRepositoryInfo () {
    var fetchBranch = this._simpleGit.revparse(['--abbrev-ref', 'HEAD'])
      .then((status) => {
        return status.replace(/\n$/, '')
      })

    var fetchRemote = this._simpleGit.getRemotes(true)
      .then((remotes) => {
        var originRemote = find(remotes, hasKeypaths({name: 'origin'}))
        if (!originRemote) {
          throw new Error('No "origin" remote found for repository')
        }
        var matches = originRemote.refs.fetch.match(/(\:|\/)([A-z0-9-_]+)\/([A-z0-9-_]+)\.git$/)
        return {
          orgName: matches[2],
          repoName: matches[3]
        }
      })

    return Promise.join(fetchBranch, fetchRemote, (branch, remote) => {
      remote.branch = branch
      return remote
    })
  }

  /**
   * Check if a filepath is ignored by git according to .gitignore rules. Accounts for .gitignore
   * files in repository subdirectories.
   * @param {String} relativePath - relative path of file from repository root
   * @return Promise - will resolve Boolean
   */
  checkIgnore (relativePath) {
    return this._simpleGit.checkIgnore(relativePath)
      .then(compose(Boolean, pluck('length')))
  }
}

module.exports = Git<commit_msg>Fix bug with git refs no trailing .git<commit_after>/**
 * @module lib/git
 * @exports {Function} Git
 */
'use strict'

var Promise = require('bluebird')
var compose = require('101/compose')
var find = require('101/find')
var hasKeypaths = require('101/has-keypaths')
var pluck = require('101/pluck')
var simpleGit = require('simple-git')

class Git {
  constructor () {
    this._simpleGit = simpleGit(process.cwd())
    this._simpleGit.checkIgnore = Promise.promisify(this._simpleGit.checkIgnore)
    this._simpleGit.getRemotes = Promise.promisify(this._simpleGit.getRemotes)
    this._simpleGit.revparse = Promise.promisify(this._simpleGit.revparse)
  }
  /**
   * Fetch repository info of cwd, returns formatted object with selected properties
   * @param {Function} cb
   * @returns Promise - will resolve object:
   *   - branch: {String
   *   - orgName: {String}
   *   - repoName: {String}
   */
  fetchRepositoryInfo () {
    var fetchBranch = this._simpleGit.revparse(['--abbrev-ref', 'HEAD'])
      .then((status) => {
        return status.replace(/\n$/, '')
      })

    var fetchRemote = this._simpleGit.getRemotes(true)
      .then((remotes) => {
        var originRemote = find(remotes, hasKeypaths({name: 'origin'}))
        if (!originRemote) {
          throw new Error('No "origin" remote found for repository')
        }
        var matches = originRemote.refs.fetch.match(/(\:|\/)([A-z0-9-_]+)\/([A-z0-9-_]+)(\.git|)$/)
        return {
          orgName: matches[2],
          repoName: matches[3]
        }
      })

    return Promise.join(fetchBranch, fetchRemote, (branch, remote) => {
      remote.branch = branch
      return remote
    })
  }

  /**
   * Check if a filepath is ignored by git according to .gitignore rules. Accounts for .gitignore
   * files in repository subdirectories.
   * @param {String} relativePath - relative path of file from repository root
   * @return Promise - will resolve Boolean
   */
  checkIgnore (relativePath) {
    return this._simpleGit.checkIgnore(relativePath)
      .then(compose(Boolean, pluck('length')))
  }
}

module.exports = Git
{'fraction_non_alphanumeric': 0.1399235912129895, 'fraction_numerical': 0.008595988538681949, 'mean_word_length': 3.0086124401913876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6555122', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1285, 'n_words': 302}