<commit_before>const fs = require('fs');

function Writewithbreaktag(string) {
    return string + "\n";
};

function InitializeLocalVariable(root){
    let text = "";
    text += Writewithbreaktag("username=\"USER INPUT\"");
    text += Writewithbreaktag("root=\"" + root.replace(/\W/g, '') + "\""); 
    return text; 
}

function CreateGitCapsuleLogo() {
    let text = "";
    text += Writewithbreaktag("echo '**************************************************************************************************' ");
    text += Writewithbreaktag("echo '  /$$$$$$  /$$$$$$ /$$$$$$$$  /$$$$$$   /$$$$$$  /$$$$$$$   /$$$$$$  /$$   /$$ /$$       /$$$$$$$$' ")
    text += Writewithbreaktag("echo ' /$$__  $$|_  $$_/|__  $$__/ /$$__  $$ /$$__  $$| $$__  $$ /$$__  $$| $$  | $$| $$      | $$_____/' ")
    text += Writewithbreaktag("echo '| $$  \\__/  | $$     | $$   | $$  \\__/| $$  \\ $$| $$  \\ $$| $$  \\__/| $$  | $$| $$      | $$      ' ")
    text += Writewithbreaktag("echo '| $$ /$$$$  | $$     | $$   | $$      | $$$$$$$$| $$$$$$$/|  $$$$$$ | $$  | $$| $$      | $$$$$   ' ")
    text += Writewithbreaktag("echo '| $$|_  $$  | $$     | $$   | $$      | $$__  $$| $$____/  \\____  $$| $$  | $$| $$      | $$__/   ' ")
    text += Writewithbreaktag("echo '| $$  \\ $$  | $$     | $$   | $$    $$| $$  | $$| $$       /$$  \\ $$| $$  | $$| $$      | $$      ' ")
    text += Writewithbreaktag("echo '|  $$$$$$/ /$$$$$$   | $$   |  $$$$$$/| $$  | $$| $$      |  $$$$$$/|  $$$$$$/| $$$$$$$$| $$$$$$$$' ")
    text += Writewithbreaktag("echo '\\______/ |______/   |__/    \\______/ |__/  |__/|__/       \\______/  \\______/ |________/|________/ ' ")
    text += Writewithbreaktag("echo '**************************************************************************************************' ")
    return text;
}

function CreateComment(comment) {
    let text = "";
    let commentsArray = comment.match(new RegExp('.{1,' + 99 + '}', 'g'));
    text += Writewithbreaktag("echo '##NOTE#############################################################################################'");
    for (var index in commentsArray) {
        text += Writewithbreaktag("echo " + commentsArray[index]);
    }
    text += Writewithbreaktag("echo '###################################################################################################'");
    return text;
}

//amtrust version
function CreatePullCodeFunction() {
    let text = ""
    text += Writewithbreaktag("function PullCode()");
    text += Writewithbreaktag("{")
    text += Writewithbreaktag("local url=$1"); //project location 
    text += Writewithbreaktag("local fulldir=$2"); //the project folder 
    text += Writewithbreaktag("local project=$3"); //project name 
    text += Writewithbreaktag("local sha=$4"); //sha for checkout
    text += Writewithbreaktag("echo \"-------------------------------------------------------- \"");
    text += Writewithbreaktag("if [ -d /$root/$fulldir ]; then");
    text += Writewithbreaktag("echo \"Git Repo Exist\"");
    text += Writewithbreaktag("echo \"-- CHANGING DIRECTORY --\"");
    text += Writewithbreaktag("echo /$root/$fulldir/$project");
    text += Writewithbreaktag("cd /$root/$fulldir/$project");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("else");
    text += Writewithbreaktag("echo \"Git Repo doesnt exist, will create\"");
    text += Writewithbreaktag("mkdir /$root/$fulldir/$project");
    text += Writewithbreaktag("echo \"-- CHANGING DIRECTORY --\"");
    text += Writewithbreaktag("cd /$root/$fulldir/$project");
    text += Writewithbreaktag("git clone $url");
    text += Writewithbreaktag("fi");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \"-- RESETTING --\"");
    text += Writewithbreaktag("git reset --hard");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \"-- FETCHING -- \"");
    text += Writewithbreaktag("git fetch");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \" -- CHECKING OUT BRANCH --\"");
    text += Writewithbreaktag("git checkout $branch");
    text += Writewithbreaktag("}")
    return text;
}

