<commit_before>import path from 'path';
import * as util from './util.js';
import * as resolve from './resolve.js';
import * as git from './git.js';
import flavio from './index.js';

/**
 *
 *
 */
async function clone( repo, options = {} ) {
	await util.readConfigFile( options.cwd );
	const repoUrl = util.parseRepositoryUrl( repo );
	// clone the repo first so it'll be on master, then checkout to the target object.
	// that way we can use the 'master' clone to list tags and so on so we can resolve the correct target without any temporary
	// clones
	let cwd = options.cwd;
	if ( !cwd ) {
		const gitname = util.getGitProjectNameFromUrl( repo );
		cwd = path.join( process.cwd(), gitname || 'project' );
	}
	await git.clone( repoUrl.url, cwd, { master: true } );
	const targetObj = await resolve.getTargetFromRepoUrl( repo, cwd );
	await git.checkout( cwd, targetObj );
	options.cwd = cwd;
	await flavio.commands.update( options );
}

export default clone;
<commit_msg>Added nicer error message is clone dir already exists, and if the target doesn't exist<commit_after>import path from 'path';
import fs from 'fs-extra';
import * as util from './util.js';
import * as resolve from './resolve.js';
import * as git from './git.js';
import flavio from './index.js';

/**
 *
 *
 */
async function clone( repo, options = {} ) {
	await util.readConfigFile( options.cwd );
	const repoUrl = util.parseRepositoryUrl( repo );
	// clone the repo first so it'll be on master, then checkout to the target object.
	// that way we can use the 'master' clone to list tags and so on so we can resolve the correct target without any temporary
	// clones
	let cwd = options.cwd;
	if ( !cwd ) {
		const gitname = util.getGitProjectNameFromUrl( repo );
		cwd = path.join( process.cwd(), gitname || 'project' );
	}
	if ( fs.existsSync( cwd ) ) {
		throw new Error( `Target directory ${cwd} already exists!` );
	}
	await git.clone( repoUrl.url, cwd, { master: true } );
	const targetObj = await resolve.getTargetFromRepoUrl( repo, cwd );
	try {
		await git.checkout( cwd, targetObj );
	} catch ( err ) {
		console.error( `Could not checkout target (${targetObj.branch || targetObj.tag || targetObj.commit}). Using 'master'...` );
	}
	options.cwd = cwd;
	await flavio.commands.update( options );
}

export default clone;

{'fraction_non_alphanumeric': 0.12753378378378377, 'fraction_numerical': 0.0, 'mean_word_length': 3.2607913669064748, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6045245', 'n_tokens_mistral': 755, 'n_tokens_neox': 748, 'n_words': 268}