<commit_before>﻿const fs = require('fs');
const spawn = require('child_process').spawn;

/**
 * Helper function to determine if a git repo is already present in the directory.
 *
 * @param dir String - Directory to check.
 * @param callback Function (Object) - Callback returning an object with the origin git remote
 *										url at origin (May be empty).
 *										{ initialized: Boolean, url: String }
 *
 */
function exists(dir, callback) {
	fs.access(dir, fs.constants.F_OK, (err) => {
		const git = {
			initialised: false,
			remoteUrl: ''
		};

		if (err) {
			callback(git);
		}
		else {
			git.initialised = true;
			const gitConfig = spawn('git', ['config', '--get', 'remote.origin.url']);

			gitConfig.stdout.on('data', (data) => {
				git.url = data.toString('utf8').replace('\n', '');
			});

			gitConfig.on('close', () => {
				callback(git);
			});
		}
	});
}

function create(callback) {
	const gitInit = spawn('git', ['init']);

	gitInit.on('close', () => {<commit_msg>Change fs.access to fs.stat for backwards compatibility.<commit_after>﻿const fs = require('fs');
const spawn = require('child_process').spawn;

/**
 * Helper function to determine if a git repo is already present in the directory.
 *
 * @param dir String - Directory to check.
 * @param callback Function (Object) - Callback returning an object with the origin git remote
 *										url at origin (May be empty).
 *										{ initialized: Boolean, url: String }
 *
 */
function exists(dir, callback) {
	fs.stat(dir, (err, stats) => {
		const git = {
			initialised: false,
			remoteUrl: ''
		};

		// Err implies that the directory does not exist.
		// !stats.isDirectory() ensures that .git is not a directory.
		if (err || !stats.isDirectory()) {
			callback(git);
		}
		else {
			git.initialised = true;
			const gitConfig = spawn('git', ['config', '--get', 'remote.origin.url']);

			gitConfig.stdout.on('data', (data) => {
				git.url = data.toString('utf8').replace('\n', '');
			});

			gitConfig.on('close', () => {
				callback(git);
			});
		}
	});
}

function create(callback) {
	const gitInit = spawn('git', ['init']);

	gitInit.on('close', () => {
{'fraction_non_alphanumeric': 0.1726218097447796, 'fraction_numerical': 0.0009280742459396752, 'mean_word_length': 3.219178082191781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6288409', 'n_tokens_mistral': 779, 'n_tokens_neox': 681, 'n_words': 193}