function PullCode(selectedGitFolders) {
    let text = "";
    for (let i in selectedGitFolders) {
        let dir = ParseDirectory(selectedGitFolders[i].file.dir); 
        text += Writewithbreaktag("PullCode \"$<EMAIL>:" +  selectedGitFolders[i].config["remote \"origin\""].url.split(":").pop() + "\" " + "\"" + dir + "\" " +  "\"" + selectedGitFolders[i].file.base + "\" " + "\"" + selectedGitFolders[i].repoInfo.sha + "\"");  
    }
    return text; 
}

function ParseDirectory(directory) {
    let array = directory.split("\\");
    let dir = "";
    for (let i = 1; i < array.length; i++) {
        dir += array[i] 
        if(i != array.length)
            dir += "/";
    }
    return dir; 
}

function GetProject(projects){
    let text = Writewithbreaktag("echo \"Following Git Repository will be created/updated in your root directory\"");
    for(let i in projects){
        text += Writewithbreaktag("echo \"" + projects[i] + "\"");
    }
    text += Writewithbreaktag("read -p \"Press enter to continue...\""); 
    return text;
}

function GetUsername(){
    let text = ""; 
    text += Writewithbreaktag("echo")
    text += Writewithbreaktag("read -p \"Enter your GIT username, then click enter: \" username") 
    return text;
}

exports.createScript = (directory, selectedGitFolders, name, comment) => {
    let codeFile = CreateGitCapsuleLogo();
    //assuming root is same for now.. 
    codeFile += InitializeLocalVariable(selectedGitFolders[0].file.root); 
    codeFile += CreatePullCodeFunction();
    if (comment) {
        codeFile += CreateComment(comment);
    }
    codeFile += GetProject(selectedGitFolders.map((e) => {return e.file.name})); 
    codeFile += GetUsername(); 
    codeFile += PullCode(selectedGitFolders); 
    const fileName = directory + "\\" + name + ".sh";
    const writer = fs.createWriteStream(fileName);
    writer.write(codeFile);
    writer.end("read -p \"$*\"");
}<commit_msg>fixed so it will checkout specific sha<commit_after>const fs = require('fs');

function Writewithbreaktag(string) {
    return string + "\n";
};

function InitializeLocalVariable(root){
    let text = "";
    text += Writewithbreaktag("username=\"USER INPUT\"");
    text += Writewithbreaktag("root=\"" + root.replace(/\W/g, '') + "\""); 
    return text; 
}

function CreateGitCapsuleLogo() {
    let text = "";
    text += Writewithbreaktag("echo '**************************************************************************************************' ");
    text += Writewithbreaktag("echo '  /$$$$$$  /$$$$$$ /$$$$$$$$  /$$$$$$   /$$$$$$  /$$$$$$$   /$$$$$$  /$$   /$$ /$$       /$$$$$$$$' ")
    text += Writewithbreaktag("echo ' /$$__  $$|_  $$_/|__  $$__/ /$$__  $$ /$$__  $$| $$__  $$ /$$__  $$| $$  | $$| $$      | $$_____/' ")
    text += Writewithbreaktag("echo '| $$  \\__/  | $$     | $$   | $$  \\__/| $$  \\ $$| $$  \\ $$| $$  \\__/| $$  | $$| $$      | $$      ' ")
    text += Writewithbreaktag("echo '| $$ /$$$$  | $$     | $$   | $$      | $$$$$$$$| $$$$$$$/|  $$$$$$ | $$  | $$| $$      | $$$$$   ' ")
    text += Writewithbreaktag("echo '| $$|_  $$  | $$     | $$   | $$      | $$__  $$| $$____/  \\____  $$| $$  | $$| $$      | $$__/   ' ")
    text += Writewithbreaktag("echo '| $$  \\ $$  | $$     | $$   | $$    $$| $$  | $$| $$       /$$  \\ $$| $$  | $$| $$      | $$      ' ")
    text += Writewithbreaktag("echo '|  $$$$$$/ /$$$$$$   | $$   |  $$$$$$/| $$  | $$| $$      |  $$$$$$/|  $$$$$$/| $$$$$$$$| $$$$$$$$' ")
    text += Writewithbreaktag("echo '\\______/ |______/   |__/    \\______/ |__/  |__/|__/       \\______/  \\______/ |________/|________/ ' ")
    text += Writewithbreaktag("echo '**************************************************************************************************' ")
    return text;
}

