<commit_before>#!/bin/env bash
# ------------------------------------------------------------------------------
# description
# ------------------------------------------------------------------------------
# 
declare branch_active=
declare -r production_branches=(
"prod"
"release"
)

declare -r remote_id="origin"
declare -r branch_master="master"

usage() {
  cat >&2 << EOF
Usage:	${0##*/} [OPTIONS] <arg1> -- [EXTRA]

arg1
  mandatory argument passed to script
  
OPTIONS:
  -h			  help
  -v			  verbose
  -q			  quiet
  -d			  debug


EXTRA
  Additional options passed for other purposes
EOF
}

main() {

  # flags
  local -i enable_verbose=0
  local -i enable_quiet=0
  local -i enable_debug=0

  local -a options=
  local -a args=

  check_dependencies
  # parse input args 
  parse_options "$@"
  # set leftover options parsed local input args
  set -- ${args[@]}
  # remove args array
  unset -v args
  check_input_args "$@"

  prepare_env
  if [[ -z $1 ]]; then
    set -- "."
  fi
  for path in "$@"; do
    pushd "$path"
    setup
    run
    popd
  done
  trap - SIGINT SIGQUIT SIGABRT SIGTERM EXIT
}

run() {
  if ! check_branches_conflict "${production_branches[@]}"; then
    die "Conflicting branches found: ${production_branches[@]}"
  fi

  local branch_prod=$(get_valid_branch "$production_branches")
  [[ -z $branch_prod ]] && die "No production branch found."

  if check_merge_allowed "$branch_prod"; then
    {
    git checkout "$branch_master" && git merge --ff-only "$branch_prod"
    } 2>/dev/null || die "Merge of '$branch_prod' on $branch_master failed."
    msg "Merged '$branch_prod' to '$branch_master'"
  fi
  for remote in $(git remote); do
    {
    git pull "$remote_id"
    git push "$remote"
    } 2>/dev/null || error "Remote push to '$remote' failed."
  done

  git checkout "$branch_active"
}



check_dependencies() {
  :
}

check_input_args() {
  :
}

prepare_env() {
  :
}

prepare() {
  set -e
  source_libs
  set +e
<commit_msg>Checkout dev branch if checkout of active failed<commit_after>#!/bin/env bash
# ------------------------------------------------------------------------------
# description
# ------------------------------------------------------------------------------
# 
declare branch_active=
declare -r dev_branch="dev"
declare -r production_branches=(
"prod"
"release"
)

declare -r remote_id="origin"
declare -r branch_master="master"

usage() {
  cat >&2 << EOF
Usage:	${0##*/} [OPTIONS] <arg1> -- [EXTRA]

arg1
  mandatory argument passed to script
  
OPTIONS:
  -h			  help
  -v			  verbose
  -q			  quiet
  -d			  debug


EXTRA
  Additional options passed for other purposes
EOF
}

main() {

  # flags
  local -i enable_verbose=0
  local -i enable_quiet=0
  local -i enable_debug=0

  local -a options=
  local -a args=

  check_dependencies
  # parse input args 
  parse_options "$@"
  # set leftover options parsed local input args
  set -- ${args[@]}
  # remove args array
  unset -v args
  check_input_args "$@"

  prepare_env
  if [[ -z $1 ]]; then
    set -- "."
  fi
  for path in "$@"; do
    pushd "$path"
    setup
    run
    popd
  done
  trap - SIGINT SIGQUIT SIGABRT SIGTERM EXIT
}

run() {
  if ! check_branches_conflict "${production_branches[@]}"; then
    die "Conflicting branches found: ${production_branches[@]}"
  fi

  local branch_prod=$(get_valid_branch "$production_branches")
  [[ -z $branch_prod ]] && die "No production branch found."

  if check_merge_allowed "$branch_prod"; then
    {
    git checkout "$branch_master" && git merge --ff-only "$branch_prod"
    } 2>/dev/null || die "Merge of '$branch_prod' on $branch_master failed."
    msg "Merged '$branch_prod' to '$branch_master'"
  fi
  for remote in $(git remote); do
    {
    git pull "$remote_id"
    git push "$remote"
    } 2>/dev/null || error "Remote push to '$remote' failed."
  done

  git checkout "$branch_active" || git checkout "$dev_branch"
}



check_dependencies() {
  :
}

check_input_args() {
  :
}

prepare_env() {
  :
}

prepare() {
  set -e
  source_libs
  set +e

{'fraction_non_alphanumeric': 0.19663616126638633, 'fraction_numerical': 0.004946821667078902, 'mean_word_length': 2.2718446601941746, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996407', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1312, 'n_words': 387}