Simplified code

This commit is contained in:
Gerhard Hoffmann 2022-06-03 09:31:33 +02:00
parent 46c58967b9
commit f70b2677d1

View File

@ -5,7 +5,9 @@ GIT_SSL_NO_VERIFY=true
commit_before_pull=""
# save the last commit before executing 'git pull'
save_commit_before_pull () {
# git reflog -> 46c5896 HEAD@{0}: commit: Made update_helpers.sh executable
commit_before_pull=$(git reflog | grep "HEAD@{0}" | cut -d" " -f1)
if ! [ -z "$commit_before_pull" ]; then
if grep -qE "^[[:xdigit:]]{6,}$" <<< $commit_before_pull; then
@ -17,6 +19,7 @@ save_commit_before_pull () {
}
# save_commit_before_pull
# fallback if something went wrong: revert to last valid commit
revert_to_commit_before_pull () {
if ! [ -z "$commit_before_pull" ]; then
if grep -qE "^[[:xdigit:]]{6,}$" <<< $commit_before_pull; then
@ -30,29 +33,44 @@ revert_to_commit_before_pull () {
}
# revert_to_commit_before_pull
# clone the customer repository in ./UpdateController/workspace.
# this is done only once.
clone_customer_repository () {
if [ $(ls -A ./workspace&>/dev/null && printf "N\n" || printf "Y\n") = 'Y' ]; then
`git clone https://git.mimbach49.de/GerhardHoffmann/customer_281.git`
current_dir=${PWD##*/}
current_dir="./${current_dir:-/}"
if [ "$current_dir" = "./UpdateController" ]; then
if ! [[ -d ./workspace ]]; then
{ mkdir -p ./workspace; }
fi
# check if the directory is empty. If so, clone the
# customer repository
if ! find ./workspace -mindepth 1 -maxdepth 1 | read; then
echo "cloning ${1} ..."
( cd ./workspace && git clone "$1" ; )
fi
fi
}
# clone_customer_repository
# clone_customer_repository https://git.mimbach49.de/GerhardHoffmann/customer_281.git
create_workspace () {
`mkdir -p ./workspace`
return 0
}
set -x
pull_customer_repository () {
cd ./workspace/customer_281
if [ $? -ne 0 ]; then
# has to be called in ./UpdateController
current_dir=${PWD##*/}
current_dir="./${current_dir:-/}"
if [ "$current_dir" = "./UpdateController" ]; then
repository_dir="./workspace/$1"
if ! [[ -d "$repository_dir" ]]; then
printf "%s\n" "$repository_dir does not exist!" >&2
return 1
fi
if [ "$(git pull)" = "Already up to date." ]; then
cd - &>/dev/null
if [ "$(cd $repository_dir && git pull)" = "Already up to date." ]; then
printf "%s\n" "$repository_dir already up to date." >&2
return 1
fi
cd - &>/dev/null
else
printf "%s\n" "${FUNCNAME[0]} not called in ./UpdateController" >&2
return 1
fi
return 0
}
pull_customer_repository
# pull_customer_repository customer_281