function CreateComment(comment) {
    let text = "";
    let commentsArray = comment.match(new RegExp('.{1,' + 99 + '}', 'g'));
    text += Writewithbreaktag("echo '##NOTE#############################################################################################'");
    for (var index in commentsArray) {
        text += Writewithbreaktag("echo " + commentsArray[index]);
    }
    text += Writewithbreaktag("echo '###################################################################################################'");
    return text;
}

//amtrust version
function CreatePullCodeFunction() {
    let text = ""
    text += Writewithbreaktag("function PullCode()");
    text += Writewithbreaktag("{")
    text += Writewithbreaktag("local url=$1"); //project location 
    text += Writewithbreaktag("local fulldir=$2"); //the project folder 
    text += Writewithbreaktag("local project=$3"); //project name 
    text += Writewithbreaktag("local sha=$4"); //sha for checkout
    text += Writewithbreaktag("echo \"-------------------------------------------------------- \"");
    text += Writewithbreaktag("if [ -d /$root/$fulldir ]; then");
    text += Writewithbreaktag("echo \"Git Repo Exist\"");
    text += Writewithbreaktag("echo \"-- CHANGING DIRECTORY --\"");
    text += Writewithbreaktag("echo /$root/$fulldir/$project");
    text += Writewithbreaktag("cd /$root/$fulldir/$project");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("else");
    text += Writewithbreaktag("echo \"Git Repo doesnt exist, will create\"");
    text += Writewithbreaktag("mkdir /$root/$fulldir/$project");
    text += Writewithbreaktag("echo \"-- CHANGING DIRECTORY --\"");
    text += Writewithbreaktag("cd /$root/$fulldir/$project");
    text += Writewithbreaktag("git clone $url");
    text += Writewithbreaktag("fi");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \"-- RESETTING --\"");
    text += Writewithbreaktag("git reset --hard");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \"-- FETCHING -- \"");
    text += Writewithbreaktag("git fetch");
    text += Writewithbreaktag("echo");
    text += Writewithbreaktag("echo \" -- CHECKING OUT BRANCH --\"");
    text += Writewithbreaktag("git checkout $sha");
    text += Writewithbreaktag("}")
    return text;
}

function PullCode(selectedGitFolders) {
    let text = "";
    for (let i in selectedGitFolders) {
        let dir = ParseDirectory(selectedGitFolders[i].file.dir); 
        text += Writewithbreaktag("PullCode \"$<EMAIL>@sourcecontrol.<EMAIL>:" +  selectedGitFolders[i].config["remote \"origin\""].url.split(":").pop() + "\" " + "\"" + dir + "\" " +  "\"" + selectedGitFolders[i].file.base + "\" " + "\"" + selectedGitFolders[i].repoInfo.sha + "\"");  
    }
    return text; 
}

function ParseDirectory(directory) {
    let array = directory.split("\\");
    let dir = "";
    for (let i = 1; i < array.length; i++) {
        dir += array[i] 
        if(i != array.length)
            dir += "/";
    }
    return dir; 
}

function GetProject(projects){
    let text = Writewithbreaktag("echo \"Following Git Repository will be created/updated in your root directory\"");
    for(let i in projects){
        text += Writewithbreaktag("echo \"" + projects[i] + "\"");
    }
    text += Writewithbreaktag("read -p \"Press enter to continue...\""); 
    return text;
}

function GetUsername(){
    let text = ""; 
    text += Writewithbreaktag("echo")
    text += Writewithbreaktag("read -p \"Enter your GIT username, then click enter: \" username") 
    return text;
}

exports.createScript = (directory, selectedGitFolders, name, comment) => {
    let codeFile = CreateGitCapsuleLogo();
    //assuming root is same for now.. 
    codeFile += InitializeLocalVariable(selectedGitFolders[0].file.root); 
    codeFile += CreatePullCodeFunction();
    if (comment) {
        codeFile += CreateComment(comment);
    }
    codeFile += GetProject(selectedGitFolders.map((e) => {return e.file.name})); 
    codeFile += GetUsername(); 
    codeFile += PullCode(selectedGitFolders); 
    const fileName = directory + "\\" + name + ".sh";
    const writer = fs.createWriteStream(fileName);
    writer.write(codeFile);
    writer.end("read -p \"Press enter to exit :)\"");
}
{'fraction_non_alphanumeric': 0.28197579326136735, 'fraction_numerical': 0.0014720314033366045, 'mean_word_length': 3.035973597359736, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '758757', 'n_tokens_mistral': 3820, 'n_tokens_neox': 3692, 'n_words': 650}