<commit_before>#!/usr/bin/env bash

set -e
shopt -s extglob

version=0.0.2-dev # x-docker
script="$0"
test -h "$script" && script="$(realpath "$script")"
scriptpath="$(cd "$(dirname "$script")" && pwd -P)/../lib/sh"
scriptname="$(basename "$script" .sh)"

__load=ext . $scriptpath/load.lib.sh
lib_load std sys os str


load()
{
  true
}


xdckr__usage()
{
	echo TODO
}

xdckr_return_to_branch()
{
  git status --porcelain | grep -q '\(U.\)\|\(.U\)' && {
    stderr "GIT checkout left in unresolved state, cannot return to $1"
    return 1
  } || {
    git checkout $1
  }
}

xdckr_git_update()
{
  test -n "$1" || stderr "branch name expected" 1
  git checkout $1 &&
  git pull origin $1 && {

    git merge $2 || {
      { test -e README.md && git checkout README.md; } ||
        stderr "Unexpected merge conflict" 1
    }
  } || {

    git merge --abort
    return 1
  }

	xdckr__link_custom_readme $1 && {
    {
      git add -f README.md &&
        git commit -m "Updating $1 for README"
    }|| return $?
  } || {

    test ! -e README.md || {
      git rm -f README.md &&
      git commit -m "Updating for README"
    }
  }
  git push
}


xdckr__git_update_all()
{
  test -n "$1" || stderr "branch expected" 1
  git checkout master &&
    git pull origin master &&
		xdckr__git_update $1
}


xdckr__git_update()
{
  test -n "$1" || stderr "branch name expected" 1
  test -n "$current_branch" ||
    local current_branch="$(git rev-parse --abbrev-ref HEAD)"
  xdckr_git_update "$1" "$current_branch" || return $?
  xdckr_return_to_branch "$current_branch"
}


xdckr__git_update_downstream()
{
	local current_branch="$(git rev-parse --abbrev-ref HEAD)"
	grep -v '^#' gitflow.tab | cut -f 2 -d ' ' | while read downstream
	do
		xdckr__git_update $downstream || return $?
	done
  xdckr_return_to_branch
}


xdckr_man_1__link_custom_readme='
With the autobuilder, README.md overrules all other matches
'
xdckr__link_custom_readme()
{
  test -n "$1" || stderr "branch name expected" 1
	# Set custom README for branch
	local name=$( echo "$1" | cut -d '-' -f 1 )
	test -e ReadMe-$name.md && {
    test -e "README.md" -a "$(readlink README.md)" = "ReadMe-$name.md" && {
      return
    } || {
      rm README.md
    }
    ln -s ReadMe-$name.md README.md
	} || return 1
}
<commit_msg>Scripts<commit_after>#!/usr/bin/env bash

set -e
shopt -s extglob

version=0.0.2-dev # x-docker
script="$0"
test -h "$script" && script="$(realpath "$script")"
scriptpath="$(cd "$(dirname "$script")" && pwd -P)/../lib/sh"
scriptname="$(basename "$script" .sh)"

__load=ext . $scriptpath/load.lib.sh
lib_load std sys os str


load()
{
  true
}


xdckr__usage()
{
	echo TODO
}

xdckr_return_to_branch()
{
  git status --porcelain | grep -q '\(U.\)\|\(.U\)' && {
    stderr "GIT checkout left in unresolved state, cannot return to $1"
    return 1
  } || {
    git checkout $1
  }
}

xdckr_git_update()
{
  test -n "$1" || stderr "branch name expected" 1
  git checkout $1 &&
  git pull origin $1 && {

    git merge $2 || {
      { test -e README.md && git checkout README.md; } ||
        stderr "Unexpected merge conflict" 1
    }
  } || {

    git merge --abort
    return 1
  }

	xdckr__link_custom_readme $1 && {
    {
      git add -f README.md &&
        git commit -m "Updating $1 for README"
    }|| return $?
  } || {

    test ! -e README.md || {
      git rm -f README.md &&
      git commit -m "Updating for README"
    }
  }
  not_trueish "$return" || {
    git push || return $?
  }
}


xdckr__git_update_all()
{
  test -n "$1" || stderr "branch expected" 1
  git checkout master &&
    git pull origin master &&
		xdckr__git_update $1
}


xdckr__git_update()
{
  test -n "$1" || stderr "branch name expected" 1
  test -n "$current_branch" ||
    local current_branch="$(git rev-parse --abbrev-ref HEAD)"
  xdckr_git_update "$1" "$current_branch" || return $?
  xdckr_return_to_branch "$current_branch"
}


xdckr__git_update_downstream()
{
	local current_branch="$(git rev-parse --abbrev-ref HEAD)"
	grep -v '^#' gitflow.tab | cut -f 2 -d ' ' | while read downstream
	do
		xdckr__git_update $downstream || return $?
	done
  not_trueish "$return" || {
    xdckr_return_to_branch || return $?
  }
}


xdckr_man_1__link_custom_readme='
With the autobuilder, README.md overrules all other matches
'
xdckr__link_custom_readme()
{
  test -n "$1" || stderr "branch name expected" 1
	# Set custom README for branch
	local name=$( echo "$1" | cut -d '-' -f 1 )
	test -e ReadMe-$name.md && {
    test -e "README.md" -a "$(readlink README.md)" = "ReadMe-$name.md" && {
      return
    } || {
      rm README.md
    }
    ln -s ReadMe-$name.md README.md
	} || return 1
}

{'fraction_non_alphanumeric': 0.15807560137457044, 'fraction_numerical': 0.01245704467353952, 'mean_word_length': 2.814086814086814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1148739', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1763, 'n_words': 476}