diff --git a/functions/main b/functions/main index b5623858..81c33764 100644 --- a/functions/main +++ b/functions/main @@ -47,6 +47,34 @@ log_debug() { console_output "DEBUG: $*\n" fi } + +get_branch_status() { + log_debug "cd $NGCPCTL_MAIN" + cd "$NGCPCTL_MAIN" + + log_debug "git rev-parse HEAD" + local LOCAL=$(git rev-parse HEAD) + + log_debug "git rev-parse @{u}" + local REMOTE=$(git rev-parse @{u}) + + log_debug "git merge-base HEAD @{u}" + local BASE=$(git merge-base HEAD @{u}) + + if [ "$LOCAL" = "$REMOTE" ]; then + # Up-to-date + return 0 + elif [ "$LOCAL" = "$BASE" ]; then + # Need to pull + return 1 + elif [ "$REMOTE" = "$BASE" ]; then + # Need to push + return 2 + else + # Diverged + return 3 + fi +} ## }}} ## important variables we depend on to operate successfully {{{