<commit_before>const sharedUtils = require('./sharedUtils');
const gitCommands = require('./gitCommands');

function checkoutOrCreate(branchName) {
    try {
        gitCommands.checkout(branchName);
    } catch (e) {
        console.log(`Branch ${branchName} doesn't exist yet. Creating it now.`);
        gitCommands.createBranch(branchName);
    }
}

function isOutOfDate() {
    const fileStatus = gitCommands.getStatus().toString();
    const changesExist = fileStatus.includes('Changes');

    if (changesExist) {
        gitCommands.stash();
    }

    gitCommands.checkout('master');
    const status = gitCommands.getStatus();

    const outOfDateStatus = status.includes('up to date')
        || status.includes('is ahead of');

    gitCommands.checkout('workspace');

    if (changesExist) {
        gitCommands.popFromStash();
    }

    return !outOfDateStatus;
}

function setUpWorkspaceBranch() {
    let fileStashSuccessful = false;

    try {
        console.log('Setting up a working environment...');

        gitCommands.stash();
        fileStashSuccessful = true;
        checkoutOrCreate('workspace');
    } catch (e) {
        console.log('Uh oh! Something unexpected happened: ', e);
    }

    if (fileStashSuccessful) {
        gitCommands.popFromStash();
    }
}

function hasGitInstalled() {
    try {
        gitCommands.getStatus();
        return true;
    } catch (e) {
        return false;
    }<commit_msg>Moved pop to try/catch to avoid weird error states<commit_after>const sharedUtils = require('./sharedUtils');
const gitCommands = require('./gitCommands');

function checkoutOrCreate(branchName) {
    try {
        gitCommands.checkout(branchName);
    } catch (e) {
        console.log(`Branch ${branchName} doesn't exist yet. Creating it now.`);
        gitCommands.createBranch(branchName);
    }
}

function safePop() {
    try{
        gitCommands.popFromStash();
    } catch(e) {
        // do nothing and move along.
    }
}

function isOutOfDate() {
    const fileStatus = gitCommands.getStatus().toString();
    const changesExist = fileStatus.includes('Changes');

    if (changesExist) {
        gitCommands.stash();
    }

    gitCommands.checkout('master');
    const status = gitCommands.getStatus();

    const outOfDateStatus = status.includes('up to date')
        || status.includes('is ahead of');

    gitCommands.checkout('workspace');

    if (changesExist) {
        safePop();
    }

    return !outOfDateStatus;
}

function setUpWorkspaceBranch() {
    let fileStashSuccessful = false;

    try {
        console.log('Setting up a working environment...');

        gitCommands.stash();
        fileStashSuccessful = true;
        checkoutOrCreate('workspace');
    } catch (e) {
        console.log('Uh oh! Something unexpected happened: ', e);
    }

    if (fileStashSuccessful) {
        safePop();
    }
}

function hasGitInstalled() {
    try {
        gitCommands.getStatus();
        return true;
    } catch (e) {
        return false;
    }
{'fraction_non_alphanumeric': 0.12529002320185614, 'fraction_numerical': 0.0, 'mean_word_length': 2.7677902621722845, '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': '6505814', 'n_tokens_mistral': 887, 'n_tokens_neox': 892, 'n_words': 190}