{"size": 2111, "ext": "js", "max_stars_repo_path": "source/git.js", "max_stars_repo_name": "antiwinter/wow-assistant", "max_stars_repo_stars_event_min_datetime": "2019-06-12T18:06:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T13:13:11.000Z", "max_issues_repo_path": "source/git.js", "max_issues_repo_name": "antiwinter/wow-assistant", "max_issues_repo_issues_event_min_datetime": "2019-06-22T08:07:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T23:45:19.000Z", "max_forks_repo_path": "source/git.js", "max_forks_repo_name": "antiwinter/wow-assistant", "max_forks_repo_forks_event_min_datetime": "2019-08-22T06:22:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T00:20:19.000Z"}
{"max_stars_count": 69, "max_issues_count": 49, "max_forks_count": 12, "avg_line_length": 25.130952381, "max_line_length": 136, "alphanum_fraction": 0.4073898626}
const sg = require('simple-git')()
const which = require('which')
const log = console.log

let git = {
  $scl: 'git',
  $lcl: /notpossiblyfind/,

  info(ad, done) {
    which('git', err => {
      if (err) {
        if (ad.source === 'git')
          log(
            'In order to install from arbitrary git, wowa requires git to be installed and that it can be called using the command git.'
          )
        return done()
      }
      sg.listRemote([ad.uri], (err, data) => {
        if (err) return done()

        let d = { 'refs/tags/': 1, 'refs/heads/': 1 }
        let info = {
          name: ad.uri,
          page: ad.uri,
          update: new Date() / 1000,
          version: []
        }

        for (k in d)
          data.split('\n').forEach(line => {
            // log('>>', line)
            if (line.match(/{}$/)) return
            if (line.match(k))
              info.version.unshift({
                name: line.slice(line.search(k) + k.length),
                hash: line.split('\t')[0]
              })
          })

        // log(info)
        done(info)
      })
    })
  },

  clone(uri, ref, to, hook) {
    sg.outputHandler((cmd, o1, o2) => {
      let unit = { KiB: 1024, MiB: 1 << 20, GiB: 1 << 30 }
      o2.on('data', line => {
        line
          .toString()
          .split('\r')
          .forEach(l => {
            if (!l.match(/Receiving objects/)) return
            let tr = /, [0-9\.]+ [KMG]iB \|/.exec(l)
            let evt = {
              percent:
                /\([0-9]+\//.exec(l)[0].slice(1, -1) /
                /\/[0-9]+\)/.exec(l)[0].slice(1, -1),
              transferred: !tr
                ? 0
                : tr[0].slice(2, -6) * unit[tr[0].slice(-5, -2)]
            }
            hook(evt)

            // log(evt, l)
          })
      })
    })
      .silent(true)
      .clone(
        uri,
        to,
        ['-b', ref, '--single-branch', '--depth', 1, '--progress', '--verbose'],
        (err, data) => {
          if (err) return hook(err.toString())
          else hook('done')
        }
      )
  }
}

module.exports = git
