core-update.bash

#!/usr/bin/env bash


function core_update(){
    is_project_dir || return;
    # @TODO Finish this feature. See bottom of the function.

    # conflicts="$(merge_conflicts)"
    # msg "${conflicts}"
    msg_header "INCOMPLETE FEATURE"
    msg_mistake "This feature is NOT fully implemented & may have some issues. Use at your own risk."
    prompt_quit "[enter] to continue" na -e \
        && return;
    
    msg_status "Downloading"
    git fetch
    # msg_mistake "downloading tempoararily disabled"
    msg_status "Download complete"
    msg_header "Current status"

    branches_status

    behindCount="$(cur_branch_behind_count)"

    if [[ behindCount -gt 0 ]]; then
        msg_header "Update local code"
        msg "Your code on ${cMark}$(cur_branch)${cOff} is behind by ${behindCount} saves..."

        changed_files_array changedFiles;
        changeCount="${#changedFiles[@]}";
        hasChanges=false
        if [[ $changeCount -gt 0 ]];then
            msg "and ${cMark}${changeCount}${cOff} local files have unsaved changes."
            hasChanges=true
        fi

        prompt_yes_or_quit "Integrate the updates into ${cMark}$(cur_branch)${cOff}?" \
            && return

        if $hasChanges; then
            msg_status "integrating changes"
            git stash
            git pull
            git stash apply
            msg
            msg_status "Updates installed"
            # msg_status "Updates installed, there are conflicts"
            msg_mistake "There may (or may not) be files with conflicts. This feature is incomplete..."
			
            prompt_quit "[enter] to see files with conflicts" na -e \
                && return;
            msg
            msg "The following files have conflicts: "
            msg
            conflicts="$(conflicting_files)"
            msg "${conflicts}"
            msg

            prompt_quit "[enter] for instructions" na -e \
                && return;
            msg_header "Instructions"
            msg "Files with conflicts will look something like:"
            msg ""
            msg "<<<<<<< Updated upstream"
            msg "    //downloaded code"
            msg "    //more downloaded code"
            msg "======="
            msg "    //local code"
            msg "    //more local code"
            msg ">>>>>>> Stashed changes"
            msg ""
            msg ""
            msg " 1. Delete the code you don't want"
            msg " 2. Delete the <<<, ===, & >>> lines"
            msg " 3. Save the file to disk, like normal."
            msg " 4. [bent save] when you're done."
            msg ""

        fi
        
        # Check if there is currently un-committed code
        # If yes, stash it then pull, then advice, then apply stash
            # or mabye commit?
        # If no, just pull
    fi
}