Changes

Jump to navigation Jump to search
1,097 bytes added ,  13:18, 31 May 2017
Line 315: Line 315:  
</source>
 
</source>
    +
=== Git check version ===
 +
<source lang="bash">#!/bin/bash
 +
 +
function set_upstream() {
 +
    echo "No upstream found, setting up branch to track "
 +
    exit
 +
}
 +
 +
function set_upstream() {
 +
    echo "No upstream found"
 +
}
 +
 +
 +
function check_latest_version(){
 +
    UPSTREAM=${1:-'@{u}'}
 +
   
 +
    if [ -z $(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)) ]; then
 +
        set_upstream
 +
    fi
 +
 +
    echo "Upstream: "$UPSTREAM
 +
    exit
 +
    # TODO: check if no upstream is configured, ask if should be automatically configured (git branch --set-upstream-to remotes/$TRACK_REPO/$TRACK_BRANCH)
 +
    # to get the upstream branch: git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
 +
 +
    LOCAL=$(git rev-parse @)
 +
    REMOTE=$(git rev-parse "$UPSTREAM")
 +
    BASE=$(git merge-base @ "$UPSTREAM")
 +
 +
    if [ ${LOCAL} = ${REMOTE} ]; then
 +
        status="Up-to-date"
 +
    elif [ ${LOCAL} = ${BASE} ]; then
 +
        status="Need-to-pull"
 +
    elif [ ${REMOTE} = ${BASE} ]; then
 +
        status="Need-to-push"
 +
    else
 +
        status="Diverged"
 +
    fi
 +
}
 +
check_latest_version</source>
 
=== Git check for updates and prompt to update ===
 
=== Git check for updates and prompt to update ===
 
<source lang="bash">
 
<source lang="bash">

Navigation menu