MT#15803 Introducing the new function to provide current branch status

Previously we guessed the status of current branch by parsing
'git status' output. Unfortunately we have to care about a
corner cases in this way. In the same time we can easily
consider current branch status comparing commits.

Introducing the new function to provide current branch status:
up-2-date, ahead, behind or diverged with origin.

Change-Id: I4d09c8867069ccafc97e5d31638e8bc94caa58cd
changes/27/3027/3
Alexander Lutay 11 years ago
parent e8f7ce894e
commit cad0d3c1b7

@ -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 {{{

Loading…
Cancel
Save