From d280bd3eae5180bbc55d39b1d6d6b15fe052a171 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Wed, 10 Jul 2024 16:39:37 -0500 Subject: [PATCH 1/2] Moved masterfiles-stage checks for git in sync so that they can work properly Ticket: ENT-11970 Changelog: none --- contrib/masterfiles-stage/common.sh | 44 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/contrib/masterfiles-stage/common.sh b/contrib/masterfiles-stage/common.sh index 77d6b813f7..a090578369 100755 --- a/contrib/masterfiles-stage/common.sh +++ b/contrib/masterfiles-stage/common.sh @@ -112,9 +112,6 @@ git_deploy_refspec() { mkdir -p "${temp_stage}/.git" cp "${local_mirrored_repo}/HEAD" "${temp_stage}/.git/" - if git_check_is_in_sync "${local_mirrored_repo}" "${temp_stage}" "$2"; then - return 0 - fi ########################## 3. SET PERMISSIONS ON POLICY SET chown -R root:root "${temp_stage}" || error_exit "Unable to chown '${temp_stage}'" @@ -238,9 +235,6 @@ git_cfbs_deploy_refspec() { mkdir -p "${temp_stage}/out/masterfiles/.git" cp "${local_mirrored_repo}/HEAD" "${temp_stage}/out/masterfiles/.git/" - if git_check_is_in_sync "${local_mirrored_repo}" "${temp_stage}/out/masterfiles" "$2"; then - return 0 - fi ########################## 3. SET PERMISSIONS ON POLICY SET chown -R root:root "${temp_stage}" || error_exit "Unable to chown '${temp_stage}'" @@ -385,15 +379,22 @@ git_masterstage() { # Depends on $GIT_URL, $ROOT, $MASTERDIR, $GIT_REFSPEC check_git_installed git_setup_local_mirrored_repo "$( dirname "$ROOT" )" - if [ "x$1" = "xtrue" ]; then - if git_check_is_in_sync "$( dirname "$ROOT" )" "$MASTERDIR" "$GIT_REFSPEC"; then - return 1 # in sync => nothing to do + git_check_is_in_sync "$local_mirrored_repo" "$MASTERDIR" "$GIT_REFSPEC" + local in_sync=$? + if [ "$1" = "true" ]; then + if [ "$in_sync" = "0" ]; then + return 1 # in sync => nothing to do + else + return 0 # not in sync => update available + fi + else + if [ "$in_sync" != "0" ]; then + git_deploy_refspec "$MASTERDIR" "${GIT_REFSPEC}" + echo "Successfully deployed '${GIT_REFSPEC}' from '${GIT_URL}' to '${MASTERDIR}' on $(date)" else - return 0 # not in sync => update available + echo "'${GIT_REFSPEC}' from '${GIT_URL}' has no changes. Will not update." fi fi - git_deploy_refspec "$MASTERDIR" "${GIT_REFSPEC}" - echo "Successfully deployed '${GIT_REFSPEC}' from '${GIT_URL}' to '${MASTERDIR}' on $(date)" } git_cfbs_masterstage() { @@ -402,15 +403,22 @@ git_cfbs_masterstage() { check_git_installed check_cfbs_installed git_setup_local_mirrored_repo "$( dirname "$ROOT" )" - if [ "x$1" = "xtrue" ]; then - if git_check_is_in_sync "$( dirname "$ROOT" )" "$MASTERDIR" "$GIT_REFSPEC"; then - return 1 # in sync => nothing to do + git_check_is_in_sync "$local_mirrored_repo" "$MASTERDIR" "$GIT_REFSPEC" + local in_sync=$? + if [ "$1" = "true" ]; then + if [ "$in_sync" = "0" ]; then + return 1 # in sync => nothing to do + else + return 0 # not in sync => update available + fi + else + if [ "$in_sync" != "0" ]; then + git_cfbs_deploy_refspec "$MASTERDIR" "${GIT_REFSPEC}" + echo "Successfully built and deployed '${GIT_REFSPEC}' from '${GIT_URL}' to '${MASTERDIR}' on $(date) with cfbs" else - return 0 # not in sync => update available + echo "'${GIT_REFSPEC}' from '${GIT_URL}' has no changes. Will not update." fi fi - git_cfbs_deploy_refspec "$MASTERDIR" "${GIT_REFSPEC}" - echo "Successfully built and deployed '${GIT_REFSPEC}' from '${GIT_URL}' to '${MASTERDIR}' on $(date) with cfbs" } svn_branch() { From 64977917ef4d834f87240b45eb6dcc189ed49ea4 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Wed, 10 Jul 2024 16:47:36 -0500 Subject: [PATCH 2/2] Added logging of fetch --dry-run in masterfiles stage scripts for reference/debugging --- contrib/masterfiles-stage/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/masterfiles-stage/common.sh b/contrib/masterfiles-stage/common.sh index a090578369..6645216aa8 100755 --- a/contrib/masterfiles-stage/common.sh +++ b/contrib/masterfiles-stage/common.sh @@ -59,6 +59,7 @@ git_setup_local_mirrored_repo() { # /opt/cfengine/git_mygitserver.net_joeblow_my_policy_repo.git if [ -d "${local_mirrored_repo}" ] ; then + git --git-dir="${local_mirrored_repo}" fetch --dry-run # to provide information in logs about from and to commits git --git-dir="${local_mirrored_repo}" fetch && return 0 # If execution arrives here, the local_mirrored_repo exists but is messed up somehow