MT#16393 Check for branch 'master' being active

Verify that the user is operating on branch master,
otherwise the result might be unexpected.

If branch master is checked out:

| root@spce:/etc/ngcp-config# ngcpcfg check
| root@spce:/etc/ngcp-config# ngcpcfg status
| [...]
| 2016-02-23 05:48:32: Checking currently active branch:
| 2016-02-23 05:48:32: OK:   branch master active

If a branch other than 'master' is checked out:

| root@spce:/etc/ngcp-config# ngcpcfg check
| 2016-02-23 05:47:42: Error: branch 'mika' in '/etc/ngcp-config' active - please switch to branch 'master' before continuing.
| root@spce:/etc/ngcp-config# echo $?
| 1
| root@spce:/etc/ngcp-config# ngcpcfg status
| [...]
| 2016-02-23 05:47:47: Checking currently active branch:
| 2016-02-23 05:47:47: ACTION_NEEDED: branch 'mika' active - please switch to branch 'master'
| [...]

Change-Id: I5df92075905cafa3b714211581c8cfe749df04ba
changes/80/4780/2
Michael Prokop 10 years ago
parent de844084ae
commit 4fd512261b

@ -48,6 +48,18 @@ log_debug() {
fi
}
compare_active_branch() {
log_debug "get_active_branch ${1:-}"
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
local current_branch
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
log_debug "current_branch = $current_branch"
echo "$current_branch"
}
get_branch_status() {
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"

@ -16,6 +16,16 @@ fi
. "${FUNCTIONS}"/main
check_branch() {
local current_branch=$(compare_active_branch 'master')
if [ "$current_branch" = 'master' ] ; then
log_debug "Current branch is 'master', continuing."
else
log_error "branch '$current_branch' in '$NGCPCTL_MAIN' active - please switch to branch 'master' before continuing."
exit 1
fi
}
check_config_encoding() {
log_debug "Checking encoding for $config_files"
for f in $config_files ; do
@ -131,6 +141,8 @@ else
config_files="$*"
fi
check_branch
check_configs
if "${VALIDATE_SCHEMA:-false}" ; then
validate_config

@ -95,6 +95,17 @@ check_etc_state() {
fi
}
check_branch() {
log_info "Checking currently active branch:"
local current_branch=$(compare_active_branch 'master')
if [ "$current_branch" = 'master' ] ; then
log_info "OK: branch master active"
else
log_info "ACTION_NEEDED: branch '$current_branch' active - please switch to branch 'master'"
fi
}
check_push() {
if type -p execute_check_shared_storage &>/dev/null ; then
log_debug "execute_check_shared_storage function, action 'push'"
@ -164,6 +175,7 @@ check_pending_build() {
if [ -z "${1:-}" ] ; then
check_local_state
check_branch
check_push
check_etc_state
check_pending_build

Loading…
Cancel
Save