From 666acbb4af4a5d1e0d29a16be55fcde75dc26011 Mon Sep 17 00:00:00 2001 From: Marc Siebeneicher Date: Tue, 13 Dec 2022 13:32:27 +0100 Subject: [PATCH 1/5] fix(sync-template): fix issue with .templatesyncignore conflicts --- src/sync_template.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sync_template.sh b/src/sync_template.sh index a0a16b3b..037c3c44 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -56,6 +56,14 @@ echo "::debug::pull changes from template" git pull "${SOURCE_REPO}" --allow-unrelated-histories --squash --strategy=recursive -X theirs echo "::endgroup::" +# restore TEMPLATE_SYNC_IGNORE_FILE_NAME in case of a change/diff +# from the tpl repository. The original file in the final repo always wins. +if ! git diff --exit-code "${TEMPLATE_SYNC_IGNORE_FILE_NAME}"; then + echo "::group::restore ignore file because of incomming changes from template" + git restore "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" + echo "::endgroup::" +fi + echo "::group::persist template version" echo "write new template version file" echo "${NEW_TEMPLATE_GIT_HASH}" > ${TEMPLATE_VERSION_FILE_NAME} From d160d843f10f15fe107db2868cfe5e8d4f1f7728 Mon Sep 17 00:00:00 2001 From: Marc Siebeneicher Date: Tue, 13 Dec 2022 15:32:45 +0100 Subject: [PATCH 2/5] fix(sync-template): fix issue with .templatesyncignore conflicts --- src/sync_template.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/sync_template.sh b/src/sync_template.sh index 037c3c44..c798fa4d 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -52,15 +52,29 @@ echo "::endgroup::" echo "::group::Pull template" echo "::debug::create new branch from default branch with name ${NEW_BRANCH}" git checkout -b "${NEW_BRANCH}" + +if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_NAME} ] +then + echo "::debug::backup ignore file in case of incomming changes" + cp "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" "${TEMPLATE_SYNC_IGNORE_FILE_NAME}.tmp" +fi + echo "::debug::pull changes from template" git pull "${SOURCE_REPO}" --allow-unrelated-histories --squash --strategy=recursive -X theirs echo "::endgroup::" -# restore TEMPLATE_SYNC_IGNORE_FILE_NAME in case of a change/diff -# from the tpl repository. The original file in the final repo always wins. -if ! git diff --exit-code "${TEMPLATE_SYNC_IGNORE_FILE_NAME}"; then - echo "::group::restore ignore file because of incomming changes from template" - git restore "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" +if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_NAME} ] +then + echo "::group::restore ignore file" + # restore ignore file. the ignore file in the final repo always wins + mv -f "${TEMPLATE_SYNC_IGNORE_FILE_NAME}.tmp" "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" + # we are checking the ignore file for diff to give propper feedback + # if exit code != 0 we had an imcomming change form the tpl repo + if ! git diff --exit-code "${TEMPLATE_SYNC_IGNORE_FILE_NAME}"; then + echo "::debug::restored ignore file because of incomming changes from tpl repository" + else + echo "::debug::no diff detected in ${TEMPLATE_SYNC_IGNORE_FILE_NAME}" + fi echo "::endgroup::" fi From a3e8095047f85fae0a0711a50321185c61d67caf Mon Sep 17 00:00:00 2001 From: Marc Siebeneicher Date: Tue, 13 Dec 2022 15:37:35 +0100 Subject: [PATCH 3/5] docs(sync-template): update docs regarding .templatesyncignore conflicts --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3b05ac10..0e84063f 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ jobs: Create a `.templatesyncignore` file. Just like writing a `.gitignore` file, follow the [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) in defining the files and folders that should be excluded from syncing with the template repository. +_Note: It is not possible to sync also the `.templatesyncignore` itself. Any changes from the template repository will be restored automatically._ + ## Debug You must create a secret named `ACTIONS_STEP_DEBUG` with the value `true` to see the debug messages set by this command in the log. For more information, see "[Enabling debug logging.][enabling-debug-logging]" From f434bf5921f259ed556e214e73c3306f2179c6fb Mon Sep 17 00:00:00 2001 From: Marc Siebeneicher Date: Fri, 23 Dec 2022 12:05:57 +0100 Subject: [PATCH 4/5] fix(sync-template): fix issue with .templatesyncignore by git --- src/sync_template.sh | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/sync_template.sh b/src/sync_template.sh index c798fa4d..6b072441 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -53,12 +53,6 @@ echo "::group::Pull template" echo "::debug::create new branch from default branch with name ${NEW_BRANCH}" git checkout -b "${NEW_BRANCH}" -if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_NAME} ] -then - echo "::debug::backup ignore file in case of incomming changes" - cp "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" "${TEMPLATE_SYNC_IGNORE_FILE_NAME}.tmp" -fi - echo "::debug::pull changes from template" git pull "${SOURCE_REPO}" --allow-unrelated-histories --squash --strategy=recursive -X theirs echo "::endgroup::" @@ -66,15 +60,8 @@ echo "::endgroup::" if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_NAME} ] then echo "::group::restore ignore file" - # restore ignore file. the ignore file in the final repo always wins - mv -f "${TEMPLATE_SYNC_IGNORE_FILE_NAME}.tmp" "${TEMPLATE_SYNC_IGNORE_FILE_NAME}" - # we are checking the ignore file for diff to give propper feedback - # if exit code != 0 we had an imcomming change form the tpl repo - if ! git diff --exit-code "${TEMPLATE_SYNC_IGNORE_FILE_NAME}"; then - echo "::debug::restored ignore file because of incomming changes from tpl repository" - else - echo "::debug::no diff detected in ${TEMPLATE_SYNC_IGNORE_FILE_NAME}" - fi + git reset ${TEMPLATE_SYNC_IGNORE_FILE_NAME} + git checkout -- ${TEMPLATE_SYNC_IGNORE_FILE_NAME} echo "::endgroup::" fi From d2538bc97dfd2e14352c8049addec18e692199b3 Mon Sep 17 00:00:00 2001 From: Marc Siebeneicher Date: Fri, 23 Dec 2022 12:07:24 +0100 Subject: [PATCH 5/5] chore(sync-template): cleanup code --- src/sync_template.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sync_template.sh b/src/sync_template.sh index 6b072441..b750d232 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -52,7 +52,6 @@ echo "::endgroup::" echo "::group::Pull template" echo "::debug::create new branch from default branch with name ${NEW_BRANCH}" git checkout -b "${NEW_BRANCH}" - echo "::debug::pull changes from template" git pull "${SOURCE_REPO}" --allow-unrelated-histories --squash --strategy=recursive -X theirs echo "::endgroup::"