diff --git a/functions/main b/functions/main index 5468cf8f..bc4e9128 100644 --- a/functions/main +++ b/functions/main @@ -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" diff --git a/scripts/check b/scripts/check index b53d08b1..b6b9e9b2 100755 --- a/scripts/check +++ b/scripts/check @@ -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 diff --git a/scripts/status b/scripts/status index 60c19fc9..15a54767 100755 --- a/scripts/status +++ b/scripts/status @@ -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