<commit_before>const git = require('simple-git')()
const fs = require('fs')
const exec = require('child_process').exec

const remote = 'origin'
const branch = 'staging'
const fileDoesNotExist = 'ENOENT'
const successInitMessage = 'init written successfully'

module.exports = {
  commit: (userDir, message) => new Promise((resolve, reject) => {
    // deletes package.json
    if (fs.existsSync(`${userDir}/package.json`)) {
      fs.unlink(`${userDir}/package.json`, (err) => {
        if (err && err.code !== fileDoesNotExist) {
          reject(err)
        }
      })
    }

    // generates a new package.json based on node_modules
    exec('npm init -y', { cwd: userDir }, (error, stdout, stderr) => {
      if (error) {
        reject(error)
      } else if (stderr && !stderr.includes(successInitMessage)) {
        reject(stderr)
      } else {
        // commits and pushes all changes to the remote branch
        git.add('--all').commit(message).push(remote, branch, (ex, data) => {
          if (ex) {
            reject(ex)
          } else {
            resolve(data)
          }
        })
      }
    })
  }),

  createLocalRepo: (userDir) => new Promise((resolve, reject) => {
    if (!fs.existsSync(`${userDir}/.git`)) {
      git.init((err) => {
        if (err) {
          reject(err)
        } else {
          resolve()
        }
      })
    }
  }),

  sendFile: (res, filename) => {
    // Use the right function depending on Express 3.x/4.x
    if (res.sendFile) {
      res.sendFile(filename)
    } else {
      res.sendfile(filename)
    }
  },

  tags: () => new Promise((resolve, reject) => {
    git.tags({}, (err, tags) => {
      if (err) {
        reject(err)
      } else {
        resolve(tags)
      }
    })
  }),

  logs: branchName => new Promise((resolve, reject) => {
    git.log([branchName], (err, result) => {
      if (err) {
        reject(err)
      } else {
        resolve(result)
      }<commit_msg>ref(git-ui): Remove console log in the function createLocalRepo<commit_after>const git = require('simple-git')()
const fs = require('fs')
const exec = require('child_process').exec

const remote = 'origin'
const branch = 'staging'
const fileDoesNotExist = 'ENOENT'
const successInitMessage = 'init written successfully'

module.exports = {
  commit: (userDir, message) => new Promise((resolve, reject) => {
    // deletes package.json
    if (fs.existsSync(`${userDir}/package.json`)) {
      fs.unlink(`${userDir}/package.json`, (err) => {
        if (err && err.code !== fileDoesNotExist) {
          reject(err)
        }
      })
    }

    // generates a new package.json based on node_modules
    exec('npm init -y', { cwd: userDir }, (error, stdout, stderr) => {
      if (error) {
        reject(error)
      } else if (stderr && !stderr.includes(successInitMessage)) {
        reject(stderr)
      } else {
        // commits and pushes all changes to the remote branch
        git.add('--all').commit(message).push(remote, branch, (ex, data) => {
          if (ex) {
            reject(ex)
          } else {
            resolve(data)
          }
        })
      }
    })
  }),

  createLocalRepo: (userDir) => new Promise((resolve, reject) => {
    if (!fs.existsSync(`${userDir}/.git`)) {
      git.init()
    }
  }),

  sendFile: (res, filename) => {
    // Use the right function depending on Express 3.x/4.x
    if (res.sendFile) {
      res.sendFile(filename)
    } else {
      res.sendfile(filename)
    }
  },

  tags: () => new Promise((resolve, reject) => {
    git.tags({}, (err, tags) => {
      if (err) {
        reject(err)
      } else {
        resolve(tags)
      }
    })
  }),

  logs: branchName => new Promise((resolve, reject) => {
    git.log([branchName], (err, result) => {
      if (err) {
        reject(err)
      } else {
        resolve(result)
      }
{'fraction_non_alphanumeric': 0.1627665106604264, 'fraction_numerical': 0.0010400416016640667, 'mean_word_length': 2.1455437448896157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '193481', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1210, 'n_words': 276}