From 65eca79cfcec732b8be627fd029a8c469365f9a5 Mon Sep 17 00:00:00 2001 From: Thomas Stokes Date: Thu, 21 Mar 2024 11:16:08 +0100 Subject: [PATCH] Push latest httpd git changes and any merge in main to the remote. Check for error status after potential conflicts. --- .../httpdConf/repo.git/hooks/post-receive | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/configuration/environments_scripts/central_reverse_proxy/files/home/httpdConf/repo.git/hooks/post-receive b/configuration/environments_scripts/central_reverse_proxy/files/home/httpdConf/repo.git/hooks/post-receive index 2f40ad43553..663e95c6371 100644 --- a/configuration/environments_scripts/central_reverse_proxy/files/home/httpdConf/repo.git/hooks/post-receive +++ b/configuration/environments_scripts/central_reverse_proxy/files/home/httpdConf/repo.git/hooks/post-receive @@ -23,12 +23,24 @@ sync_repo() { ssh -o "StrictHostKeyChecking=no" -o "ConnectTimeout=10" root@${IP} "cd ~ && sync-repo-and-execute-cmd.sh '${DIR}' '${COMMAND}' '${2}'"; done; } +check_conflict() { + # $1: Return code of a command + # $2: Error msg to use + if [[ "$1" -ne 0 ]]; then + echo "$2" + echo "$2" | notify-operators "Merge issue for httpd config repo in checked-out workspace" + exit 1 + fi +} merge_main_into_branch() { - #$1 branch name. Assumes you are in the git repo. + #$1 Branch name. Assumes you are in the git repo. git checkout "${1}" + check_conflict "$?" "Conflict checking out ${1}" git pull - echo "merging ${MAIN_BRANCH_NAME} into ${1}" + check_conflict "$?" "Conflict pulling ${1}" + echo "Merging ${MAIN_BRANCH_NAME} into ${1}" git merge ${MAIN_BRANCH_NAME} + check_conflict "$?" "Conflict merging ${MAIN_BRANCH_NAME} into ${1}" git push } while read oldrev newrev refname; do # These vars are passed on stdin to this hook. @@ -46,14 +58,21 @@ while read oldrev newrev refname; do # These vars are passed on stdin to this cd ~ unset GIT_DIR cd ${CHECKED_OUT_WORKSPACE_NAME} - # get the latest main + # Get the latest main git checkout ${MAIN_BRANCH_NAME} + check_conflict "$?" "Uncommitted files in the working directory" git pull - # get the latest diposable branch and merge in changes - merge_main_into_branch "$DISPOSABLE_BRANCH_NAME" - # get the latest central branch and merge in changes - merge_main_into_branch "$CENTRAL_BRANCH_NAME" - git checkout ${MAIN_BRANCH_NAME} + if [[ "$(git rev-parse ${MAIN_BRANCH_NAME})" != "$(git rev-parse origin/${MAIN_BRANCH_NAME})" ]]; then + echo "Merge induced by pull. Pushing latest changes in ${MAIN_BRANCH_NAME} to origin" # In case of a merge from diverging branches. This seems cyclic as we are pushing to the same branch, but should resolve, when "Everything up-to-date". + git push + else + check_conflict "$?" "Merge conflict in main branch" + # Get the latest diposable branch and merge in changes + merge_main_into_branch "$DISPOSABLE_BRANCH_NAME" + # Get the latest central branch and merge in changes + merge_main_into_branch "$CENTRAL_BRANCH_NAME" + git checkout ${MAIN_BRANCH_NAME} + fi fi fi done \ No newline at end of file